test(*): Add POM to BDD tests

This commit is contained in:
Josh Creek
2025-04-24 10:02:33 +01:00
parent a7c1d60db8
commit b8130f4b0b
9 changed files with 201 additions and 50 deletions
+12
View File
@@ -0,0 +1,12 @@
import type { Page } from '@playwright/test';
export class HomePage {
readonly page: Page;
constructor(page: Page) {
this.page = page;
}
async navigateTo() {
await this.page.goto('http://localhost:5173/');
}
}
+91
View File
@@ -0,0 +1,91 @@
import type { Page } from '@playwright/test';
export class ResultsPage {
readonly page: Page;
constructor(page: Page) {
this.page = page;
}
headingSelector = '[data-testid="results-heading"]';
feedbackSelector = '[data-testid="feedback"]';
gradeSelector = '[data-testid="feedback"] div:has(span:has-text("Grade:"))';
strengthsSelector = '[data-testid="feedback"] div:has(span:has-text("Strengths:"))';
areasForImprovementSelector = '[data-testid="feedback"] div:has(span:has-text("Areas for Improvement:"))';
individualizedActivitySelector = '[data-testid="feedback"] div:has(span:has-text("Individualized Activity:"))';
reflectionQuestionSelector = '[data-testid="feedback"] div:has(span:has-text("Reflection Question:"))';
teacherSuggestionSelector = '[data-testid="feedback"] div:has(span:has-text("Teacher Suggestion:"))';
spellingAndGrammarSelector = '[data-testid="feedback"] div:has(span:has-text("Spelling and Grammar:"))';
reasoningSummarySelector = '[data-testid="feedback"] details > summary';
reasoningTextSelector = '[data-testid="feedback"] details > div';
backToUploadSelector = 'a[aria-label="Back to upload page"]';
noResultsSelector = 'div[aria-live="polite"][role="status"]';
clearHistorySelector = 'button[aria-label="Clear all assessment history"]';
async navigateTo() {
await this.page.goto('http://localhost:5173/results');
}
async getHeadingText() {
return this.page.textContent(this.headingSelector);
}
async waitForHeadingVisible(timeout = 60000) {
await this.page.waitForSelector(this.headingSelector, { state: 'visible', timeout });
}
async isFeedbackVisible() {
return this.page.isVisible(this.feedbackSelector);
}
async waitForFeedbackVisible(timeout = 60000) {
await this.page.waitForSelector(this.feedbackSelector, { state: 'visible', timeout });
}
async getGrade() {
return this.page.textContent(this.gradeSelector);
}
async getStrengths() {
return this.page.textContent(this.strengthsSelector);
}
async getAreasForImprovement() {
return this.page.textContent(this.areasForImprovementSelector);
}
async getIndividualizedActivity() {
return this.page.textContent(this.individualizedActivitySelector);
}
async getReflectionQuestion() {
return this.page.textContent(this.reflectionQuestionSelector);
}
async getTeacherSuggestion() {
return this.page.textContent(this.teacherSuggestionSelector);
}
async getSpellingAndGrammar() {
return this.page.textContent(this.spellingAndGrammarSelector);
}
async expandReasoning() {
await this.page.click(this.reasoningSummarySelector);
}
async getReasoning() {
return this.page.textContent(this.reasoningTextSelector);
}
async clickBackToUpload() {
await this.page.click(this.backToUploadSelector);
}
async isNoResultsMessageVisible() {
return this.page.isVisible(this.noResultsSelector);
}
async clearHistory() {
await this.page.click(this.clearHistorySelector);
}
}
+37
View File
@@ -0,0 +1,37 @@
import type { Page } from '@playwright/test';
export class UploadPage {
readonly page: Page;
constructor(page: Page) {
this.page = page;
}
taskInputSelector = '[data-testid="task-input"]';
fileInputSelector = 'input[type="file"]';
submissionInputSelector = '[data-testid="submission-input"]';
submitButtonSelector = '[data-testid="submit-button"]';
async navigateTo() {
await this.page.goto('http://localhost:5173/upload');
}
async setTaskDescription(text: string) {
await this.page.fill(this.taskInputSelector, text);
}
async uploadFile(filePath: string) {
await this.page.setInputFiles(this.fileInputSelector, filePath);
}
async setSubmissionText(text: string) {
await this.page.fill(this.submissionInputSelector, text);
}
async submit() {
await this.page.click(this.submitButtonSelector);
}
async isSubmitButtonEnabled() {
return this.page.isEnabled(this.submitButtonSelector);
}
}