fix playwright tests (#759)
This commit is contained in:
@@ -3,6 +3,9 @@ import { test as teardown } from '@playwright/test';
|
||||
teardown('delete user', async ({ page }) => {
|
||||
await page.goto('/settings/account', { waitUntil: 'networkidle' });
|
||||
await page.locator("#delete-account").click();
|
||||
|
||||
// Wait for modal to appear
|
||||
await page.locator("#confirm").waitFor({ state: 'visible' });
|
||||
await page.locator("#confirm").click();
|
||||
|
||||
await page.waitForURL('/');
|
||||
|
||||
@@ -1,30 +1,39 @@
|
||||
import { test as base, expect } from '@playwright/test';
|
||||
import { ListsPage } from '../../pages/lists_page';
|
||||
|
||||
// Run tests serially to avoid race conditions with shared list data
|
||||
base.describe.configure({ mode: 'serial' });
|
||||
|
||||
const test = base.extend<{ listsPage: ListsPage }>({
|
||||
listsPage: async ({ page }, use) => {
|
||||
const listsPage = new ListsPage(page);
|
||||
await listsPage.goto();
|
||||
await listsPage.create();
|
||||
await use(listsPage);
|
||||
await listsPage.removeAll();
|
||||
},
|
||||
});
|
||||
|
||||
test('shows a list card', async ({ listsPage }) => {
|
||||
const testListName = `Test List ${Date.now()}`;
|
||||
const listItemCount = await listsPage.listItems.count();
|
||||
await listsPage.create();
|
||||
expect(listsPage.listItems).toHaveCount(listItemCount + 1);
|
||||
expect(listsPage.listItemsImage).toBeVisible();
|
||||
await listsPage.create(testListName);
|
||||
|
||||
await expect(listsPage.listItems).toHaveCount(listItemCount + 1);
|
||||
const createdListItem = listsPage.listItems.filter({ hasText: testListName });
|
||||
await expect(createdListItem).toBeVisible();
|
||||
await expect(createdListItem.getByRole('img', { name: 'list avatar' })).toBeVisible();
|
||||
});
|
||||
|
||||
test('update a list card', async ({ listsPage }) => {
|
||||
await listsPage.create("List to Update");
|
||||
await listsPage.update();
|
||||
expect(listsPage.listItems.first()).toContainText("Updated List");
|
||||
expect(listsPage.listItems.first()).toContainText("New Description");
|
||||
await expect(listsPage.listItems.first()).toContainText("Updated List");
|
||||
await expect(listsPage.listItems.first()).toContainText("New Description");
|
||||
});
|
||||
|
||||
test('delete a list card', async ({ listsPage }) => {
|
||||
await listsPage.create("List to Delete");
|
||||
const countBefore = await listsPage.listItems.count();
|
||||
await listsPage.delete();
|
||||
expect(listsPage.listItems).toHaveCount(0);
|
||||
await expect(listsPage.listItems).toHaveCount(countBefore - 1);
|
||||
});
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test('logs the user out', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
await page.getByRole('button', { name: 'avatar' }).click();
|
||||
await page.goto('/', { waitUntil: 'networkidle' });
|
||||
await page.getByLabel('Open user menu').click();
|
||||
await page.locator(".menu .menu-item").filter({ hasText: "Logout" }).click();
|
||||
|
||||
await page.waitForURL('/');
|
||||
|
||||
const cookies = await page.context().cookies();
|
||||
const pbAuthCookie = cookies.find(cookie => cookie.name === 'pb_auth');
|
||||
expect(pbAuthCookie).toBeFalsy();
|
||||
|
||||
@@ -10,14 +10,20 @@ export class IndexPage {
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/');
|
||||
await this.page.goto('/', { waitUntil: 'networkidle' });
|
||||
}
|
||||
|
||||
async search() {
|
||||
// Start waiting for response before triggering the search
|
||||
const responsePromise = this.page.waitForResponse(resp =>
|
||||
resp.url().includes('/api/v1/search/multi') && resp.status() === 200
|
||||
);
|
||||
|
||||
await this.page.locator('input[name="q"]').fill('Munich');
|
||||
await this.page.waitForResponse('**/api/v1/search/multi');
|
||||
await responsePromise;
|
||||
|
||||
await this.page.locator('.menu-item').first().click();
|
||||
await this.page.waitForURL('/map?lat=48.13743&lon=11.57549');
|
||||
await this.page.waitForURL(/\/map\?lat=.*&lon=.*/);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,13 @@ export class ListsPage {
|
||||
readonly listItems: Locator;
|
||||
readonly listItemsImage: Locator;
|
||||
|
||||
readonly listModal: Locator;
|
||||
readonly listModalAvatar: Locator;
|
||||
readonly listModalName: Locator;
|
||||
readonly listModalDescription: Locator;
|
||||
readonly listModalSaveButton: Locator;
|
||||
readonly listForm: Locator;
|
||||
readonly listFormAvatar: Locator;
|
||||
readonly listFormName: Locator;
|
||||
readonly listFormDescription: Locator;
|
||||
readonly listFormSaveButton: Locator;
|
||||
|
||||
readonly dropdownButton: Locator;
|
||||
|
||||
readonly confirmModal: Locator;
|
||||
readonly confirmModalConfirmButton: Locator;
|
||||
@@ -20,17 +21,19 @@ export class ListsPage {
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.createListButton = page.locator("#create-list");
|
||||
this.listModal = page.locator("#list-modal");
|
||||
this.createListButton = page.getByLabel('New list');
|
||||
this.listForm = page.locator("#list-form");
|
||||
|
||||
this.listModalAvatar = this.listModal.locator('input[name="avatar"]')
|
||||
this.listModalName = this.listModal.locator('input[name="name"]')
|
||||
this.listModalDescription = this.listModal.locator('textarea[name="description"]')
|
||||
this.listModalSaveButton = this.listModal.getByText('Save');
|
||||
this.listFormAvatar = page.locator('#avatar')
|
||||
this.listFormName = page.locator('input[name="name"]')
|
||||
this.listFormDescription = page.locator('.ProseMirror')
|
||||
this.listFormSaveButton = this.listForm.locator('button[type="submit"]');
|
||||
|
||||
this.listItems = page.locator('.list-list-item');
|
||||
this.listItemsImage = page.locator('.list-list-item img');
|
||||
// Only match the main avatar image (first img with aspect-square class in each list item)
|
||||
this.listItemsImage = page.locator('.list-list-item img.aspect-square');
|
||||
|
||||
this.dropdownButton = page.getByLabel('Open dropdown');
|
||||
|
||||
this.confirmModal = page.locator("#confirm-modal");
|
||||
this.confirmModalConfirmButton = this.confirmModal.locator("button").filter({ hasText: "Delete" });
|
||||
@@ -40,33 +43,49 @@ export class ListsPage {
|
||||
await this.page.goto('/lists', { waitUntil: 'networkidle' });
|
||||
}
|
||||
|
||||
private async selectDropdownAction(action: string) {
|
||||
await this.dropdownButton.click();
|
||||
await this.page.locator(".menu .menu-item").filter({ hasText: action }).click();
|
||||
}
|
||||
|
||||
async create(name: string = "Test List") {
|
||||
await this.createListButton.click();
|
||||
await this.listModalName.fill(name);
|
||||
await this.listModalAvatar.setInputFiles([
|
||||
await this.listFormName.fill(name);
|
||||
await this.listFormAvatar.setInputFiles([
|
||||
"./tests/playwright/fixtures/avatar.webp"
|
||||
]);
|
||||
|
||||
await Promise.all([
|
||||
this.page.waitForResponse(resp => resp.url().includes('/api/v1/list') && resp.status() === 200),
|
||||
this.listModalSaveButton.click()
|
||||
this.listFormSaveButton.click()
|
||||
]);
|
||||
|
||||
// Navigate back to lists page and wait for list items to load
|
||||
await this.page.goto('/lists', { waitUntil: 'domcontentloaded' });
|
||||
await this.listItems.first().waitFor({ state: 'visible', timeout: 10000 });
|
||||
}
|
||||
|
||||
async update(name: string = "Updated List", description = "New Description") {
|
||||
await this.listItems.first().locator(".dropdown button").click();
|
||||
await this.listItems.first().locator(".menu .menu-item").filter({ hasText: "Edit" }).click();
|
||||
await this.listModalName.fill(name);
|
||||
await this.listModalDescription.fill(description);
|
||||
await this.listItems.first().click();
|
||||
await this.selectDropdownAction("Edit");
|
||||
|
||||
await this.listFormName.clear();
|
||||
await this.listFormName.fill(name);
|
||||
await this.listFormDescription.fill(description);
|
||||
|
||||
await Promise.all([
|
||||
this.page.waitForResponse(resp => resp.url().includes('/api/v1/list') && resp.status() === 200),
|
||||
this.listModalSaveButton.click()
|
||||
this.listFormSaveButton.click()
|
||||
]);
|
||||
|
||||
// Navigate back to lists page
|
||||
await this.page.goto('/lists', { waitUntil: 'domcontentloaded' });
|
||||
}
|
||||
|
||||
async delete() {
|
||||
await this.listItems.first().locator(".dropdown button").click();
|
||||
await this.listItems.first().locator(".menu .menu-item").filter({ hasText: "Delete" }).click();
|
||||
await this.listItems.first().click();
|
||||
await this.selectDropdownAction("Delete");
|
||||
|
||||
await Promise.all([
|
||||
this.page.waitForResponse(resp => resp.url().includes('/api/v1/list') && resp.status() === 200),
|
||||
this.confirmModalConfirmButton.click()
|
||||
@@ -74,8 +93,14 @@ export class ListsPage {
|
||||
}
|
||||
|
||||
async removeAll() {
|
||||
while ((await this.listItems.count()) > 0) {
|
||||
await this.goto();
|
||||
|
||||
let count = await this.listItems.count();
|
||||
while (count > 0) {
|
||||
await this.delete();
|
||||
// Navigate back to lists page after deletion
|
||||
await this.goto();
|
||||
count = await this.listItems.count();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user