forked from strapi/strapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
93 changed files
with
1,488 additions
and
702 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## End-to-end Playwright Tests | ||
|
||
See contributor docs in docs/docs/guides/e2e for more info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { CUSTOM_TRANSFER_TOKEN_ACCESS_KEY } = require('./constants'); | ||
|
||
/** | ||
* Make sure the test transfer token exists in the database | ||
* @param {Strapi.Strapi} strapi | ||
* @returns {Promise<void>} | ||
*/ | ||
const createTestTransferToken = async (strapi) => { | ||
const { token: transferTokenService } = strapi.admin.services.transfer; | ||
|
||
const accessKeyHash = transferTokenService.hash(CUSTOM_TRANSFER_TOKEN_ACCESS_KEY); | ||
const exists = await transferTokenService.exists({ accessKey: accessKeyHash }); | ||
|
||
if (!exists) { | ||
await transferTokenService.create({ | ||
name: 'TestToken', | ||
description: 'Transfer token used to seed the e2e database', | ||
lifespan: null, | ||
permissions: ['push'], | ||
accessKey: CUSTOM_TRANSFER_TOKEN_ACCESS_KEY, | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
createTestTransferToken, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { login } from '../../../utils/login'; | ||
import { resetDatabaseAndImportDataFromPath } from '../../../scripts/dts-import'; | ||
import { navToHeader, delay } from '../../../utils/shared'; | ||
|
||
const createTransferToken = async (page, tokenName, duration, type) => { | ||
await navToHeader( | ||
page, | ||
['Settings', 'Transfer Tokens', 'Create new Transfer Token'], | ||
'Create Transfer Token' | ||
); | ||
|
||
await page.getByLabel('Name*').click(); | ||
await page.getByLabel('Name*').fill(tokenName); | ||
|
||
await page.getByLabel('Token duration').click(); | ||
await page.getByRole('option', { name: duration }).click(); | ||
|
||
await page.getByLabel('Token type').click(); | ||
await page.getByRole('option', { name: type }).click(); | ||
|
||
await page.getByRole('button', { name: 'Save' }).click(); | ||
|
||
await expect(page.getByText(/copy this token/)).toBeVisible(); | ||
await expect(page.getByText('Expiration date:')).toBeVisible(); | ||
}; | ||
|
||
test.describe('Transfer Tokens', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await resetDatabaseAndImportDataFromPath('./e2e/data/with-admin.tar'); | ||
await page.goto('/admin'); | ||
await login({ page }); | ||
}); | ||
|
||
// Test token creation | ||
const testCases = [ | ||
['30-day push token', '30 days', 'Push'], | ||
['30-day pull token', '30 days', 'Pull'], | ||
['30-day full-access token', '30 days', 'Full access'], | ||
// if push+pull work generally that's good enough for e2e | ||
['7-day token', '7 days', 'Full access'], | ||
['90-day token', '90 days', 'Full access'], | ||
['unlimited token', 'Unlimited', 'Full access'], | ||
]; | ||
for (const [name, duration, type] of testCases) { | ||
test(`A user should be able to create a ${name}`, async ({ page }) => { | ||
await createTransferToken(page, name, duration, type); | ||
}); | ||
} | ||
|
||
test('Created tokens list page should be correct', async ({ page }) => { | ||
await createTransferToken(page, 'my test token', 'unlimited', 'Full access'); | ||
|
||
// if we don't wait until createdAt is at least 1s, we see "NaN" for the timestamp | ||
// TODO: fix the bug and remove this | ||
await page.waitForTimeout(1100); | ||
|
||
await navToHeader(page, ['Settings', 'Transfer Tokens'], 'Transfer Tokens'); | ||
|
||
const row = page.getByRole('gridcell', { name: 'my test token', exact: true }); | ||
await expect(row).toBeVisible(); | ||
await expect(page.getByText(/\d+ (second|minute)s? ago/)).toBeVisible(); | ||
// TODO: expand on this test, it could check edit and delete icons | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
import { test } from '@playwright/test'; | ||
import { test, Page, expect } from '@playwright/test'; | ||
|
||
/** | ||
* Execute a test suite only if the condition is true | ||
*/ | ||
export const describeOnCondition = (shouldDescribe: boolean) => | ||
shouldDescribe ? test.describe : test.describe.skip; | ||
|
||
/** | ||
* Navigate to a page and confirm the header, awaiting each step | ||
*/ | ||
export const navToHeader = async (page: Page, navItems: string[], headerText: string) => { | ||
for (const navItem of navItems) { | ||
// This does not use getByRole because sometimes "Settings" is "Settings 1" if there's a badge notification | ||
// BUT if we don't match exact it conflicts with "Advanceed Settings" | ||
// As a workaround, we implement our own startsWith with page.locator | ||
const item = page.locator(`role=link[name^="${navItem}"]`); | ||
await expect(item).toBeVisible(); | ||
await item.click(); | ||
} | ||
|
||
const header = page.getByRole('heading', { name: headerText, exact: true }); | ||
await expect(header).toBeVisible(); | ||
return header; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.