Skip to content

Commit

Permalink
✅ Listbox: implement test "test should be possible to wrap the Listbo…
Browse files Browse the repository at this point in the history
…x.Options with a Transition component"
  • Loading branch information
dmcnamara-eng committed Sep 8, 2021
1 parent 94e2666 commit bf8a28f
Showing 1 changed file with 70 additions and 4 deletions.
74 changes: 70 additions & 4 deletions tests/integration/components/listbox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
getListbox,
getListboxes,
} from '../../accessibility-assertions';
import Component from '@ember/component';

async function typeWord(word) {
word.split('').forEach((char) => {
Expand Down Expand Up @@ -372,10 +373,75 @@ module('Integration | Component | <Listbox>', function (hooks) {
});

module('Listbox composition', () => {
todo(
'test should be possible to wrap the Listbox.Options with a Transition component',
async function () {}
);
test('test should be possible to wrap the Listbox.Options with a Transition component', async function (assert) {
let order = [];

this.set('orderFn', (value) => {
order.push(value);
});

this.owner.register(
'component:debug',
Component.extend({
init() {
this._super(...arguments);
this.fn('Mounting - ' + this.name);
},

didDestroyElement() {
this._super(...arguments);
this.fn('Unmounting - ' + this.name);
}
})
);

await render(hbs`
<Listbox as |listbox|>
<listbox.Button data-test="headlessui-listbox-button-1">Trigger</listbox.Button>
<Debug @name="Listbox" @fn={{this.orderFn}}/>
<Transition @show={{listbox.isOpen}}>
<Debug @name="Transition" @fn={{this.orderFn}}/>
<listbox.Options
@isOpen={{true}}
as |options|>
<options.Option as |option|>
{{option.active}} {{option.selected}} {{option.disabled}}
<Debug @name="Listbox.Option" @fn={{this.orderFn}}/>
</options.Option>
</listbox.Options>
</Transition>
</Listbox>
`);

assertListboxButton({
state: ListboxState.InvisibleUnmounted,
attributes: { 'data-test': 'headlessui-listbox-button-1' },
});
assertListbox({ state: ListboxState.InvisibleUnmounted });

await click(getListboxButton());

assertListboxButton({
state: ListboxState.Visible,
attributes: { 'data-test': 'headlessui-listbox-button-1' },
});
assertListbox({
state: ListboxState.Visible,
textContent: 'false false false',
});

await click(getListboxButton());

// Verify that we tracked the `mounts` and `unmounts` in the correct order
assert.deepEqual(order, [
'Mounting - Listbox',
'Mounting - Transition',
'Mounting - Listbox.Option',
'Unmounting - Transition',
'Unmounting - Listbox.Option',
]);

});
});

module('Listbox keyboard actions', () => {
Expand Down

0 comments on commit bf8a28f

Please sign in to comment.