Skip to content

Commit

Permalink
Add playwright group edit test
Browse files Browse the repository at this point in the history
  • Loading branch information
fhennig authored and corneliusroemer committed Oct 16, 2024
1 parent 8f752dc commit 0b342ab
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 12 deletions.
62 changes: 52 additions & 10 deletions website/tests/pages/user/group/group.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,75 @@ export class GroupPage {
await this.page.waitForURL(`${baseUrl}${routes.groupOverviewPage(groupId)}`);
}

public async createGroup(uniqueGroupName: string) {
public async goToGroupEditPage() {
const editButton = this.page.getByRole('link', { name: 'Edit group' });
await editButton.waitFor({ state: 'visible' });
await editButton.click();
await this.page.waitForURL(/\/group\/\d+\/edit/);
}

public async editGroupName(groupName: string) {
const newGroupField = this.page.getByLabel('Group name');
await newGroupField.fill(uniqueGroupName);
await newGroupField.fill(groupName);
}

public async editInstitution(institution: string) {
const newInstitutionField = this.page.getByLabel('Institution');
await newInstitutionField.fill(DEFAULT_GROUP.institution);
await newInstitutionField.fill(institution);
}

public async editContactEmail(contactEmail: string) {
const newContactEmailField = this.page.getByLabel('Email address', { exact: false });
await newContactEmailField.fill(DEFAULT_GROUP.contactEmail);
await newContactEmailField.fill(contactEmail);
}

public async editCountry(index: number) {
const newCountryField = this.page.getByLabel('Country');
await newCountryField.selectOption({ index: 1 });
await newCountryField.selectOption({ index });
}

public async editAddressLine1(line1: string) {
const newLine1Field = this.page.getByLabel('Address Line 1');
await newLine1Field.fill(DEFAULT_GROUP.address.line1);
await newLine1Field.fill(line1);
}

public async editAddressLine2(line2: string) {
const newLine2Field = this.page.getByLabel('Address Line 2');
await newLine2Field.fill(DEFAULT_GROUP.address.line2 ?? '');
await newLine2Field.fill(line2);
}

public async editCity(city: string) {
const newCityField = this.page.getByLabel('City');
await newCityField.fill(DEFAULT_GROUP.address.city);
await newCityField.fill(city);
}

public async editState(state: string) {
const newStateField = this.page.getByLabel('State', { exact: false });
await newStateField.fill(DEFAULT_GROUP.address.state ?? '');
await newStateField.fill(state);
}

public async editPostalCode(postalCode: string) {
const newPostalCodeField = this.page.getByLabel('Postal code', { exact: false });
await newPostalCodeField.fill(DEFAULT_GROUP.address.postalCode);
await newPostalCodeField.fill(postalCode);
}

public async finishEditingGroup() {
const updateGroupButton = this.page.getByRole('button', { name: 'Update group' });
await updateGroupButton.click();

await this.page.waitForURL(/\/group\/\d+/);
}

public async createGroup(uniqueGroupName: string) {
await this.editGroupName(uniqueGroupName);
await this.editInstitution(DEFAULT_GROUP.institution);
await this.editContactEmail(DEFAULT_GROUP.contactEmail);
await this.editCountry(1);
await this.editAddressLine1(DEFAULT_GROUP.address.line1);
await this.editAddressLine2(DEFAULT_GROUP.address.line2 ?? '');
await this.editCity(DEFAULT_GROUP.address.city);
await this.editState(DEFAULT_GROUP.address.state ?? '');
await this.editPostalCode(DEFAULT_GROUP.address.postalCode);

const createGroupButton = this.page.getByRole('button', { name: 'Create group' });
await createGroupButton.click();
Expand Down
46 changes: 44 additions & 2 deletions website/tests/pages/user/group/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { v4 } from 'uuid';

import { test, testUser } from '../../../e2e.fixture';
import { expect, test, testUser } from '../../../e2e.fixture';

test.describe('The group page', () => {
test('should see all users of the group, add a user and remove it afterwards', async ({
Expand All @@ -24,7 +24,49 @@ test.describe('The group page', () => {
await groupPage.removeUserFromGroup(testUser);

await groupPage.verifyUserIsNotPresent(testUser);
});

test('should edit group info and see changes afterwards', async ({ groupPage, loginAsTestUser }) => {
await loginAsTestUser();

await groupPage.goToUserPage();
await groupPage.goToGroupCreationPage();

const groupName = v4();
await groupPage.createGroup(groupName);
const newName = v4();
const newInstitution = v4();
const newEmail = `${v4()}@example.com`;
const newCountry = 2;
const newLine1 = v4();
const newLine2 = v4();
const newCity = v4();
const newState = v4();
const newPostalCode = v4();

await groupPage.goToGroupEditPage();
await groupPage.editGroupName(newName);
await groupPage.editInstitution(newInstitution);
await groupPage.editContactEmail(newEmail);
await groupPage.editCountry(newCountry);
await groupPage.editAddressLine1(newLine1);
await groupPage.editAddressLine2(newLine2);
await groupPage.editCity(newCity);
await groupPage.editState(newState);
await groupPage.editPostalCode(newPostalCode);
await groupPage.finishEditingGroup();

await expect(groupPage.page.getByRole('heading', { name: newName })).toBeVisible();

const tableLocator = groupPage.page.locator('table');

// TODO: Edit a group and verify the changes are shown
await expect(tableLocator).toContainText(newInstitution);
await expect(tableLocator).toContainText(newEmail);
await expect(tableLocator).toContainText(newLine1);
await expect(tableLocator).toContainText(newLine2);
await expect(tableLocator).toContainText(newCity);
await expect(tableLocator).toContainText(newState);
await expect(tableLocator).toContainText(newPostalCode);
await expect(tableLocator).toContainText('Albania');
});
});

0 comments on commit 0b342ab

Please sign in to comment.