it('will return the same JSON scalar field object', () => { const query = gql` { a { b c } d { e f } } `; const queryResult = { a: { b: 1, c: { x: 2, y: 3, z: 4 } }, d: { e: 5, f: { x: 6, y: 7, z: 8 } }, }; const store = writeQueryToStore({ query, result: queryResult, }); const previousResult = { a: { b: 1, c: { x: 2, y: 3, z: 4 } }, d: { e: 50, f: { x: 6, y: 7, z: 8 } }, }; const { result } = diffQueryAgainstStore({ store, query, previousResult, }); assert.deepEqual(result, queryResult); assert.notStrictEqual(result, previousResult); assert.strictEqual(result.a, previousResult.a); assert.notStrictEqual(result.d, previousResult.d); assert.strictEqual(result.d.f, previousResult.d.f); });
it('will return parts of the previous result that changed', () => { const query = gql` query { a { b } c { d e { f } } } `; const queryResult = { a: { b: 1 }, c: { d: 2, e: { f: 3 } }, }; const store = writeQueryToStore({ query, result: queryResult, }); const previousResult = { a: { b: 1 }, c: { d: 20, e: { f: 3 } }, }; const { result } = diffQueryAgainstStore({ store, query, previousResult, }); assert.deepEqual(result, queryResult); assert.notStrictEqual(result, previousResult); assert.strictEqual(result.a, previousResult.a); assert.notStrictEqual(result.c, previousResult.c); assert.strictEqual(result.c.e, previousResult.c.e); });
it('will return parts of the previous result if there are changes in child arrays', () => { const query = gql` query { a { b } c { d e { f } } } `; const queryResult = { a: [{ b: 1.1 }, { b: 1.2 }, { b: 1.3 }], c: { d: 2, e: [{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }, { f: 3.4 }, { f: 3.5 }], }, }; const store = writeQueryToStore({ query, result: queryResult, }); const previousResult = { a: [{ b: 1.1 }, { b: -1.2 }, { b: 1.3 }], c: { d: 20, e: [{ f: 3.1 }, { f: 3.2 }, { f: 3.3 }, { f: 3.4 }, { f: 3.5 }], }, }; const { result } = diffQueryAgainstStore({ store, query, previousResult, }); assert.deepEqual(result, queryResult); assert.notStrictEqual(result, previousResult); assert.notStrictEqual(result.a, previousResult.a); assert.strictEqual(result.a[0], previousResult.a[0]); assert.notStrictEqual(result.a[1], previousResult.a[1]); assert.strictEqual(result.a[2], previousResult.a[2]); assert.notStrictEqual(result.c, previousResult.c); assert.notStrictEqual(result.c.e, previousResult.c.e); assert.strictEqual(result.c.e[0], previousResult.c.e[0]); assert.strictEqual(result.c.e[1], previousResult.c.e[1]); assert.strictEqual(result.c.e[2], previousResult.c.e[2]); assert.strictEqual(result.c.e[3], previousResult.c.e[3]); assert.strictEqual(result.c.e[4], previousResult.c.e[4]); });
it('should set the level and step for a game', () => { const game = createAndInitGame(); const newLevel = 2; const newStep = 2; assert.notStrictEqual(game.level, newLevel); assert.notStrictEqual(game.step, newStep); const updatedGame = setDifficulty(game, newLevel, newStep); assert.strictEqual(updatedGame.level, newLevel); assert.strictEqual(updatedGame.step, newStep); assert.strictEqual(updatedGame.shouldRefreshChoices, true); });
it('set a new correct choice', () => { const choices = I.List.of(1, 2, 3); const correctChoice = 80; const note1 = 'C1'; const note2 = 'C8'; const game = create() .set('choices', choices) .set('correctChoice', correctChoice) .set('currentNote1', note1) .set('currentNote2', note2) as State; const updatedGame = refreshCorrectChoice(game); assert.notStrictEqual(game.correctChoice, updatedGame.correctChoice); assert.notStrictEqual(updatedGame.currentNote1, note1); assert.notStrictEqual(updatedGame.currentNote2, note2); });
it("should always return a different variable name for different entries", function() { let mapping = helper.createUnstructuredMapping(); let a = mapping.getPropertyVariable("A"); let b = mapping.getPropertyVariable("B"); assert.notStrictEqual(a, b); });
it('should serialise Date, include millisecond level', () => { var valueA = new Date(); var ori = xm.jsonToIdent(valueA); var alt = xm.jsonToIdent(new Date(valueA.getTime())); assert.strictEqual(ori, alt, 'identical values'); alt = xm.jsonToIdent(new Date(valueA.getTime() + 2)); assert.notStrictEqual(ori, alt, 'milli second'); });
it('should not refresh a new game when not forced', () => { const game = createAndInitGame(); const newChoices = I.List([7, 8, 9]); const newCorrectChoice = 8; assert(!I.is(game.choices, newChoices)); assert.notStrictEqual(game.correctChoice, newCorrectChoice); const updatedGame = refresh( game, (g: TestState) => g.set('choices', newChoices) as TestState, (g: TestState) => g.set('correctChoice', newCorrectChoice) as TestState, false ); assert(!I.is(updatedGame.choices, newChoices)); assert.notStrictEqual(updatedGame.correctChoice, newCorrectChoice); assert.strictEqual(updatedGame.guessCountForCurrentCorrectChoice, 0); assert.strictEqual(game.refreshChoicesCount, updatedGame.refreshChoicesCount); assert.strictEqual(game.refreshCorrectChoiceCount, updatedGame.refreshCorrectChoiceCount); });
it('set a new correct choice', () => { const choices = I.List.of('B0', 'C1', 'C#1'); const correctChoice = 'C8'; const game = create() .set('choices', choices) .set('correctChoice', correctChoice) as State; const updatedGame = refreshCorrectChoice(game); assert.notStrictEqual(game.correctChoice, updatedGame.correctChoice); });
it('should return different hash for different data', () => { var ori = xm.jsonToIdent(valueA); var alt; alt = xm.jsonToIdent(valueX1); assert.notStrictEqual(ori, alt, 'valueA -> valueX1'); alt = xm.jsonToIdent(valueX2); assert.notStrictEqual(ori, alt, 'valueA -> valueX2'); alt = xm.jsonToIdent(valueX3); assert.notStrictEqual(ori, alt, 'valueA -> valueX3'); alt = xm.jsonToIdent(valueX4); assert.notStrictEqual(ori, alt, 'valueA -> valueX4'); alt = xm.jsonToIdent(valueX5); assert.notStrictEqual(ori, alt, 'valueA -> valueX5'); });