-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #575 from mkszepp/fix-item-undefined
Fix error `TypeError: items[0] is undefined` in `sortable-item` modifier
- Loading branch information
Showing
2 changed files
with
37 additions
and
1 deletion.
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
36 changes: 36 additions & 0 deletions
36
test-app/tests/integration/modifiers/sortable-item-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,36 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { find, render } from '@ember/test-helpers'; | ||
import { set } from '@ember/object'; | ||
import { drag } from 'ember-sortable/test-support'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
module('Integration | Modifier | sortable-item', function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test('Drag works with one item', async function (assert) { | ||
this.items = ['Uno']; | ||
|
||
this.update = (items) => { | ||
set(this, 'items', items); | ||
}; | ||
|
||
await render(hbs` | ||
<ol id="test-list" {{sortable-group onChange=this.update}}> | ||
{{#each this.items as |item|}} | ||
<li data-test-item {{sortable-item model=item}}>{{item}}</li> | ||
{{/each}} | ||
</ol> | ||
`); | ||
|
||
await drag('mouse', '[data-test-item]', () => { | ||
return { dy: 10 }; | ||
}); | ||
|
||
assert.equal(contents('#test-list'), 'Uno'); | ||
}); | ||
|
||
function contents(selector) { | ||
return find(selector).textContent.replace(/⇕/g, '').replace(/\s+/g, ' ').replace(/^\s+/, '').replace(/\s+$/, ''); | ||
} | ||
}); |