mirror of
https://github.com/RealKai42/qwerty-learner.git
synced 2026-04-04 22:09:04 +08:00
* docs: update README, add deploy to vercel * docs: update README * feat: add e2e tests * feat: add main feature e2e tests with playwright * fix: ci env value and update gitignore * fix: ci job conditions for execution * chore: merge from main --------- Co-authored-by: KaiyiWing <Zhang.kaiyi42@gmail.com>
91 lines
3.3 KiB
TypeScript
91 lines
3.3 KiB
TypeScript
import { test, expect } from '@playwright/test'
|
|
|
|
test.describe('Dictionary manage', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto('/')
|
|
await page.getByLabel('关闭提示').click()
|
|
})
|
|
|
|
test('Homepage default dictionary', async ({ page }) => {
|
|
await expect(await page.getByText('CET-4').isVisible()).toBeTruthy()
|
|
|
|
await page.getByText('CET-4').hover()
|
|
await expect(await page.getByText('词典切换').isVisible()).toBeTruthy()
|
|
})
|
|
|
|
test('Switch language', async ({ page }) => {
|
|
await page.getByText('CET-4').click()
|
|
await page.waitForURL('**/gallery')
|
|
|
|
await expect(await page.getByRole('radio', { name: /^英语$/ }).getAttribute('aria-checked')).toBeTruthy()
|
|
|
|
await page.getByRole('radio', { name: /^日语$/ }).click()
|
|
await expect(await page.getByRole('radio', { name: /^日语$/ }).getAttribute('aria-checked')).toBeTruthy()
|
|
await expect(
|
|
await page
|
|
.getByRole('button', { name: /日语常见词/g })
|
|
.first()
|
|
.isVisible(),
|
|
).toBeTruthy()
|
|
|
|
await page.getByRole('radio', { name: /^Code$/ }).click()
|
|
await expect(await page.getByRole('radio', { name: /^Code$/ }).getAttribute('aria-checked')).toBeTruthy()
|
|
await expect(
|
|
await page
|
|
.getByRole('button', { name: /Coder Dict/g })
|
|
.first()
|
|
.isVisible(),
|
|
).toBeTruthy()
|
|
})
|
|
|
|
test('Switch category', async ({ page }) => {
|
|
await page.getByText('CET-4').click()
|
|
await page.waitForURL('**/gallery')
|
|
|
|
await expect(await page.getByRole('radio', { name: /^大学英语$/ }).getAttribute('aria-checked')).toBeTruthy()
|
|
|
|
await page.getByRole('radio', { name: /^考研$/ }).click()
|
|
await expect(await page.getByRole('radio', { name: /^考研$/ }).getAttribute('aria-checked')).toBeTruthy()
|
|
await expect(await page.getByRole('button', { name: /考研/g }).first().isVisible()).toBeTruthy()
|
|
|
|
await page.getByRole('radio', { name: /^GRE$/ }).click()
|
|
await expect(await page.getByRole('radio', { name: /^GRE$/ }).getAttribute('aria-checked')).toBeTruthy()
|
|
await expect(await page.getByRole('button', { name: /GRE/g }).first().isVisible()).toBeTruthy()
|
|
})
|
|
|
|
test('Switch dictionary', async ({ page }) => {
|
|
await page.getByText('CET-4').click()
|
|
await page.waitForURL('**/gallery')
|
|
|
|
await page
|
|
.getByRole('button', { name: /六级巧记速记/g })
|
|
.first()
|
|
.click()
|
|
await page.getByRole('heading', { name: '第 2 章' }).click()
|
|
|
|
await page.waitForURL('**/')
|
|
await expect(await page.getByRole('button', { name: '第 2 章' }).first().isVisible()).toBeTruthy()
|
|
})
|
|
|
|
test('Close dictionary settings', async ({ page }) => {
|
|
await page.getByText('CET-4').click()
|
|
await page.waitForURL('**/gallery')
|
|
// should use testId
|
|
await page.locator('main > div > svg').first().click()
|
|
|
|
await page.waitForURL('**/')
|
|
await expect(await page.getByText('Start').first().isVisible()).toBeTruthy()
|
|
})
|
|
|
|
test('Switch dictionary chapter', async ({ page }) => {
|
|
await page.getByText('第 1 章').first().hover()
|
|
await expect(await page.getByText('章节切换').isVisible()).toBeTruthy()
|
|
|
|
await page.getByText('第 1 章').click()
|
|
await page.getByRole('option', { name: '第 2 章' }).click()
|
|
|
|
await page.getByText('第 2 章').first().hover()
|
|
await expect(await page.getByText('章节切换').isVisible()).toBeTruthy()
|
|
})
|
|
})
|