Skip to content

Commit 6fceef4

Browse files
committed
chore: fix tests
1 parent c43295b commit 6fceef4

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

integration/tests/machine-auth/component.test.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -109,39 +124,27 @@ testAgainstRunningApps({
109124

110125
const apiKeyName = `${fakeAdmin.firstName}-${Date.now()}`;
111126

112-
// Wait for create API response to get the secret
127+
// Create API key and capture the secret from the response
113128
const createResponsePromise = page.waitForResponse(
114129
response => response.url().includes('/api_keys') && response.request().method() === 'POST',
115130
);
116-
117-
// Create API key
118131
await u.po.apiKeys.clickAddButton();
119132
await u.po.apiKeys.waitForFormOpened();
120133
await u.po.apiKeys.typeName(apiKeyName);
121134
await u.po.apiKeys.selectExpiration('1d');
122135
await u.po.apiKeys.clickSaveButton();
123136

124-
// Get the secret from the create response
125137
const createResponse = await createResponsePromise;
126-
const apiKeyData = await createResponse.json();
127-
const secret = apiKeyData.secret;
138+
const secret = (await createResponse.json()).secret;
128139

129-
// Wait for the copy modal to appear
130-
const copyModal = page.locator('.cl-apiKeysCopyModal');
131-
await copyModal.waitFor({ state: 'attached' });
132-
133-
// Grant clipboard permissions before clicking the button
140+
// Copy secret via modal and verify clipboard contents
141+
// Wait and close copy modal
142+
await u.po.apiKeys.waitForCopyModalOpened();
134143
await context.grantPermissions(['clipboard-read']);
144+
await u.po.apiKeys.clickCopyAndCloseButton();
145+
await u.po.apiKeys.waitForCopyModalClosed();
146+
await u.po.apiKeys.waitForFormClosed();
135147

136-
// Click "Copy & Close" button which will copy the secret and close the modal
137-
const copyAndCloseButton = copyModal.locator('.cl-apiKeysCopyModalSubmitButton');
138-
await copyAndCloseButton.waitFor({ state: 'attached' });
139-
await copyAndCloseButton.click();
140-
141-
// Wait for modal to close
142-
await copyModal.waitFor({ state: 'detached' });
143-
144-
// Read clipboard contents to verify the secret was copied
145148
const clipboardText = await page.evaluate('navigator.clipboard.readText()');
146149
await context.clearPermissions();
147150
expect(clipboardText).toBe(secret);

packages/testing/src/playwright/unstable/page-objects/apiKeys.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ export const createAPIKeysComponentPageObject = (testArgs: { page: EnhancedPage
3535
waitForRevokeModalClosed: () => {
3636
return page.waitForSelector('.cl-apiKeysRevokeModal', { state: 'detached' });
3737
},
38+
waitForCopyModalOpened: () => {
39+
return page.waitForSelector('.cl-apiKeysCopyModal', { state: 'attached' });
40+
},
41+
waitForCopyModalClosed: () => {
42+
return page.waitForSelector('.cl-apiKeysCopyModal', { state: 'detached' });
43+
},
44+
clickCopyAndCloseButton: () => {
45+
return page.locator('.cl-apiKeysCopyModal .cl-apiKeysCopyModalSubmitButton').click();
46+
},
3847
typeName: (value: string) => {
3948
return page.getByLabel(/Secret key name/i).fill(value);
4049
},

0 commit comments

Comments
 (0)