@@ -43,6 +43,10 @@ testAgainstRunningApps({
4343 await u . po . apiKeys . selectExpiration ( '1d' ) ;
4444 await u . po . apiKeys . clickSaveButton ( ) ;
4545
46+ // Close copy modal
47+ await u . po . apiKeys . waitForCopyModalOpened ( ) ;
48+ await u . po . apiKeys . clickCopyAndCloseButton ( ) ;
49+ await u . po . apiKeys . waitForCopyModalClosed ( ) ;
4650 await u . po . apiKeys . waitForFormClosed ( ) ;
4751
4852 // Create API key 2
@@ -52,8 +56,14 @@ testAgainstRunningApps({
5256 await u . po . apiKeys . selectExpiration ( '7d' ) ;
5357 await u . po . apiKeys . clickSaveButton ( ) ;
5458
59+ // Wait and close copy modal
60+ await u . po . apiKeys . waitForCopyModalOpened ( ) ;
61+ await u . po . apiKeys . clickCopyAndCloseButton ( ) ;
62+ await u . po . apiKeys . waitForCopyModalClosed ( ) ;
63+ await u . po . apiKeys . waitForFormClosed ( ) ;
64+
5565 // Check if both API keys are created
56- await expect ( u . page . locator ( '.cl-apiKeysTable .cl-tableRow' ) ) . toHaveCount ( 2 ) ;
66+ await expect ( u . page . locator ( '.cl-apiKeysTable .cl-tableBody .cl- tableRow' ) ) . toHaveCount ( 2 ) ;
5767 } ) ;
5868
5969 test ( 'can revoke api keys' , async ( { page, context } ) => {
@@ -74,6 +84,11 @@ testAgainstRunningApps({
7484 await u . po . apiKeys . typeName ( apiKeyName ) ;
7585 await u . po . apiKeys . selectExpiration ( '1d' ) ;
7686 await u . po . apiKeys . clickSaveButton ( ) ;
87+
88+ // Wait and close copy modal
89+ await u . po . apiKeys . waitForCopyModalOpened ( ) ;
90+ await u . po . apiKeys . clickCopyAndCloseButton ( ) ;
91+ await u . po . apiKeys . waitForCopyModalClosed ( ) ;
7792 await u . po . apiKeys . waitForFormClosed ( ) ;
7893
7994 // Retrieve API key
@@ -97,7 +112,7 @@ testAgainstRunningApps({
97112 await expect ( table . locator ( '.cl-tableRow' , { hasText : apiKeyName } ) ) . toHaveCount ( 0 ) ;
98113 } ) ;
99114
100- test ( 'can copy api key secret' , async ( { page, context } ) => {
115+ test ( 'can copy api key secret after creation ' , async ( { page, context } ) => {
101116 const u = createTestUtils ( { app, page, context } ) ;
102117 await u . po . signIn . goTo ( ) ;
103118 await u . po . signIn . waitForMounted ( ) ;
@@ -109,71 +124,30 @@ testAgainstRunningApps({
109124
110125 const apiKeyName = `${ fakeAdmin . firstName } -${ Date . now ( ) } ` ;
111126
112- // Create API key
127+ // Create API key and capture the secret from the response
128+ const createResponsePromise = page . waitForResponse (
129+ response => response . url ( ) . includes ( '/api_keys' ) && response . request ( ) . method ( ) === 'POST' ,
130+ ) ;
113131 await u . po . apiKeys . clickAddButton ( ) ;
114132 await u . po . apiKeys . waitForFormOpened ( ) ;
115133 await u . po . apiKeys . typeName ( apiKeyName ) ;
116134 await u . po . apiKeys . selectExpiration ( '1d' ) ;
117135 await u . po . apiKeys . clickSaveButton ( ) ;
118- await u . po . apiKeys . waitForFormClosed ( ) ;
119136
120- const responsePromise = page . waitForResponse (
121- response => response . url ( ) . includes ( '/secret' ) && response . request ( ) . method ( ) === 'GET' ,
122- ) ;
123-
124- // Copy API key
125- const table = u . page . locator ( '.cl-apiKeysTable' ) ;
126- const row = table . locator ( '.cl-tableRow' , { hasText : apiKeyName } ) ;
127- await row . waitFor ( { state : 'attached' } ) ;
128- await row . locator ( '.cl-apiKeysCopyButton' ) . click ( ) ;
137+ const createResponse = await createResponsePromise ;
138+ const secret = ( await createResponse . json ( ) ) . secret ;
129139
130- // Read clipboard contents
131- const data = await ( await responsePromise ) . json ( ) ;
140+ // Copy secret via modal and verify clipboard contents
141+ // Wait and close copy modal
142+ await u . po . apiKeys . waitForCopyModalOpened ( ) ;
132143 await context . grantPermissions ( [ 'clipboard-read' ] ) ;
133- const clipboardText = await page . evaluate ( 'navigator.clipboard.readText()' ) ;
134- await context . clearPermissions ( ) ;
135- expect ( clipboardText ) . toBe ( data . secret ) ;
136- } ) ;
137-
138- test ( 'can toggle api key secret visibility' , async ( { page, context } ) => {
139- const u = createTestUtils ( { app, page, context } ) ;
140- await u . po . signIn . goTo ( ) ;
141- await u . po . signIn . waitForMounted ( ) ;
142- await u . po . signIn . signInWithEmailAndInstantPassword ( { email : fakeAdmin . email , password : fakeAdmin . password } ) ;
143- await u . po . expect . toBeSignedIn ( ) ;
144-
145- await u . po . page . goToRelative ( '/api-keys' ) ;
146- await u . po . apiKeys . waitForMounted ( ) ;
147-
148- const apiKeyName = `${ fakeAdmin . firstName } -${ Date . now ( ) } ` ;
149-
150- // Create API key
151- await u . po . apiKeys . clickAddButton ( ) ;
152- await u . po . apiKeys . waitForFormOpened ( ) ;
153- await u . po . apiKeys . typeName ( apiKeyName ) ;
154- await u . po . apiKeys . selectExpiration ( '1d' ) ;
155- await u . po . apiKeys . clickSaveButton ( ) ;
144+ await u . po . apiKeys . clickCopyAndCloseButton ( ) ;
145+ await u . po . apiKeys . waitForCopyModalClosed ( ) ;
156146 await u . po . apiKeys . waitForFormClosed ( ) ;
157147
158- const responsePromise = page . waitForResponse (
159- response => response . url ( ) . includes ( '/secret' ) && response . request ( ) . method ( ) === 'GET' ,
160- ) ;
161-
162- // Toggle API key secret visibility
163- const table = u . page . locator ( '.cl-apiKeysTable' ) ;
164- const row = table . locator ( '.cl-tableRow' , { hasText : apiKeyName } ) ;
165- await row . waitFor ( { state : 'attached' } ) ;
166- await expect ( row . locator ( 'input' ) ) . toHaveAttribute ( 'type' , 'password' ) ;
167- await row . locator ( '.cl-apiKeysRevealButton' ) . click ( ) ;
168-
169- // Verify if secret matches the input value
170- const data = await ( await responsePromise ) . json ( ) ;
171- await expect ( row . locator ( 'input' ) ) . toHaveAttribute ( 'type' , 'text' ) ;
172- await expect ( row . locator ( 'input' ) ) . toHaveValue ( data . secret ) ;
173-
174- // Toggle visibility off
175- await row . locator ( '.cl-apiKeysRevealButton' ) . click ( ) ;
176- await expect ( row . locator ( 'input' ) ) . toHaveAttribute ( 'type' , 'password' ) ;
148+ const clipboardText = await page . evaluate ( 'navigator.clipboard.readText()' ) ;
149+ await context . clearPermissions ( ) ;
150+ expect ( clipboardText ) . toBe ( secret ) ;
177151 } ) ;
178152
179153 test ( 'component does not render for orgs when user does not have permissions' , async ( { page, context } ) => {
0 commit comments