From ba6d95cd56454b367b03cfbeaa55b9f49a5ee236 Mon Sep 17 00:00:00 2001 From: Quentin AUBERT Date: Tue, 8 Oct 2024 16:33:07 +0200 Subject: [PATCH] FIX playwright tests --- .../javascript/tests/connectedUser.spec.ts | 35 +++++---- daikoku/javascript/tests/envMode.spec.ts | 73 ++----------------- 2 files changed, 29 insertions(+), 79 deletions(-) diff --git a/daikoku/javascript/tests/connectedUser.spec.ts b/daikoku/javascript/tests/connectedUser.spec.ts index 7ea4c875a..0539db82d 100644 --- a/daikoku/javascript/tests/connectedUser.spec.ts +++ b/daikoku/javascript/tests/connectedUser.spec.ts @@ -326,7 +326,7 @@ test('Create & manage API', async ({ page }) => { * subscribe on second API and aggregate it * delete a key */ -test('aggregation mode', async ({ page, request }) => { +test('aggregation mode', async ({ page, request, context }) => { await request.post('http://localhost:9000/admin-api/usage-plans', { headers: { "Authorization": `Basic ${btoa(adminApikeyId + ":" + adminApikeySecret)}` @@ -368,6 +368,8 @@ test('aggregation mode', async ({ page, request }) => { ] }) + await context.grantPermissions(["clipboard-read", "clipboard-write"]); + //login await page.goto(`http://localhost:${exposedPort}/apis`); await page.getByRole('img', { name: 'user menu' }).click(); @@ -395,16 +397,18 @@ test('aggregation mode', async ({ page, request }) => { await page.getByRole('link', { name: 'APIs list' }).click(); await page.locator('.top__container').filter({ hasText: 'Your teams' }) .getByText('Consumers').click() - // await page.getByLabel('Notifications alt+T').getByRole('button').click(); await page.getByText('API keys', { exact: true }).click(); await page.getByRole('row', { name: 'test API 2 1.0.0' }).getByLabel('View APIkeys').click(); //get the client id value to check - const apikey = await page.locator('.api-subscription__infos__value').innerText() + await page.getByRole('button', { name: 'clientId:clientToken' }).click(); + const apikey = await page.evaluate(() => navigator.clipboard.readText()); await page.getByText('API keys', { exact: true }).click(); await page.getByRole('row', { name: 'test API 2.0.0' }).getByLabel('view APikey').click(); - await expect(page.locator('.api-subscription__infos__value').first()).toHaveText(apikey); + await page.getByRole('button', { name: 'clientId:clientToken' }).click(); + const apikey2 = await page.evaluate(() => navigator.clipboard.readText()); + await expect(apikey2).toBe(apikey) await page.locator('.api-subscription').locator('.dropdown').click(); await page.getByText('Show aggregate').click(); await expect(page.getByRole('link', { name: 'test API 2/test plan' })).toBeVisible(); @@ -413,16 +417,21 @@ test('aggregation mode', async ({ page, request }) => { await page.getByRole('row', { name: 'test API 2 1.0.0' }).getByLabel('view APikey').click(); await page.locator('.api-subscription').locator('.dropdown').click(); await page.getByText('Extract from aggregate').click(); - // await page.getByRole('button', { name: 'make unique' }).click(); await expect(page.getByRole('paragraph')).toContainText('Are you sure to make this API key unique and separate from his parent plan?'); await page.getByRole('button', { name: 'Ok', exact: true }).click(); - await expect(page.locator('.api-subscription__infos__value').first()).not.toHaveText(apikey); + await page.waitForResponse(r => r.url().includes('/_makeUnique') && r.status() === 200); + await page.reload(); + + await page.getByRole('button', { name: 'clientId:clientToken' }).click(); + const apikeyUniq = await page.evaluate(() => navigator.clipboard.readText()); + console.log({apikey, apikey2, apikeyUniq}) + await expect(apikeyUniq).not.toBe(apikey) + // //test archive apikey & clean archive apikeys await page.locator('.api-subscription').locator('.dropdown').click(); await page.getByText('Disable subscription').click(); await expect(page.locator('.api-subscription__value__type')).toHaveText('Disabled') - // await expect(page.getByRole('button', { name: 'Enable subscription' })).toBeVisible(); await page.locator('.api-subscription').locator('.dropdown').click(); await page.getByText('Delete').click(); @@ -586,7 +595,8 @@ test('Filter API List', async ({ page, request }) => { }) -test('transfer an api subscription', async ({ page }) => { +test('transfer an api subscription', async ({ page, context }) => { + await context.grantPermissions(["clipboard-read", "clipboard-write"]); await page.goto('http://localhost:5173/apis'); await page.getByRole('img', { name: 'user menu' }).click(); await page.getByPlaceholder('Email address').fill('tester@foo.bar'); @@ -602,17 +612,16 @@ test('transfer an api subscription', async ({ page }) => { await page.locator('div').filter({ hasText: /^fake prod plan/ }).getByRole('button').click(); await page.getByText('Consumers').click(); await page.getByLabel('Notifications').getByRole('img').nth(1).click(); - const apikey = await page.locator('.api-subscription__infos__value').innerText(); - - + await page.locator('.api-subscription__icon').isVisible(); + // await page.locator('.api-subscription__infos__value').innerText(); + await page.getByRole('button', { name: 'clientId:clientToken' }).click(); + const apikey = await page.evaluate(() => navigator.clipboard.readText()); await page.locator('#dropdownMenuButton').click(); await page.getByText('Transfer subscription').click(); await page.getByText('Display link').click(); const link = await page.locator('.api-susbcription__display-link').innerText(); - - await page.goto(link); await page.getByText('Testers').click(); await page.getByRole('button', { name: 'Confirm transfer' }).click(); diff --git a/daikoku/javascript/tests/envMode.spec.ts b/daikoku/javascript/tests/envMode.spec.ts index fc9fba824..9498416c2 100644 --- a/daikoku/javascript/tests/envMode.spec.ts +++ b/daikoku/javascript/tests/envMode.spec.ts @@ -95,73 +95,14 @@ test('aggregation security works', async ({ page, request }) => { await expect(page.getByRole('cell', { name: 'Child API' })).toBeVisible(); await expect(page.getByRole('cell', { name: 'Parent API' })).toBeVisible(); await page.getByRole('row', { name: 'Parent API 1.0.0 View API' }).getByLabel('View APIkeys').click(); - await expect(page.getByText('prod')).toBeVisible(); + // await expect(page.getByText('prod')).toBeVisible(); + await expect(page.locator('.api-subscription__infos__name')).toHaveText('prod') await page.getByText('API keys', { exact: true }).click(); await page.getByRole('cell', { name: 'Child API' }).click(); await page.getByRole('row', { name: 'Child API 1.0.0 View API View' }).getByLabel('View APIkeys').click(); - await expect(page.getByText('dev')).toBeVisible(); - await expect(page.getByText('prod')).toBeVisible(); - - - - // //subscribe first API - // await page.getByRole('heading', { name: 'Parent API', exact: true }).click(); - // await page.getByText('Environments').click(); - // await page.locator('.usage-plan__card').filter({ hasText: 'prod' }).getByRole('button').click(); - // await page.locator('div').filter({ hasText: /^Consumers$/ }).click(); - // await page.getByRole('link', { name: 'APIs list' }).click(); - - // //subscribe second api with aggregation - // await page.getByRole('heading', { name: 'Child API' }).click(); - // await page.getByText('Environments').click(); - // await page.locator('.usage-plan__card').filter({ hasText: 'dev' }).getByRole('button').click(); - // await page.locator('.team-selection').filter({ hasText: 'Consumers' }).click(); - // //no possibility to extends existing key - - - // //subscribe second api with aggregation - // await page.getByRole('link', { name: 'APIs list' }).click(); - // await page.getByRole('heading', { name: 'Child API' }).click(); - // await page.getByText('Environments').click(); - // await page.locator('.usage-plan__card').filter({ hasText: 'prod' }).getByRole('button').click(); - // await page.locator('.team-selection').filter({ hasText: 'Consumers' }).click(); - // await page.getByRole('button', { name: ' Subscribe using an existing' }).click(); - // await page.getByText('parent API/prod').click(); - - // //go to subscriptions - // await page.getByRole('link', { name: 'APIs list' }).click(); - // await page.locator('.top__container').filter({ hasText: 'Your teams' }) - // .getByText('Consumers').click() - // // await page.getByLabel('Notifications alt+T').getByRole('button').click(); - // await page.getByText('API keys', { exact: true }).click(); - // await page.getByRole('row', { name: 'test API 2 1.0.0' }).getByLabel('View APIkeys').click(); - - // //get the client id value to check - // const clientId = await page.getByLabel('Client Id').inputValue() - - // await page.getByText('API keys', { exact: true }).click(); - // await page.getByRole('row', { name: 'test API 2.0.0' }).getByLabel('view APikey').click(); - // await expect(page.getByLabel('Client Id').first()).toHaveValue(clientId); - // await page.getByRole('button', { name: 'Show aggregate subscriptions' }).click(); - // await expect(page.getByRole('link', { name: 'test API 2/test plan' })).toBeVisible(); - // await page.getByText('API keys', { exact: true }).click(); - // await page.getByRole('row', { name: 'test API 2 1.0.0' }).getByLabel('view APikey').click(); - // await page.getByRole('button', { name: 'make unique' }).click(); - // await expect(page.getByRole('paragraph')).toContainText('Are you sure to make this API key unique and separate from his parent plan?'); - // await page.getByRole('button', { name: 'Ok' }).click(); - // await expect(page.getByLabel('Client Id').first()).not.toHaveValue(clientId); - - // // //test archive apikey & clean archive apikeys - // await page.getByRole('button', { name: 'Disable subscription' }).click(); - // await expect(page.getByRole('button', { name: 'Enable subscription' })).toBeVisible(); - - // await page.getByLabel('Delete').click(); - // await expect(page.locator('h5')).toContainText('Confirm Deletion'); - // await page.getByLabel('To confirm the deletion,').fill('test API 2/test plan'); - // await page.getByRole('button', { name: 'Confirm' }).click(); - // await page.getByText('API keys', { exact: true }).click(); - // await expect(page.getByRole('row', { name: 'test API 2 1.0.0' })).toBeHidden - - - + + const apiKeys = await page.locator('.api-subscription__infos__name'); + expect(apiKeys).toHaveCount(2); + expect(apiKeys.nth(0)).toHaveText('dev'); + expect(apiKeys.nth(1)).toHaveText('prod'); }) \ No newline at end of file