-
Notifications
You must be signed in to change notification settings - Fork 484
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
7 changed files
with
106 additions
and
13 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
46 changes: 46 additions & 0 deletions
46
projects/demo-playwright/tests/kit/input-date/input-date.spec.ts
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,46 @@ | ||
import {TuiDocumentationPagePO, tuiGoto} from '@demo-playwright/utils'; | ||
import type {Locator} from '@playwright/test'; | ||
import {expect, test} from '@playwright/test'; | ||
|
||
import {TuiCalendarPO, TuiInputDatePO} from '../../../utils'; | ||
|
||
test.describe('InputDate', () => { | ||
test.describe('API', () => { | ||
let documentationPage: TuiDocumentationPagePO; | ||
let example: Locator; | ||
|
||
let inputDate!: TuiInputDatePO; | ||
let calendar!: TuiCalendarPO; | ||
|
||
test.use({ | ||
viewport: { | ||
width: 600, | ||
height: 800, | ||
}, | ||
}); | ||
|
||
test.beforeEach(({page}) => { | ||
documentationPage = new TuiDocumentationPagePO(page); | ||
example = documentationPage.apiPageExample; | ||
|
||
inputDate = new TuiInputDatePO(example.locator('tui-input-date')); | ||
|
||
calendar = new TuiCalendarPO(inputDate.calendar); | ||
}); | ||
|
||
test('Click any day after `Until today` was selected', async ({page}) => { | ||
await tuiGoto(page, 'components/input-date/API?items$=1'); | ||
|
||
await inputDate.textfield.click(); | ||
await calendar.itemButton.click(); | ||
|
||
await inputDate.textfield.click(); | ||
|
||
const [calendarSheet] = await calendar.getCalendarSheets(); | ||
|
||
await calendarSheet?.clickOnDay(1); | ||
|
||
await expect(inputDate.textfield).toHaveScreenshot('01-input-date.png'); | ||
}); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
projects/demo-playwright/utils/page-objects/calendar-sheet.po.ts
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,25 @@ | ||
import type {Locator} from '@playwright/test'; | ||
|
||
export class TuiCalendarSheetPO { | ||
constructor(private readonly host: Locator) {} | ||
|
||
async getDays(): Promise<Locator[]> { | ||
return this.host | ||
.locator( | ||
'[automation-id="tui-primitive-calendar__cell"], [automation-id="tui-primitive-calendar-mobile__cell"]', | ||
) | ||
.all(); | ||
} | ||
|
||
async clickOnDay(day: number): Promise<void> { | ||
const cells = await this.getDays(); | ||
|
||
for (const cell of cells) { | ||
if ((await cell.textContent())?.trim() === day.toString()) { | ||
await cell.click(); | ||
|
||
break; | ||
} | ||
} | ||
} | ||
} |
23 changes: 12 additions & 11 deletions
23
projects/demo-playwright/utils/page-objects/calendar.po.ts
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,19 +1,20 @@ | ||
import {Locator} from '@playwright/test'; | ||
|
||
import {TuiCalendarSheetPO} from './calendar-sheet.po'; | ||
|
||
export class TuiCalendarPO { | ||
constructor(private readonly host: Locator) {} | ||
readonly itemButton: Locator = this.host | ||
.page() | ||
.locator('tui-dropdown tui-calendar ~ * button'); | ||
|
||
async getDays(): Promise<Locator[]> { | ||
return this.host.locator('[automation-id="tui-primitive-calendar__cell"]').all(); | ||
} | ||
constructor(private readonly host: Locator) {} | ||
|
||
async clickOnCalendarDay(day: number): Promise<void> { | ||
const cells = await this.getDays(); | ||
async getCalendarSheets(): Promise<TuiCalendarSheetPO[]> { | ||
const locators = await this.host | ||
.page() | ||
.locator('tui-primitive-calendar, tui-primitive-calendar-mobile') | ||
.all(); | ||
|
||
for (const cell of cells) { | ||
if ((await cell.textContent())?.trim() === day.toString()) { | ||
return cell.click(); | ||
} | ||
} | ||
return locators.map(x => new TuiCalendarSheetPO(x)); | ||
} | ||
} |
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,8 @@ | ||
import {Locator} from '@playwright/test'; | ||
|
||
export class TuiInputDatePO { | ||
readonly textfield: Locator = this.host.getByRole('textbox'); | ||
readonly calendar: Locator = this.host.page().locator('tui-calendar'); | ||
|
||
constructor(private readonly host: Locator) {} | ||
} |
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