fix formatting to airbnb javascript

This commit is contained in:
Hen Shalom 2018-03-01 22:21:48 +02:00
parent 544eea4f11
commit aedc77fdd4
2 changed files with 146 additions and 87 deletions

View file

@ -1,56 +1,100 @@
import "babel-polyfill";
import mocha from "mocha";
import chai from "chai";
import { getJsonDiff } from "../src/JsonDiff";
const expect = chai.expect;
import 'babel-polyfill';
import { describe, it } from 'mocha';
import { expect } from 'chai';
import {
getJsonDiff,
checkArryTypeDiff,
checkObjectTypeDiffAdd,
checkObjectDiffDelete,
} from '../src/JsonDiff';
describe("Json Diff", function() {
describe("#getJsonDiff", function() {
it("should return the property diff between two object", function() {
let res = getJsonDiff({}, { color: "blue" });
expect(res[0]).to.equal("Add .color:blue");
});
it("should return the property inside property diff between two object", function() {
let res = getJsonDiff({}, { color: { deep: "blue" } });
expect(res[0]).to.equal("Add .color.deep:blue");
});
it("should return multi properties diff ", function() {
let res = getJsonDiff(
{},
{ color: { deep: "blue" }, shadow: "light" }
);
expect(res).to.deep.equal([
"Add .color.deep:blue",
"Add .shadow:light"
]);
});
it("should ignore properties that also exists in the old json ", function() {
let res = getJsonDiff(
{ shadow: "light" },
{ color: { deep: "blue" }, shadow: "light" }
);
expect(res).to.deep.equal(["Add .color.deep:blue"]);
});
it("should not return anything when two json are the same ", function() {
let res = getJsonDiff(
{ color: { deep: "blue" }, shadow: "light" },
{ color: { deep: "blue" }, shadow: "light" }
);
expect(res).to.deep.equal([]);
});
it("write update if value where changed ", function() {
let res = getJsonDiff(
{ color: { deep: "blue" }, shadow: "light" },
{ color: { deep: "blue" }, shadow: "dark" }
);
expect(res).to.deep.equal(["Update .shadow:dark"]);
});
it("write Delete if the head is ahead ", function() {
let res = getJsonDiff(
{ color: { deep: "blue" }, shadow: "light" },
{ color: { deep: "blue" } }
);
expect(res).to.deep.equal(["Delete .shadow:light"]);
});
describe('Json Diff', () => {
describe('#checkObjectTypeDiffAdd', () => {
it('should return the property diff between two object', () => {
const res = [];
checkObjectTypeDiffAdd({}, { color: 'blue' }, res, '');
expect(res[0]).to.equal('Add .color:blue');
});
it('should return the property inside property diff between two object', () => {
const res = [];
checkObjectTypeDiffAdd({}, { color: { deep: 'blue' } }, res, '');
expect(res[0]).to.equal('Add .color.deep:blue');
});
it('should return multi properties diff ', () => {
const res = [];
checkObjectTypeDiffAdd({}, { color: { deep: 'blue' }, shadow: 'light' }, res, '');
expect(res).to.deep.equal(['Add .color.deep:blue', 'Add .shadow:light']);
});
it('should ignore properties that also exists in the old json ', () => {
const res = [];
checkObjectTypeDiffAdd(
{ shadow: 'light' },
{ color: { deep: 'blue' }, shadow: 'light' },
res,
'',
);
expect(res).to.deep.equal(['Add .color.deep:blue']);
});
it('should not return anything when two json are the same ', () => {
const res = [];
checkObjectTypeDiffAdd(
{ color: { deep: 'blue' }, shadow: 'light' },
{ color: { deep: 'blue' }, shadow: 'light' },
res,
'',
);
expect(res).to.deep.equal([]);
});
it('write update if value where changed ', () => {
const res = [];
checkObjectTypeDiffAdd(
{ color: { deep: 'blue' }, shadow: 'light' },
{ color: { deep: 'blue' }, shadow: 'dark' },
res,
'',
);
expect(res).to.deep.equal(['Update .shadow:dark']);
});
});
describe('#checkObjectDiffDelete', () => {
it('write Delete if the head is ahead ', () => {
const res = [];
checkObjectDiffDelete(
{ color: { deep: 'blue' }, shadow: 'light' },
{ color: { deep: 'blue' } },
res,
'',
);
expect(res).to.deep.equal(['Delete .shadow:light']);
});
it('should return new element in array', () => {
const res = getJsonDiff(
{ color: { deep: 'blue' }, shadow: 'light' },
{ color: { deep: 'blue' } },
);
expect(res).to.deep.equal(['Delete .shadow:light']);
});
});
describe('#checkArryTypeDiff', () => {
it('should return the array diff', () => {
const res = [];
checkArryTypeDiff([], ['1'], res, '');
expect(res[0]).to.equal('Add .[0]>1');
});
it('should return the array update', () => {
const res = [];
checkArryTypeDiff(['3'], ['1'], res, '');
expect(res[0]).to.equal('Update .[0]>1');
});
it('should return the diff of a complex array', () => {
const res = [];
checkArryTypeDiff([], [[1, 2], [3, 4]], res, '');
expect(res).to.deep.equal([
'Add .[0].[0]>1',
'Add .[0].[1]>2',
'Add .[1].[0]>3',
'Add .[1].[1]>4',
]);
});
});
});