| 1 |
'use strict'; |
| 2 |
|
| 3 |
const { mount, flushPromises } = require( '@vue/test-utils' ); |
| 4 |
const { mockMwApiGet } = require( './SpecialBlock.setup.js' ); |
| 5 |
const { createTestingPinia } = require( '@pinia/testing' ); |
| 6 |
const UserLookup = require( '../../../resources/src/mediawiki.special.block/components/UserLookup.vue' ); |
| 7 |
|
| 8 |
beforeAll( () => mockMwApiGet() ); |
| 9 |
|
| 10 |
describe( 'UserLookup', () => { |
| 11 |
it( 'should update menu items based on the API response', async () => { |
| 12 |
const wrapper = mount( UserLookup, { |
| 13 |
props: { modelValue: 'UserLookup' }, |
| 14 |
global: { |
| 15 |
plugins: [ createTestingPinia( { stubActions: false } ) ] |
| 16 |
} |
| 17 |
} ); |
| 18 |
|
| 19 |
const input = wrapper.find( '.cdx-text-input__input' ); |
| 20 |
expect( input.element.value ).toBe( 'UserLookup' ); |
| 21 |
|
| 22 |
const listBox = wrapper.find( '.cdx-menu__listbox' ); |
| 23 |
expect( listBox.element.children ).toHaveLength( 1 ); |
| 24 |
await input.trigger( 'input' ); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
await flushPromises(); |
| 29 |
expect( listBox.element.children ).toHaveLength( 2 ); |
| 30 |
expect( listBox.element.children[ 0 ].textContent ).toBe( 'UserLookup1' ); |
| 31 |
expect( listBox.element.children[ 1 ].textContent ).toBe( 'UserLookup2' ); |
| 32 |
} ); |
| 33 |
} ); |