54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { Page, expect } from '@playwright/test';
|
|
|
|
export class FrontendNewsPage {
|
|
readonly page: Page;
|
|
|
|
constructor(page: Page) {
|
|
this.page = page;
|
|
}
|
|
|
|
async goto() {
|
|
await this.page.goto('/news');
|
|
await this.page.waitForLoadState('domcontentloaded');
|
|
}
|
|
|
|
async expectNewsListVisible() {
|
|
const newsCards = this.page.locator('article, [data-testid="news-card"]');
|
|
await expect(newsCards.first()).toBeVisible({ timeout: 10000 });
|
|
const count = await newsCards.count();
|
|
expect(count).toBeGreaterThan(0);
|
|
}
|
|
|
|
async clickFirstNews() {
|
|
const firstNews = this.page.locator('article a, [data-testid="news-card"] a').first();
|
|
if (await firstNews.count() > 0) {
|
|
await firstNews.click();
|
|
await this.page.waitForLoadState('domcontentloaded');
|
|
}
|
|
}
|
|
|
|
async expectNewsDetailVisible(expectedContent?: string) {
|
|
await expect(this.page.locator('h1')).toBeVisible();
|
|
if (expectedContent) {
|
|
await expect(this.page.locator(`text=${expectedContent}`)).toBeVisible();
|
|
}
|
|
}
|
|
|
|
async expectNewsVisible(title: string) {
|
|
await this.goto();
|
|
const newsCard = this.page.locator(`article:has-text("${title}"), [data-testid="news-card"]:has-text("${title}")`);
|
|
await expect(newsCard).toBeVisible();
|
|
}
|
|
|
|
async expectNewsNotVisible(title: string) {
|
|
await this.goto();
|
|
const newsCard = this.page.locator(`article:has-text("${title}"), [data-testid="news-card"]:has-text("${title}")`);
|
|
await expect(newsCard).not.toBeVisible();
|
|
}
|
|
|
|
async clickNews(title: string) {
|
|
await this.page.locator(`text="${title}"`).click();
|
|
await this.page.waitForLoadState('domcontentloaded');
|
|
}
|
|
}
|