-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-ordering linksToMany doesn't preserve templates (and UI component …
…state) (#2241) * add test for re-rodering linksToMany items * Fix reordering issue where finding element is based upon value that is already set. The getter was not tracking correct value * fix lint fix more lint * add box unit test * make re-order example for 3 items * fix lint * improve test naming * fix more english --------- Co-authored-by: Buck Doyle <[email protected]>
- Loading branch information
1 parent
160dab0
commit 8f1e981
Showing
3 changed files
with
216 additions
and
4 deletions.
There are no files selected for viewing
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
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
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,55 @@ | ||
import { RenderingTestContext } from '@ember/test-helpers'; | ||
|
||
import { module, test } from 'qunit'; | ||
|
||
import { Loader, baseRealm } from '@cardstack/runtime-common'; | ||
|
||
import { lookupLoaderService } from '../helpers'; | ||
import { setupRenderingTest } from '../helpers/setup'; | ||
|
||
let cardApi: typeof import('https://cardstack.com/base/card-api'); | ||
|
||
let loader: Loader; | ||
|
||
module('Unit | box', function (hooks) { | ||
setupRenderingTest(hooks); | ||
hooks.beforeEach(function (this: RenderingTestContext) { | ||
loader = lookupLoaderService().loader; | ||
}); | ||
hooks.beforeEach(async function () { | ||
cardApi = await loader.import(`${baseRealm.url}card-api`); | ||
}); | ||
|
||
test('Box children maintain object strict equality after re-ordering', async function (assert) { | ||
let { Box } = cardApi; | ||
let parentCardModel = { | ||
someField: [], | ||
}; | ||
let childCard1Model = {}; | ||
let childCard2Model = {}; | ||
let childCard3Model = {}; | ||
let box = Box.create(parentCardModel); | ||
let boxArr = box.field('someField'); | ||
let childValues: any = [childCard1Model, childCard2Model, childCard3Model]; | ||
boxArr.set(childValues); | ||
assert.strictEqual(boxArr.children[0].value, childCard1Model); | ||
assert.strictEqual(boxArr.children[1].value, childCard2Model); | ||
assert.strictEqual(boxArr.children[2].value, childCard3Model); | ||
assert.strictEqual(boxArr.children[0].name, '0'); | ||
assert.strictEqual(boxArr.children[1].name, '1'); | ||
assert.strictEqual(boxArr.children[2].name, '2'); | ||
|
||
let childValuesReordered: any = [ | ||
childCard2Model, | ||
childCard3Model, | ||
childCard1Model, | ||
]; | ||
boxArr.set(childValuesReordered); | ||
assert.strictEqual(boxArr.children[0].value, childCard2Model); | ||
assert.strictEqual(boxArr.children[1].value, childCard3Model); | ||
assert.strictEqual(boxArr.children[2].value, childCard1Model); | ||
assert.strictEqual(boxArr.children[0].name, '0'); | ||
assert.strictEqual(boxArr.children[1].name, '1'); | ||
assert.strictEqual(boxArr.children[2].name, '2'); | ||
}); | ||
}); |