-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add test for unloadAll not fully cleaning up
- Loading branch information
Showing
1 changed file
with
380 additions
and
0 deletions.
There are no files selected for viewing
380 changes: 380 additions & 0 deletions
380
tests/main/tests/integration/records/unload-all-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,380 @@ | ||
import { setupTest } from 'ember-qunit'; | ||
import { module, test } from 'qunit'; | ||
import Model, { attr } from '@ember-data/model'; | ||
import { settled } from '@ember/test-helpers'; | ||
|
||
module('Integration | Records | unloadAll', function(hooks) { | ||
setupTest(hooks); | ||
|
||
test('repeat unloadAll works when queues are given the chance to settle', 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(); | ||
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'); | ||
}); | ||
}); |