113 lines
3.7 KiB
TypeScript
113 lines
3.7 KiB
TypeScript
import { Page, Locator } from '@playwright/test';
|
|
import path from 'path';
|
|
|
|
export class NewsAdminPage {
|
|
readonly page: Page;
|
|
|
|
// Авторизация
|
|
readonly emailInput: Locator;
|
|
readonly passwordInput: Locator;
|
|
readonly loginButton: Locator;
|
|
|
|
// Навигация
|
|
readonly adminPanelLink: Locator;
|
|
|
|
// Элементы добавления новости
|
|
readonly addNewsButton: Locator;
|
|
readonly titleTextarea: Locator;
|
|
readonly contentTextarea: Locator;
|
|
readonly fileInput: Locator;
|
|
readonly cropSaveButton: Locator;
|
|
readonly confirmAddButton: Locator;
|
|
|
|
// Таблица новостей
|
|
readonly newsTable: Locator;
|
|
|
|
// Ошибки
|
|
readonly emptyTitleError: Locator;
|
|
readonly emptyContentError: Locator;
|
|
|
|
constructor(page: Page) {
|
|
this.page = page;
|
|
|
|
// Авторизация
|
|
this.emailInput = page.getByPlaceholder('Email');
|
|
this.passwordInput = page.getByPlaceholder('Пароль');
|
|
this.loginButton = page.getByRole('button', { name: 'Войти', exact: true });
|
|
|
|
// Навигация
|
|
this.adminPanelLink = page.getByText('Панель администратора');
|
|
|
|
// Форма добавления новости
|
|
this.addNewsButton = page.getByRole('button', { name: 'Добавить новость' });
|
|
this.titleTextarea = page.getByPlaceholder('Заголовок');
|
|
this.contentTextarea = page.getByPlaceholder('Текст новости');
|
|
this.fileInput = page.locator('input[type="file"]');
|
|
this.cropSaveButton = page.getByRole('button', { name: 'Сохранить' });
|
|
this.confirmAddButton = page.getByRole('button', { name: 'Добавить' });
|
|
|
|
// Таблица новостей
|
|
this.newsTable = page.locator('table');
|
|
|
|
// Ошибки валидации
|
|
this.emptyTitleError = page.getByText('Заголовок новости не может быть пустым.');
|
|
this.emptyContentError = page.getByText('Текст новости не может быть пустым.');
|
|
}
|
|
|
|
async loginAsAdmin() {
|
|
await this.page.goto('https://ssas.dev.rdcenter.ru/login/authorization');
|
|
await this.emailInput.fill('admin@sfedu.ru');
|
|
await this.passwordInput.fill('dfDk1oQQ6YGV@');
|
|
await this.loginButton.click();
|
|
}
|
|
|
|
async navigateToNewsSection() {
|
|
await this.page.waitForURL('**/');
|
|
await this.adminPanelLink.click();
|
|
await this.page.waitForURL('**/adminPage/news');
|
|
}
|
|
|
|
async goto() {
|
|
await this.page.waitForURL('**/');
|
|
await this.adminPanelLink.click();
|
|
await this.page.waitForURL('**/adminPage/news');
|
|
}
|
|
|
|
async addNews(params: { title: string; content: string; imagePath: string }) {
|
|
const { title, content, imagePath } = params;
|
|
|
|
await this.addNewsButton.click();
|
|
await this.titleTextarea.fill(title);
|
|
await this.contentTextarea.fill(content);
|
|
|
|
await this.fileInput.setInputFiles(imagePath);
|
|
await this.cropSaveButton.click();
|
|
await this.confirmAddButton.click();
|
|
}
|
|
|
|
async verifyNewsAppears(title: string) {
|
|
await this.page.waitForLoadState('networkidle');
|
|
await this.newsTable.waitFor();
|
|
await this.page.getByText(title).waitFor({ state: 'visible' });
|
|
}
|
|
|
|
async addEmptyNews() {
|
|
await this.addNewsButton.click();
|
|
await this.confirmAddButton.click();
|
|
}
|
|
|
|
async verifyValidationErrors() {
|
|
await this.emptyTitleError.waitFor({ state: 'visible' });
|
|
await this.emptyContentError.waitFor({ state: 'visible' });
|
|
}
|
|
|
|
async clickEditButtonForNews(title: string) {
|
|
await this.page.locator('tr', { hasText: title }).getByRole('button', { name: 'Редактировать' }).click();
|
|
}
|
|
|
|
async clickDeleteButtonForNews(title: string) {
|
|
await this.page.locator('tr', { hasText: title }).getByRole('button', { name: 'Удалить' }).click();
|
|
}
|
|
|
|
}
|