Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dxinteractive committed Jan 28, 2019
1 parent c28c335 commit 097d98f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 85 deletions.
33 changes: 0 additions & 33 deletions packages/dataparcels/src/change/__test__/ChangeRequest-test.js
Expand Up @@ -283,39 +283,6 @@ test('ChangeRequest should cache its data after its calculated, so subsequent ca
expect(ms2).toBeLessThan(ms / 100); // expect amazing performance boosts from having cached
});

// test('ChangeRequest data chache should be invalidated correctly', () => {
// expect.assertions(6);

// var parcel = new Parcel({
// value: {
// a: {
// b: 123
// }
// }
// });

// parcel
// .get('a')
// .modifyChange((parcel, changeRequest) => {
// expect(changeRequest.nextData).toEqual({key: 'a', meta: {abc: 123}, value: {b: 456}, child: {b:{key: "b"}}});
// expect(changeRequest.nextData).toEqual({key: 'a', meta: {abc: 123}, value: {b: 456}, child: {b:{key: "b"}}}); // get cached
// parcel.dispatch(changeRequest);
// })
// .modifyChange((parcel, changeRequest) => {
// expect(changeRequest.nextData).toEqual({key: 'a', meta: {}, value: {b: 456}, child: {b:{key: "b"}}});
// expect(changeRequest.nextData).toEqual({key: 'a', meta: {}, value: {b: 456}, child: {b:{key: "b"}}}); // get cached
// parcel.dispatch(changeRequest);
// parcel.setMeta({abc: 123});
// })
// .get('b')
// .modifyChange((parcel, changeRequest) => {
// expect(changeRequest.nextData).toEqual({key: 'b', meta: {}, value: 456});
// expect(changeRequest.nextData).toEqual({key: 'b', meta: {}, value: 456}); // get cached
// parcel.dispatch(changeRequest);
// })
// .onChange(456);
// });

