Skip to content

Commit

Permalink
fix: add test for unloadAll not fully cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Sep 27, 2023
1 parent 9ec3d59 commit 9947221
Showing 1 changed file with 380 additions and 0 deletions.
380 changes: 380 additions & 0 deletions tests/main/tests/integration/records/unload-all-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,380 @@
import { setupTest } from 'ember-qunit';

Check failure on line 1 in tests/main/tests/integration/records/unload-all-test.js

View workflow job for this annotation

GitHub Actions / lint

Run autofix to sort these imports!
import { module, test } from 'qunit';
import Model, { attr } from '@ember-data/model';
import { settled } from '@ember/test-helpers';

module('Integration | Records | unloadAll', function(hooks) {

Check failure on line 6 in tests/main/tests/integration/records/unload-all-test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `·`
setupTest(hooks);

test('repeat unloadAll works when queues are given the chance to settle', async function(assert) {

Check failure on line 9 in tests/main/tests/integration/records/unload-all-test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `·`
this.owner.register('model:post', class Post extends Model {

Check failure on line 10 in tests/main/tests/integration/records/unload-all-test.js

View workflow job for this annotation

GitHub Actions / lint

Replace `'model:post',` with `⏎······'model:post',⏎·····`
@attr title;

Check failure on line 11 in tests/main/tests/integration/records/unload-all-test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
});

Check failure on line 12 in tests/main/tests/integration/records/unload-all-test.js

View workflow job for this annotation

GitHub Actions / lint

Replace `}` with `··}⏎····`
const store = this.owner.lookup('service:store');

// round 1
store.push({
data: [
{
type: 'post',
id: '1',
attributes: {
title: 'Lorem ipsum'

Check failure on line 22 in tests/main/tests/integration/records/unload-all-test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
}

Check failure on line 23 in tests/main/tests/integration/records/unload-all-test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
},
{
type: 'post',
id: '2',
attributes: {
title: 'Lorem ipsum'

Check failure on line 29 in tests/main/tests/integration/records/unload-all-test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
}

Check failure on line 30 in tests/main/tests/integration/records/unload-all-test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
}
]
});
await settled();
assert.strictEqual(store.peekAll('post').length, 2, 'precond - 2 posts in the store');
store.unloadAll('post');
await settled();
assert.strictEqual(store.peekAll('post').length, 0, '0 posts in the store after first unloadAll');

// round 2
store.push({
data: [
{
type: 'post',
id: '1',
attributes: {
title: 'Lorem ipsum'
}
},
{
type: 'post',
id: '2',
attributes: {
title: 'Lorem ipsum'
}
}
]
});
await settled();
assert.strictEqual(store.peekAll('post').length, 2, '2 posts in the store');
store.unloadAll('post');
await settled();
assert.strictEqual(store.peekAll('post').length, 0, '0 posts in the store after second unloadAll');

// round 3
store.push({
data: [
{
type: 'post',
id: '1',
attributes: {
title: 'Lorem ipsum'
}
},
{
type: 'post',
id: '2',
attributes: {
title: 'Lorem ipsum'
}
}
]
});
await settled();
assert.strictEqual(store.peekAll('post').length, 2, '2 posts in the store');
store.unloadAll('post');
await settled();
assert.strictEqual(store.peekAll('post').length, 0, '0 posts in the store after third unloadAll');
});

test('repeat unloadAll works when queues are given the chance to settle, no peekAll after unloadAll', async function(assert) {
this.owner.register('model:post', class Post extends Model {
@attr title;
});
const store = this.owner.lookup('service:store');

// round 1
store.push({
data: [
{
type: 'post',
id: '1',
attributes: {
title: 'Lorem ipsum'
}
},
{
type: 'post',
id: '2',
attributes: {
title: 'Lorem ipsum'
}
}
]
});
await settled();
assert.strictEqual(store.peekAll('post').length, 2, 'precond - 2 posts in the store');
store.unloadAll('post');
await settled();

// round 2
store.push({
data: [
{
type: 'post',
id: '1',
attributes: {
title: 'Lorem ipsum'
}
},
{
type: 'post',
id: '2',
attributes: {
title: 'Lorem ipsum'
}
}
]
});
await settled();
assert.strictEqual(store.peekAll('post').length, 2, '2 posts in the store');
store.unloadAll('post');
await settled();

debugger;

// round 3
store.push({
data: [
{
type: 'post',
id: '1',
attributes: {
title: 'Lorem ipsum'
}
},
{
type: 'post',
id: '2',
attributes: {
title: 'Lorem ipsum'
}
}
]
});
await settled();
debugger;
assert.strictEqual(store.peekAll('post').length, 2, '2 posts in the store');
store.unloadAll('post');
await settled();
assert.strictEqual(store.peekAll('post').length, 0, '0 posts in the store after third unloadAll');
});

test('repeat unloadAll works when queues are given the chance to settle, no peekAll until end', async function(assert) {
this.owner.register('model:post', class Post extends Model {
@attr title;
});
const store = this.owner.lookup('service:store');
assert.strictEqual(store.peekAll('post').length, 0, '0 posts in the store');

// round 1
store.push({
data: [
{
type: 'post',
id: '1',
attributes: {
title: 'Lorem ipsum'
}
},
{
type: 'post',
id: '2',
attributes: {
title: 'Lorem ipsum'
}
}
]
});
await settled();
store.unloadAll('post');
await settled();

// round 2
store.push({
data: [
{
type: 'post',
id: '1',
attributes: {
title: 'Lorem ipsum'
}
},
{
type: 'post',
id: '2',
attributes: {
title: 'Lorem ipsum'
}
}
]
});
await settled();
store.unloadAll('post');
await settled();

assert.strictEqual(store.peekAll('post').length, 0, '0 posts in the store after second unloadAll');
});

test('(crazytown) repeat unloadAll works when queues are not given the chance to settle, no peekAll after unloadAll', async function(assert) {
this.owner.register('model:post', class Post extends Model {
@attr title;
});
const store = this.owner.lookup('service:store');

// round 1
store.push({
data: [
{
type: 'post',
id: '1',
attributes: {
title: 'Lorem ipsum'
}
},
{
type: 'post',
id: '2',
attributes: {
title: 'Lorem ipsum'
}
}
]
});
assert.strictEqual(store.peekAll('post').length, 2, 'precond - 2 posts in the store');
store.unloadAll('post');

// round 2
store.push({
data: [
{
type: 'post',
id: '1',
attributes: {
title: 'Lorem ipsum'
}
},
{
type: 'post',
id: '2',
attributes: {
title: 'Lorem ipsum'
}
}
]
});
assert.strictEqual(store.peekAll('post').length, 2, '2 posts in the store');
store.unloadAll('post');

// round 3
store.push({
data: [
{
type: 'post',
id: '1',
attributes: {
title: 'Lorem ipsum'
}
},
{
type: 'post',
id: '2',
attributes: {
title: 'Lorem ipsum'
}
}
]
});
assert.strictEqual(store.peekAll('post').length, 2, '2 posts in the store');
store.unloadAll('post');
assert.strictEqual(store.peekAll('post').length, 0, '0 posts in the store after third unloadAll');

await settled();
assert.strictEqual(store.peekAll('post').length, 0, '0 posts in the store at the end');
});

test('(crazytown) repeat unloadAll works when queues are not given the chance to settle, no peekAll until the end', async function(assert) {
this.owner.register('model:post', class Post extends Model {
@attr title;
});
const store = this.owner.lookup('service:store');

// round 1
store.push({
data: [
{
type: 'post',
id: '1',
attributes: {
title: 'Lorem ipsum'
}
},
{
type: 'post',
id: '2',
attributes: {
title: 'Lorem ipsum'
}
}
]
});
store.unloadAll('post');

// round 2
store.push({
data: [
{
type: 'post',
id: '1',
attributes: {
title: 'Lorem ipsum'
}
},
{
type: 'post',
id: '2',
attributes: {
title: 'Lorem ipsum'
}
}
]
});
store.unloadAll('post');

// round 3
store.push({
data: [
{
type: 'post',
id: '1',
attributes: {
title: 'Lorem ipsum'
}
},
{
type: 'post',
id: '2',
attributes: {
title: 'Lorem ipsum'
}
}
]
});
store.unloadAll('post');
assert.strictEqual(store.peekAll('post').length, 0, '0 posts in the store after third unloadAll');

await settled();
assert.strictEqual(store.peekAll('post').length, 0, '0 posts in the store at the end');
});
});

0 comments on commit 9947221

Please sign in to comment.