mirror of
				https://github.com/strapi/strapi.git
				synced 2025-10-31 18:08:11 +00:00 
			
		
		
		
	chore: sync e2e tests with v5 branch (#20334)
This commit is contained in:
		
							parent
							
								
									c413ad99eb
								
							
						
					
					
						commit
						48a7b1e909
					
				| @ -1,6 +1,8 @@ | ||||
| const { CUSTOM_TRANSFER_TOKEN_ACCESS_KEY } = require('./app-template/template/src/constants'); | ||||
| export const { | ||||
|   CUSTOM_TRANSFER_TOKEN_ACCESS_KEY, | ||||
| } = require('./app-template/template/src/constants'); | ||||
| 
 | ||||
| const ALLOWED_CONTENT_TYPES = [ | ||||
| export const ALLOWED_CONTENT_TYPES = [ | ||||
|   'admin::user', | ||||
|   'admin::role', | ||||
|   'admin::permission', | ||||
| @ -18,15 +20,11 @@ const ALLOWED_CONTENT_TYPES = [ | ||||
|   'plugin::upload.file', | ||||
| ]; | ||||
| 
 | ||||
| export const TITLE_LOGIN = 'Strapi Admin'; | ||||
| export const TITLE_HOME = 'Homepage'; | ||||
| 
 | ||||
| // TODO: we should start using @strapi.io addresses to have the chance one day to
 | ||||
| // actually receive and check the emails; also: it is not nice to spam other peoples
 | ||||
| // websites
 | ||||
| const ADMIN_EMAIL_ADDRESS = 'test@testing.com'; | ||||
| const ADMIN_PASSWORD = 'Testing123!'; | ||||
| 
 | ||||
| module.exports = { | ||||
|   ADMIN_EMAIL_ADDRESS, | ||||
|   ADMIN_PASSWORD, | ||||
|   ALLOWED_CONTENT_TYPES, | ||||
|   CUSTOM_TRANSFER_TOKEN_ACCESS_KEY, | ||||
| }; | ||||
| export const ADMIN_EMAIL_ADDRESS = 'test@testing.com'; | ||||
| export const ADMIN_PASSWORD = 'Testing123!'; | ||||
							
								
								
									
										52
									
								
								tests/e2e/tests/admin/api-tokens.spec.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								tests/e2e/tests/admin/api-tokens.spec.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,52 @@ | ||||
| import { test, expect } from '@playwright/test'; | ||||
| import { login } from '../../utils/login'; | ||||
| import { navToHeader } from '../../utils/shared'; | ||||
| import { resetDatabaseAndImportDataFromPath } from '../../utils/dts-import'; | ||||
| 
 | ||||
| const createAPIToken = async (page, tokenName, duration, type) => { | ||||
|   await navToHeader(page, ['Settings', 'API Tokens', 'Create new API Token'], 'Create API 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('Make sure to copy this token')).toBeVisible(); | ||||
|   await expect(page.getByText('Expiration date:')).toBeVisible(); | ||||
| }; | ||||
| 
 | ||||
| test.describe('API Tokens', () => { | ||||
|   test.beforeEach(async ({ page }) => { | ||||
|     await resetDatabaseAndImportDataFromPath('with-admin.tar'); | ||||
|     await page.goto('/admin'); | ||||
|     await login({ page }); | ||||
|   }); | ||||
| 
 | ||||
|   // Test token creation
 | ||||
|   const testCases = [ | ||||
|     ['30-day Read-only token', '30 days', 'Read-only'], | ||||
|     ['30-day full-access token', '30 days', 'Full access'], | ||||
|     ['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 createAPIToken(page, name, duration, type); | ||||
|     }); | ||||
|   } | ||||
| 
 | ||||
|   test('Created tokens list page should be correct', async ({ page }) => { | ||||
|     await createAPIToken(page, 'my test token', 'unlimited', 'Full access'); | ||||
|     await navToHeader(page, ['Settings', 'API Tokens'], 'API Tokens'); | ||||
| 
 | ||||
|     const row = page.getByRole('gridcell', { name: 'my test token', exact: true }); | ||||
|     await expect(row).toBeVisible(); | ||||
|   }); | ||||
| }); | ||||
| @ -1,7 +1,7 @@ | ||||
| import { test, expect } from '@playwright/test'; | ||||
| import { resetDatabaseAndImportDataFromPath } from '../../utils/dts-import'; | ||||
| import { toggleRateLimiting } from '../../utils/rate-limit'; | ||||
| import { ADMIN_EMAIL_ADDRESS, ADMIN_PASSWORD } from '../../constants'; | ||||
| import { ADMIN_EMAIL_ADDRESS, ADMIN_PASSWORD, TITLE_HOME, TITLE_LOGIN } from '../../constants'; | ||||
| import { login } from '../../utils/login'; | ||||
| 
 | ||||
| test.describe('Login', () => { | ||||
| @ -17,23 +17,23 @@ test.describe('Login', () => { | ||||
|     }) => { | ||||
|       // Test without making user authentication persistent
 | ||||
|       await login({ page }); | ||||
|       await expect(page).toHaveTitle('Homepage'); | ||||
|       await expect(page).toHaveTitle(TITLE_HOME); | ||||
| 
 | ||||
|       await page.close(); | ||||
| 
 | ||||
|       page = await context.newPage(); | ||||
|       await page.goto('/admin'); | ||||
|       await expect(page).toHaveTitle('Strapi Admin'); | ||||
|       await expect(page).toHaveTitle(TITLE_LOGIN); | ||||
| 
 | ||||
|       // Test with making user authentication persistent
 | ||||
|       await login({ page, rememberMe: true }); | ||||
|       await expect(page).toHaveTitle('Homepage'); | ||||
|       await expect(page).toHaveTitle(TITLE_HOME); | ||||
| 
 | ||||
|       await page.close(); | ||||
| 
 | ||||
|       page = await context.newPage(); | ||||
|       await page.goto('/admin'); | ||||
|       await expect(page).toHaveTitle('Homepage'); | ||||
|       await expect(page).toHaveTitle(TITLE_HOME); | ||||
|     }); | ||||
|   }); | ||||
| 
 | ||||
| @ -1,7 +1,7 @@ | ||||
| import { test, expect } from '@playwright/test'; | ||||
| 
 | ||||
| import { resetDatabaseAndImportDataFromPath } from '../../utils/dts-import'; | ||||
| import { ADMIN_EMAIL_ADDRESS, ADMIN_PASSWORD } from '../../constants'; | ||||
| import { ADMIN_EMAIL_ADDRESS, ADMIN_PASSWORD, TITLE_HOME } from '../../constants'; | ||||
| 
 | ||||
| /** | ||||
|  * Fill in the sign up form with valid values | ||||
| @ -96,6 +96,6 @@ test.describe('Sign Up', () => { | ||||
|   }) => { | ||||
|     await page.getByRole('button', { name: "Let's start" }).click(); | ||||
| 
 | ||||
|     await expect(page).toHaveTitle('Homepage'); | ||||
|     await expect(page).toHaveTitle(TITLE_HOME); | ||||
|   }); | ||||
| }); | ||||
| @ -1,7 +1,7 @@ | ||||
| import { test, expect } from '@playwright/test'; | ||||
| import { login } from '../../../utils/login'; | ||||
| import { resetDatabaseAndImportDataFromPath } from '../../../utils/dts-import'; | ||||
| import { navToHeader } from '../../../utils/shared'; | ||||
| import { login } from '../../utils/login'; | ||||
| import { resetDatabaseAndImportDataFromPath } from '../../utils/dts-import'; | ||||
| import { navToHeader } from '../../utils/shared'; | ||||
| 
 | ||||
| const createTransferToken = async (page, tokenName, duration, type) => { | ||||
|   await navToHeader( | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Ben Irvin
						Ben Irvin