test('ChangeRequest getDataIn should return previous and next value at keyPath', () => {
var action = new Action({
type: "set",
Expand Down
19 changes: 13 additions & 6 deletions packages/dataparcels/src/parcel/__test__/ModifyMethods-test.js
Expand Up @@ -124,12 +124,19 @@ test('Parcel.modifyUp() should allow you to change the payload of a changed parc
expect(handleChange.mock.calls[0][0].value).toBe(undefined);
});

// test('Parcel.modifyUp() should validate value updater', () => {
// TestValidateValueUpdater(
// expect,
// (value, updater) => new Parcel({value: undefined}).modifyUp(updater).onChange(value)
// );
// });
test('Parcel.modifyUp() should validate value updater', () => {
let handleChange = () => {};

TestValidateValueUpdater(
expect,
(value, updater) => new Parcel({
value: undefined,
handleChange
})
.modifyUp(updater)
.onChange(value)
);
});

test('Parcel.modifyUp() should allow changes to meta through', () => {
expect.assertions(2);
Expand Down
Expand Up @@ -132,50 +132,40 @@ test('ParcelShapeTypes should correctly identify element values with getIn', ()
expect(new ParcelShape(value).getIn(["b",0]).isTopLevel()).toBe(false);
});

// // method creators

// // test('Correct methods are created for primitive values', () => {
// // var value = 123;
// // expect(() => new ParcelShape(value).set('A')).not.toThrow();
// // expect(() => new ParcelShape(value).has('a')).toThrowError(`.has() is not a function`);
// // expect(() => new ParcelShape(value).pop()).toThrowError(`.pop() is not a function`);
// // expect(() => new ParcelShape(value).delete()).toThrowError(`.delete() cannot be called with 0 arguments`);
// // expect(() => new ParcelShape(value).swapNext()).toThrowError(`.swapNext() cannot be called with 0 arguments`);
// // });

// // test('Correct methods are created for object values', () => {
// // var value = {a: 123};
// // expect(() => new ParcelShape(value).set('A')).not.toThrow();
// // expect(() => new ParcelShape(value).has('a')).not.toThrow();
// // expect(() => new ParcelShape(value).pop()).toThrowError(`.pop() is not a function`);
// // expect(() => new ParcelShape(value).delete()).toThrowError(`.delete() cannot be called with 0 arguments`);
// // expect(() => new ParcelShape(value).swapNext()).toThrowError(`.swapNext() cannot be called with 0 arguments`);
// // });

// // test('Correct methods are created for array values', () => {
// // var value = [1,2,3];
// // expect(() => new ParcelShape(value).set('A')).not.toThrow();
// // expect(() => new ParcelShape(value).has('a')).not.toThrow();
// // expect(() => new ParcelShape(value).pop()).not.toThrow();
// // expect(() => new ParcelShape(value).delete()).toThrowError(`.delete() cannot be called with 0 arguments`);
// // expect(() => new ParcelShape(value).swapNext()).toThrowError(`.swapNext() cannot be called with 0 arguments`);
// // });

// // test('Correct methods are created for object child values', () => {
// // var value = {a: 123};
// // expect(() => new ParcelShape(value).get("a").set('A')).not.toThrow();
// // expect(() => new ParcelShape(value).get("a").has('a')).toThrowError(`.has() is not a function`);
// // expect(() => new ParcelShape(value).get("a").pop()).toThrowError(`.pop() is not a function`);
// // expect(() => new ParcelShape(value).get("a").delete()).not.toThrow();
// // expect(() => new ParcelShape(value).get("a").swapNext()).toThrowError(`.swapNext() cannot be called with 0 arguments`);
// // });

// // test('Correct methods are created for array element values', () => {
// // var value = [1,2,3];
// // expect(() => new ParcelShape(value).get(0).set('A')).not.toThrow();
// // expect(() => new ParcelShape(value).get(0).has('a')).toThrowError(`.has() is not a function`);
// // expect(() => new ParcelShape(value).get(0).pop()).toThrowError(`.pop() is not a function`);
// // expect(() => new ParcelShape(value).get(0).delete()).not.toThrow();
// // expect(() => new ParcelShape(value).get(0).swapNext()).not.toThrow();
// // });
// method creators

test('Correct methods are created for primitive values', () => {
var value = 123;
expect(() => new ParcelShape(value).set('A')).not.toThrow();
expect(() => new ParcelShape(value).has('a')).toThrowError(`.has() is not a function`);
expect(() => new ParcelShape(value).pop()).toThrowError(`.pop() is not a function`);
});

test('Correct methods are created for object values', () => {
var value = {a: 123};
expect(() => new ParcelShape(value).set('A')).not.toThrow();
expect(() => new ParcelShape(value).has('a')).not.toThrow();
expect(() => new ParcelShape(value).pop()).toThrowError(`.pop() is not a function`);
});

test('Correct methods are created for array values', () => {
var value = [1,2,3];
expect(() => new ParcelShape(value).set('A')).not.toThrow();
expect(() => new ParcelShape(value).has('a')).not.toThrow();
expect(() => new ParcelShape(value).pop()).not.toThrow();
});

test('Correct methods are created for object child values', () => {
var value = {a: 123};
expect(() => new ParcelShape(value).get("a").set('A')).not.toThrow();
expect(() => new ParcelShape(value).get("a").has('a')).toThrowError(`.has() is not a function`);
expect(() => new ParcelShape(value).get("a").pop()).toThrowError(`.pop() is not a function`);
});

test('Correct methods are created for array element values', () => {
var value = [1,2,3];
expect(() => new ParcelShape(value).get(0).set('A')).not.toThrow();
expect(() => new ParcelShape(value).get(0).has('a')).toThrowError(`.has() is not a function`);
expect(() => new ParcelShape(value).get(0).pop()).toThrowError(`.pop() is not a function`);
});

0 comments on commit 097d98f

Please sign in to comment.