Debian Codegraph @

tests/jest/mediawiki.special.block/UserLookup.test.js

raw symbols SCIP
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 // Ensure that the initial search string matches the initial prop value.
19 const input = wrapper.find( '.cdx-text-input__input' );
20 expect( input.element.value ).toBe( 'UserLookup' );
21 // "No results"
22 const listBox = wrapper.find( '.cdx-menu__listbox' );
23 expect( listBox.element.children ).toHaveLength( 1 );
24 await input.trigger( 'input' );
25 // Ensure that the Lookup menu is populated with API response data
26 // We need to use "flushPromises" from Vue test utils
27 // to ensure the fake API request can complete
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 } );