Skip to content

Commit

Permalink
[CHORE tests] misc test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Apr 11, 2019
1 parent 5678b9e commit 92980b0
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 35 deletions.
16 changes: 8 additions & 8 deletions packages/-ember-data/tests/integration/adapter/queries-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,26 @@ test('a query can be updated via `update()`', function(assert) {
return store
.query('person', {})
.then(query => {
assert.equal(query.get('length'), 1);
assert.equal(query.get('firstObject.id'), 'first');
assert.equal(query.get('isUpdating'), false);
assert.equal(query.get('length'), 1, 'we have one person');
assert.equal(query.get('firstObject.id'), 'first', 'the right person is present');
assert.equal(query.get('isUpdating'), false, 'we are not updating');

adapter.query = function() {
assert.ok('query is called a second time');
assert.ok(true, 'query is called a second time');
return resolve({ data: [{ id: 'second', type: 'person' }] });
};

let updateQuery = query.update();

assert.equal(query.get('isUpdating'), true);
assert.equal(query.get('isUpdating'), true, 'we are updating');

return updateQuery;
})
.then(query => {
assert.equal(query.get('length'), 1);
assert.equal(query.get('firstObject.id'), 'second');
assert.equal(query.get('length'), 1, 'we still have one person');
assert.equal(query.get('firstObject.id'), 'second', 'now it is a different person');

assert.equal(query.get('isUpdating'), false);
assert.equal(query.get('isUpdating'), false, 'we are no longer updating');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ module('RESTAdapter - fetch', function(hooks) {

assert.equal(posts.get('length'), 2, 'The posts are in the array');
assert.equal(posts.get('isLoaded'), true, 'The RecordArray is loaded');
assert.deepEqual(posts.toArray(), [post1, post2], 'The correct records are in the array');
assert.deepEqual(
posts.toArray().map(p => p.name),
['Rails is omakase', 'The Parley Letter'],
'The correct records are in the array'
);
});
});
});
101 changes: 79 additions & 22 deletions packages/-ember-data/tests/integration/debug-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ module('integration/debug-adapter - DS.DebugAdapter', function(hooks) {
assert.expect(5);

function added(types) {
assert.equal(types.length, 1);
assert.equal(types[0].name, 'post');
assert.equal(types[0].count, 0);
assert.strictEqual(types[0].object, store.modelFor('post'));
assert.equal(types.length, 1, 'added one type');
assert.equal(types[0].name, 'post', 'the type is post');
assert.equal(types[0].count, 0, 'we added zero posts');
assert.strictEqual(
types[0].object,
store.modelFor('post'),
'we received the ModelClass for post'
);
}

function updated(types) {
assert.equal(types[0].count, 1);
assert.equal(types[0].count, 1, 'We updated one record');
}

debugAdapter.watchModelTypes(added, updated);
Expand Down Expand Up @@ -94,41 +98,94 @@ module('integration/debug-adapter - DS.DebugAdapter', function(hooks) {

debugAdapter.watchRecords('post', recordsAdded, recordsUpdated, recordsRemoved);

assert.equal(get(addedRecords, 'length'), 1);
assert.equal(get(addedRecords, 'length'), 1, 'We initially have 1 post');
let record = addedRecords[0];
assert.deepEqual(record.columnValues, { id: '1', title: 'Clean Post' });
assert.deepEqual(record.filterValues, { isNew: false, isModified: false, isClean: true });
assert.deepEqual(record.searchKeywords, ['1', 'Clean Post']);
assert.deepEqual(record.color, 'black');
assert.deepEqual(
record.columnValues,
{ id: '1', title: 'Clean Post' },
'The initial post has the right values'
);
assert.deepEqual(
record.filterValues,
{ isNew: false, isModified: false, isClean: true },
'The initial post has the right state'
);
assert.deepEqual(record.searchKeywords, ['1', 'Clean Post'], 'We have meaningful keywords');
assert.deepEqual(
record.color,
'black',
'We are given the right display color for a clean value'
);

let post = await store.findRecord('post', 1);

post.set('title', 'Modified Post');

assert.equal(get(updatedRecords, 'length'), 1);
assert.equal(get(updatedRecords, 'length'), 1, 'We updated 1 post');
record = updatedRecords[0];
assert.deepEqual(record.columnValues, { id: '1', title: 'Modified Post' });
assert.deepEqual(record.filterValues, { isNew: false, isModified: true, isClean: false });
assert.deepEqual(record.searchKeywords, ['1', 'Modified Post']);
assert.deepEqual(record.color, 'blue');
assert.deepEqual(
record.columnValues,
{ id: '1', title: 'Modified Post' },
'The modified values are correct for the post'
);
assert.deepEqual(
record.filterValues,
{ isNew: false, isModified: true, isClean: false },
'The modified state is correct for the post'
);
assert.deepEqual(
record.searchKeywords,
['1', 'Modified Post'],
'The keywords have been updated'
);
assert.deepEqual(record.color, 'blue', 'we have a color to represent we were modified');

// reset
addedRecords = updatedRecords = [];
removedCount = removedIndex = null;

post = store.createRecord('post', { id: '2', title: 'New Post' });

await settled();

assert.equal(get(addedRecords, 'length'), 1);
assert.equal(
get(addedRecords, 'length'),
1,
'We are notified when we add a newly created post'
);
record = addedRecords[0];
assert.deepEqual(record.columnValues, { id: '2', title: 'New Post' });
assert.deepEqual(record.filterValues, { isNew: true, isModified: false, isClean: false });
assert.deepEqual(record.searchKeywords, ['2', 'New Post']);
assert.deepEqual(record.color, 'green');
assert.deepEqual(
record && record.columnValues,
{ id: '2', title: 'New Post' },
'The newly created post has the right values'
);
assert.deepEqual(
record && record.filterValues,
{ isNew: true, isModified: false, isClean: false },
'The newly created post has the right state'
);
assert.deepEqual(
record && record.searchKeywords,
['2', 'New Post'],
'The newly created post has meaningful keywords'
);
assert.deepEqual(record && record.color, 'green'),
'The newly created post has meaningful color to represent new-ness';

// reset
addedRecords = updatedRecords = [];
removedCount = removedIndex = null;

run(() => post.unloadRecord());

await settled();

assert.equal(removedIndex, 1);
assert.equal(removedCount, 1);
assert.equal(
removedIndex,
1,
'We are notified of the start index of a removal when we remove posts'
);
assert.equal(removedCount, 1, 'We are notified of the total posts removed');
});

test('Column names', function(assert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,14 @@ test('Calling push with relationship does not trigger observers if the relations
person = store.peekRecord('person', 'wat');
});

const observerMethod = function() {
observerCount++;
};

run(() => {
// prime the pump
person.get('siblings');
person.addObserver('siblings.[]', function() {
observerCount++;
});
person.addObserver('siblings.[]', observerMethod);
});

run(() => {
Expand All @@ -482,6 +484,8 @@ test('Calling push with relationship does not trigger observers if the relations
run(() => {
assert.equal(observerCount, 0, 'siblings observer should not be triggered');
});

person.removeObserver('siblings.[]', observerMethod);
});

test('Calling push with relationship triggers willChange and didChange with detail when appending', function(assert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ test('#destroy', function(assert) {
1,
'after destroy, we should have dissociated from own record array'
);
recordArray.destroy();

assert.strictEqual(get(recordArray, 'content'), null);
assert.equal(get(recordArray, 'length'), 0, 'after destroy we should have no length');
Expand Down

0 comments on commit 92980b0

Please sign in to comment.