33 * SPDX-License-Identifier: BUSL-1.1
44 */
55
6- import { click , settled , visit , fillIn , currentURL , waitFor , findAll } from '@ember/test-helpers' ;
6+ import {
7+ click ,
8+ settled ,
9+ visit ,
10+ fillIn ,
11+ currentURL ,
12+ waitFor ,
13+ findAll ,
14+ triggerKeyEvent ,
15+ find ,
16+ } from '@ember/test-helpers' ;
717import { module , test } from 'qunit' ;
818import { setupApplicationTest } from 'ember-qunit' ;
919import { runCmd , createNS } from 'vault/tests/helpers/commands' ;
@@ -28,58 +38,82 @@ module('Acceptance | Enterprise | namespaces', function (hooks) {
2838 fetchSpy . restore ( ) ;
2939 } ) ;
3040
31- test ( 'it filters namespaces based on search input' , async function ( assert ) {
32- assert . expect ( 7 ) ;
41+ test ( 'it focuses the search input field when the component is loaded' , async function ( assert ) {
42+ await click ( NAMESPACE_PICKER_SELECTORS . toggle ) ;
43+
44+ // Verify that the search input field is focused
45+ const searchInput = find ( NAMESPACE_PICKER_SELECTORS . searchInput ) ;
46+ assert . strictEqual (
47+ document . activeElement ,
48+ searchInput ,
49+ 'The search input field is focused on component load'
50+ ) ;
51+ } ) ;
3352
53+ test ( 'it navigates to the matching namespace when Enter is pressed' , async function ( assert ) {
3454 await click ( NAMESPACE_PICKER_SELECTORS . toggle ) ;
3555
36- // Verify all namespaces are displayed initially
37- assert . dom ( NAMESPACE_PICKER_SELECTORS . link ( ) ) . exists ( 'Namespace link(s) exist' ) ;
56+ // Simulate typing into the search input
57+ await fillIn ( NAMESPACE_PICKER_SELECTORS . searchInput , 'beep/boop' ) ;
58+ assert
59+ . dom ( NAMESPACE_PICKER_SELECTORS . searchInput )
60+ . hasValue ( 'beep/boop' , 'The search input field has the correct value' ) ;
61+
62+ // Simulate pressing Enter
63+ await triggerKeyEvent ( NAMESPACE_PICKER_SELECTORS . searchInput , 'keydown' , 'Enter' ) ;
64+
65+ // Verify navigation to the matching namespace
3866 assert . strictEqual (
39- findAll ( NAMESPACE_PICKER_SELECTORS . link ( ) ) . length ,
40- 5 ,
41- 'All namespaces are displayed initially '
67+ this . owner . lookup ( 'service:router' ) . currentURL ,
68+ '/vault/dashboard?namespace=beep%2Fboop' ,
69+ 'Navigates to the correct namespace when Enter is pressed '
4270 ) ;
71+ } ) ;
72+
73+ test ( 'it filters namespaces based on search input' , async function ( assert ) {
74+ await click ( NAMESPACE_PICKER_SELECTORS . toggle ) ;
75+
76+ // Verify all namespaces are displayed initially
77+ assert . dom ( NAMESPACE_PICKER_SELECTORS . link ( ) ) . exists ( 'Namespace link(s) exist' ) ;
78+ const allNamespaces = findAll ( NAMESPACE_PICKER_SELECTORS . link ( ) ) ;
4379
4480 // Verify the search input field exists
45- assert . dom ( '[type="search"]' ) . exists ( 'The namespace search field exists' ) ;
81+ assert . dom ( NAMESPACE_PICKER_SELECTORS . searchInput ) . exists ( 'The namespace search field exists' ) ;
4682
4783 // Verify 3 namespaces are displayed after searching for "beep"
48- await fillIn ( '[type="search"]' , 'beep' ) ;
84+ await fillIn ( NAMESPACE_PICKER_SELECTORS . searchInput , 'beep' ) ;
4985 assert . strictEqual (
5086 findAll ( NAMESPACE_PICKER_SELECTORS . link ( ) ) . length ,
5187 3 ,
5288 'Display 3 namespaces matching "beep" after searching'
5389 ) ;
5490
5591 // Verify 1 namespace is displayed after searching for "bop"
56- await fillIn ( '[type="search"]' , 'bop' ) ;
92+ await fillIn ( NAMESPACE_PICKER_SELECTORS . searchInput , 'bop' ) ;
5793 assert . strictEqual (
5894 findAll ( NAMESPACE_PICKER_SELECTORS . link ( ) ) . length ,
5995 1 ,
6096 'Display 1 namespace matching "bop" after searching'
6197 ) ;
6298
6399 // Verify no namespaces are displayed after searching for "other"
64- await fillIn ( '[type="search"]' , 'other' ) ;
100+ await fillIn ( NAMESPACE_PICKER_SELECTORS . searchInput , 'other' ) ;
65101 assert . strictEqual (
66102 findAll ( NAMESPACE_PICKER_SELECTORS . link ( ) ) . length ,
67103 0 ,
68104 'No namespaces are displayed after searching for "other"'
69105 ) ;
70106
71107 // Clear the search input & verify all namespaces are displayed again
72- await fillIn ( '[type="search"]' , '' ) ;
108+ await fillIn ( NAMESPACE_PICKER_SELECTORS . searchInput , '' ) ;
73109 assert . strictEqual (
74110 findAll ( NAMESPACE_PICKER_SELECTORS . link ( ) ) . length ,
75- 5 ,
111+ allNamespaces . length ,
76112 'All namespaces are displayed after clearing search input'
77113 ) ;
78114 } ) ;
79115
80116 test ( 'it updates the namespace list after clicking "Refresh list"' , async function ( assert ) {
81- assert . expect ( 3 ) ;
82-
83117 await click ( NAMESPACE_PICKER_SELECTORS . toggle ) ;
84118
85119 // Verify that the namespace list was fetched on load
@@ -108,8 +142,6 @@ module('Acceptance | Enterprise | namespaces', function (hooks) {
108142 } ) ;
109143
110144 test ( 'it displays the "Manage" button with the correct URL' , async function ( assert ) {
111- assert . expect ( 1 ) ;
112-
113145 await click ( NAMESPACE_PICKER_SELECTORS . toggle ) ;
114146
115147 // Verify the "Manage" button is rendered and has the correct URL
@@ -154,6 +186,7 @@ module('Acceptance | Enterprise | namespaces', function (hooks) {
154186
155187 // check that the full namespace path, like "beep/boop", shows in the toggle display
156188 await waitFor ( NAMESPACE_PICKER_SELECTORS . link ( targetNamespace ) ) ;
189+
157190 assert
158191 . dom ( NAMESPACE_PICKER_SELECTORS . link ( targetNamespace ) )
159192 . hasText ( targetNamespace , `shows the namespace ${ targetNamespace } in the toggle component` ) ;
@@ -170,14 +203,12 @@ module('Acceptance | Enterprise | namespaces', function (hooks) {
170203 await waitFor ( `svg${ GENERAL . icon ( 'check' ) } ` ) ;
171204
172205 // Find the selected element with the check icon & ensure it exists
173- const checkIcon = document . querySelector (
174- `${ NAMESPACE_PICKER_SELECTORS . link ( ) } svg${ GENERAL . icon ( 'check' ) } `
175- ) ;
176- assert . ok ( checkIcon , 'A selected namespace link with the check icon exists' ) ;
206+ const checkIcon = find ( `${ NAMESPACE_PICKER_SELECTORS . link ( ) } ${ GENERAL . icon ( 'check' ) } ` ) ;
207+ assert . dom ( checkIcon ) . exists ( 'A selected namespace link with the check icon exists' ) ;
177208
178209 // Get the selected namespace with the data-test-namespace-link attribute & ensure it exists
179- const selectedNamespace = checkIcon . closest ( NAMESPACE_PICKER_SELECTORS . link ( ) ) ;
180- assert . ok ( selectedNamespace , 'The selected namespace link exists' ) ;
210+ const selectedNamespace = checkIcon ? .closest ( NAMESPACE_PICKER_SELECTORS . link ( ) ) ;
211+ assert . dom ( selectedNamespace ) . exists ( 'The selected namespace link exists' ) ;
181212
182213 // Verify that the selected namespace has the correct data-test-namespace-link attribute and path value
183214 assert . strictEqual (
0 commit comments