From 8c1d8b2214cb391e15fa3c73dbed5c151869e80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A4=A9=E4=BD=91?= <66231260+You-Hw-Y@users.noreply.github.com> Date: Mon, 25 Dec 2023 02:58:19 -0800 Subject: [PATCH] test(calendar): [calendar] amend e2e test (#1200) * test(calender): [calender] amend e2e test * test(calendar): [calendar] amend e2e test * test(calendar): [calendar] amend e2e test * test(calendar): [calendar] amend e2e test * test(calendar): [calendar] amend e2e test * test(calendar): [calendar] amend e2e test * test(calendar): [calendar] amend e2e test * test(calendar): [calendar] amend e2e test * test(calendar): [calendar] amend e2e test * test(calendar): [calendar] amend e2e test * test(calendar): [calendar] amend e2e test --- .../demos/pc/app/calendar/basic-usage.spec.ts | 38 +++++++++++++++++++ .../pc/app/calendar/calender-mode.spec.ts | 38 +++++++++++++++++++ ...ustom-calendar-toolbar-composition-api.vue | 5 +++ .../calendar/custom-calendar-toolbar.spec.ts | 19 ++++++++++ .../app/calendar/custom-calendar-toolbar.vue | 19 +++++++--- .../pc/app/calendar/custom-day-cell.spec.ts | 10 +++++ .../app/calendar/dynamic-add-schedule.spec.ts | 26 +++++++++++++ .../app/calendar/show-selected-date.spec.ts | 14 +++++++ 8 files changed, 164 insertions(+), 5 deletions(-) create mode 100644 examples/sites/demos/pc/app/calendar/basic-usage.spec.ts create mode 100644 examples/sites/demos/pc/app/calendar/calender-mode.spec.ts create mode 100644 examples/sites/demos/pc/app/calendar/custom-calendar-toolbar.spec.ts create mode 100644 examples/sites/demos/pc/app/calendar/custom-day-cell.spec.ts create mode 100644 examples/sites/demos/pc/app/calendar/dynamic-add-schedule.spec.ts create mode 100644 examples/sites/demos/pc/app/calendar/show-selected-date.spec.ts diff --git a/examples/sites/demos/pc/app/calendar/basic-usage.spec.ts b/examples/sites/demos/pc/app/calendar/basic-usage.spec.ts new file mode 100644 index 000000000..5e68d9626 --- /dev/null +++ b/examples/sites/demos/pc/app/calendar/basic-usage.spec.ts @@ -0,0 +1,38 @@ +import { test, expect } from '@playwright/test' + +test('基本用法', async ({ page }) => { + page.on('pageerror', (exception) => expect(exception).toBeNull()) + await page.goto('calendar#basic-usage') + const pcDemo = page.locator('.pc-demo') + const nowDate = new Date().getDate() + const nowMonth = new Date().getMonth() + 1 + const selectedDay = page.getByRole('cell', { name: '14' }).locator('div').first() + const selectedMonth = page.getByRole('cell', { name: '7 月' }).locator('div').first() + // 校验日期,查看页面显示是否是月 + await pcDemo.getByRole('listitem').filter({ hasText: '月' }).nth(2).click() + await expect(pcDemo.locator('.tiny-calendar > div').last()).toHaveClass(/month/) + // 校验日期选择,选中的样式有selected + await selectedDay.click() + await expect(selectedDay).toHaveClass(/selected/) + // 校验今天按钮,选中的样式有selected today + await pcDemo.getByRole('button', { name: '今天' }).click() + await expect( + pcDemo + .getByRole('cell', { name: `${nowDate}` }) + .locator('div') + .first() + ).toHaveClass(/selected/) + + // 校验年里的月份代码逻辑一致 + await pcDemo.getByRole('listitem').filter({ hasText: '年' }).nth(2).click() + await expect(pcDemo.locator('.tiny-calendar > div').last()).toHaveClass(/year/) + await selectedMonth.click() + await expect(selectedMonth).toHaveClass(/selected/) + await pcDemo.getByRole('button', { name: '本月' }).click() + await expect( + pcDemo + .getByRole('cell', { name: `${nowMonth}` + ' 月' }) + .locator('div') + .first() + ).toHaveClass(/selected/) +}) diff --git a/examples/sites/demos/pc/app/calendar/calender-mode.spec.ts b/examples/sites/demos/pc/app/calendar/calender-mode.spec.ts new file mode 100644 index 000000000..e066f1561 --- /dev/null +++ b/examples/sites/demos/pc/app/calendar/calender-mode.spec.ts @@ -0,0 +1,38 @@ +import { test, expect } from '@playwright/test' + +test('显示模式', async ({ page }) => { + page.on('pageerror', (exception) => expect(exception).toBeNull()) + await page.goto('calendar#calendar-mode') + const pcDemo = page.locator('.pc-demo') + const nowDate = new Date().getDate() + const nowMonth = new Date().getMonth() + 1 + const selectedDay = page.getByRole('cell', { name: '14' }).locator('div').first() + const selectedMonth = page.getByRole('cell', { name: '7 月' }).locator('div').first() + // 校验日期,查看页面显示是否是月 + await pcDemo.getByRole('listitem').filter({ hasText: '月' }).nth(2).click() + await expect(pcDemo.locator('.tiny-calendar > div').last()).toHaveClass(/month/) + // 校验日期选择,选中的样式有selected + await selectedDay.click() + await expect(selectedDay).toHaveClass(/selected/) + // 校验今天按钮,选中的样式有selected today + await pcDemo.getByRole('button', { name: '今天' }).click() + await expect( + pcDemo + .getByRole('cell', { name: `${nowDate}` }) + .locator('div') + .first() + ).toHaveClass(/selected/) + + // 校验年里的月份代码逻辑一致 + await pcDemo.getByRole('listitem').filter({ hasText: '年' }).nth(2).click() + await expect(pcDemo.locator('.tiny-calendar > div').last()).toHaveClass(/year/) + await selectedMonth.click() + await expect(selectedMonth).toHaveClass(/selected/) + await pcDemo.getByRole('button', { name: '本月' }).click() + await expect( + pcDemo + .getByRole('cell', { name: `${nowMonth}` + ' 月' }) + .locator('div') + .first() + ).toHaveClass(/selected/) +}) diff --git a/examples/sites/demos/pc/app/calendar/custom-calendar-toolbar-composition-api.vue b/examples/sites/demos/pc/app/calendar/custom-calendar-toolbar-composition-api.vue index dccf58e9a..7ce557b92 100644 --- a/examples/sites/demos/pc/app/calendar/custom-calendar-toolbar-composition-api.vue +++ b/examples/sites/demos/pc/app/calendar/custom-calendar-toolbar-composition-api.vue @@ -1,4 +1,5 @@