Initial commit: Complete NodeJS-native setup
- Migrated from Python pre-commit to NodeJS-native solution - Reorganized documentation structure - Set up Husky + lint-staged for efficient pre-commit hooks - Fixed Dockerfile healthcheck issue - Added comprehensive documentation index
This commit is contained in:
131
tests/e2e/helpers.ts
Normal file
131
tests/e2e/helpers.ts
Normal file
@@ -0,0 +1,131 @@
|
||||
// E2E Test Utilities and Helpers
|
||||
|
||||
export class MedicationHelpers {
|
||||
constructor(private page: any) {}
|
||||
|
||||
async addMedication(
|
||||
name: string,
|
||||
dosage: string,
|
||||
frequency: string = 'daily',
|
||||
times: string = '1'
|
||||
) {
|
||||
await this.page.click('button:has-text("Add Medication")');
|
||||
await this.page.fill('input[name="name"]', name);
|
||||
await this.page.fill('input[name="dosage"]', dosage);
|
||||
await this.page.selectOption('select[name="frequency"]', frequency);
|
||||
if (times !== '1') {
|
||||
await this.page.fill('input[name="times"]', times);
|
||||
}
|
||||
await this.page.click('button[type="submit"]');
|
||||
|
||||
// Wait for medication to appear
|
||||
await this.page.waitForSelector(`text=${name}`);
|
||||
}
|
||||
|
||||
async deleteMedication(name: string) {
|
||||
await this.page.click('button:has-text("Manage")');
|
||||
|
||||
// Find the medication row and click delete
|
||||
const medicationRow = this.page.locator(`tr:has-text("${name}")`);
|
||||
await medicationRow.locator('[data-testid="delete-medication"]').click();
|
||||
await this.page.click('button:has-text("Delete")');
|
||||
|
||||
// Close manage modal
|
||||
await this.page.click('button:has-text("Close")');
|
||||
}
|
||||
|
||||
async takeDose(medicationName: string) {
|
||||
const doseCard = this.page.locator(
|
||||
`.dose-card:has-text("${medicationName}")`
|
||||
);
|
||||
await doseCard.locator('button:has-text("Take")').click();
|
||||
}
|
||||
}
|
||||
|
||||
export class AuthHelpers {
|
||||
constructor(private page: any) {}
|
||||
|
||||
async loginAsAdmin() {
|
||||
await this.page.goto('/');
|
||||
await this.page.fill('input[type="email"]', 'admin@localhost');
|
||||
await this.page.fill('input[type="password"]', 'admin123!');
|
||||
await this.page.click('button[type="submit"]');
|
||||
await this.page.waitForSelector('h1:has-text("Medication Reminder")');
|
||||
}
|
||||
|
||||
async registerUser(email: string, username: string, password: string) {
|
||||
await this.page.goto('/');
|
||||
await this.page.click('text=Register');
|
||||
await this.page.fill('input[type="email"]', email);
|
||||
await this.page.fill('input[name="username"]', username);
|
||||
await this.page.fill('input[type="password"]', password);
|
||||
await this.page.click('button[type="submit"]');
|
||||
}
|
||||
|
||||
async logout() {
|
||||
await this.page.click('[data-testid="avatar-dropdown"]');
|
||||
await this.page.click('button:has-text("Logout")');
|
||||
await this.page.waitForSelector('h2:has-text("Sign In")');
|
||||
}
|
||||
}
|
||||
|
||||
export class ModalHelpers {
|
||||
constructor(private page: any) {}
|
||||
|
||||
async openModal(buttonText: string) {
|
||||
await this.page.click(`button:has-text("${buttonText}")`);
|
||||
}
|
||||
|
||||
async closeModal() {
|
||||
await this.page.click('button:has-text("Close")');
|
||||
}
|
||||
|
||||
async confirmAction() {
|
||||
await this.page.click('button:has-text("Confirm")');
|
||||
}
|
||||
}
|
||||
|
||||
export class WaitHelpers {
|
||||
constructor(private page: any) {}
|
||||
|
||||
async waitForAppLoad() {
|
||||
await this.page.waitForSelector('h1:has-text("Medication Reminder")');
|
||||
}
|
||||
|
||||
async waitForModal(title: string) {
|
||||
await this.page.waitForSelector(`text=${title}`);
|
||||
}
|
||||
|
||||
async waitForNotification(message: string) {
|
||||
await this.page.waitForSelector(`text=${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Data generators for testing
|
||||
export const TestData = {
|
||||
medications: [
|
||||
{ name: 'Aspirin', dosage: '100mg', frequency: 'daily', times: '1' },
|
||||
{ name: 'Vitamin D', dosage: '1000 IU', frequency: 'daily', times: '1' },
|
||||
{ name: 'Omega-3', dosage: '500mg', frequency: 'daily', times: '2' },
|
||||
{ name: 'Calcium', dosage: '600mg', frequency: 'twice_daily', times: '1' },
|
||||
],
|
||||
|
||||
users: [
|
||||
{
|
||||
email: 'test1@example.com',
|
||||
username: 'testuser1',
|
||||
password: 'TestPass123!',
|
||||
},
|
||||
{
|
||||
email: 'test2@example.com',
|
||||
username: 'testuser2',
|
||||
password: 'TestPass456!',
|
||||
},
|
||||
],
|
||||
|
||||
reminders: [
|
||||
{ title: 'Drink Water', icon: 'bell', frequency: 60 },
|
||||
{ title: 'Exercise', icon: 'heart', frequency: 1440 }, // Daily
|
||||
{ title: 'Check Blood Pressure', icon: 'chart', frequency: 10080 }, // Weekly
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user