Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 48 additions & 6 deletions playwright/pages/item-metadata.page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Locator, Page, expect } from "@playwright/test";

// sets which UUID is to be used for sample record navigation
export type MetadataScenario = "DEFAULT" | "SAMPLE1" | "SAMPLE2";

class FieldLocatorService {
// Method returns an object containing both the Locator and the content/text Pattern
public getNameLocatorAndPattern(
Expand Down Expand Up @@ -46,7 +49,17 @@ export default class ItemMetadataPage {
readonly page: Page;
private locatorService = new FieldLocatorService();

static itemResultURL: string = "/items/8b2b3160-c5d5-012f-d95c-58d385a7bc34";
// Sample URL-Record Mapping
private static readonly SCENARIOS: Record<MetadataScenario, string> = {
DEFAULT: "8b2b3160-c5d5-012f-d95c-58d385a7bc34",
SAMPLE1: "25a47180-c55f-012f-3759-58d385a7bc34", // Topics
SAMPLE2: "4649be20-9890-0138-2359-2360945aaf51", // Genres
};

async loadScenario(scenario: MetadataScenario): Promise<void> {
const uuid = ItemMetadataPage.SCENARIOS[scenario];
await this.page.goto(`/items/${uuid}`);
}

// item-metadata
readonly itemDataHeader: Locator;
Expand Down Expand Up @@ -80,6 +93,8 @@ export default class ItemMetadataPage {
readonly descriptionText: Locator;
readonly typeHeading: Locator;
readonly typeText: Locator;
readonly languageHeading: Locator;
readonly languageText: Locator;
readonly identifiersHeading: Locator;
readonly identifiersText: Locator;
readonly rightsHeading: Locator;
Expand All @@ -101,6 +116,7 @@ export default class ItemMetadataPage {
{ name: "Ratzer, Bernard", role: "Cartographer" },
{ name: "Kitchin, Thomas, 1718-1784", role: "Engraver" },
];
static readonly EXPECTED_LANGUAGE_VALUE = "English";
static readonly EXPECTED_TOPIC_LINK_MAP = [
{
fullText: "New York (N.Y.)",
Expand Down Expand Up @@ -195,11 +211,9 @@ export default class ItemMetadataPage {
this.typeHeading = this.page.getByText("Type of Resource", { exact: true });
this.typeText = this.typeHeading.locator("+ p");

// Identifiers
this.identifiersHeading = this.page.getByText("Identifiers", {
exact: true,
});
this.identifiersText = this.identifiersHeading.locator("+ p");
// Languages
this.languageHeading = this.page.getByText("Languages", { exact: true });
this.languageText = this.languageHeading.locator("+ p");

// Rights Statement
this.rightsHeading = this.page.getByText("Rights Statement", {
Expand Down Expand Up @@ -331,6 +345,34 @@ export default class ItemMetadataPage {
}
}

async verifyLanguageValues(): Promise<void> {
await expect(this.languageHeading).toBeVisible();

const languageLink = this.languageText.getByRole("link");
await expect(languageLink).toBeVisible();
await expect(languageLink).toHaveText(
ItemMetadataPage.EXPECTED_LANGUAGE_VALUE
);
}

async verifyLanguageText(): Promise<void> {
await expect(this.languageHeading).toBeVisible();
await expect(this.languageText).toContainText(
ItemMetadataPage.EXPECTED_LANGUAGE_VALUE
);
}

async verifyLanguageLinks(): Promise<void> {
const languageLink = this.languageText.getByRole("link");

// If it's visible and has the right text, Playwright has already
// confirmed it's a functional link role.
await expect(languageLink).toBeVisible();
await expect(languageLink).toHaveText(
ItemMetadataPage.EXPECTED_LANGUAGE_VALUE
);
}

public async getTopicLocatorAndDelimiter(): Promise<string[]> {
const parentContainer = this.topicText; // The <p> element
const allLinks = parentContainer.locator("a");
Expand Down
43 changes: 28 additions & 15 deletions playwright/tests/item-metadata.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import ItemMetadataPage from "../pages/item-metadata.page";

let itemMetadataPage: ItemMetadataPage;

test.describe("Verify Metadata Fields", () => {
test.beforeEach(async ({ page }) => {
itemMetadataPage = new ItemMetadataPage(page);
});

test.describe("Verify Default Test Record", () => {
test.beforeEach(async ({ page }) => {
itemMetadataPage = new ItemMetadataPage(page);
await itemMetadataPage.loadPage(ItemMetadataPage.itemResultURL);
await itemMetadataPage.loadScenario("DEFAULT");
});

test("should display Title heading and corresponding text", async () => {
Expand Down Expand Up @@ -76,19 +79,13 @@ test.describe("Verify Metadata Fields", () => {
});
});

test.describe("Subjects", () => {
test.describe("Verify Links", () => {
test.beforeEach(async ({ page }) => {
// Load the SPECIFIC Topics-modified URL before each test in this block
itemMetadataPage = new ItemMetadataPage(page);

await itemMetadataPage.loadPage(
ItemMetadataPage.itemResultURL.replace(
ItemMetadataPage.EXPECTED_UUID_VALUE,
ItemMetadataPage.EXPECTED_TOPIC_UUID_VALUE
)
);
test.describe("Verify Sample Record 1", () => {
test.beforeEach(async ({ page }) => {
await itemMetadataPage.loadScenario("SAMPLE1");
});

test.describe("Subjects", () => {
test.beforeEach(async ({ page }) => {
await expect(itemMetadataPage.topicHeading).toBeVisible();
await expect(itemMetadataPage.topicText).toBeVisible();
});
Expand All @@ -106,3 +103,19 @@ test.describe("Subjects", () => {
});
});
});

test.describe("Verify Sample Record 2", () => {
test.beforeEach(async ({ page }) => {
await itemMetadataPage.loadScenario("SAMPLE2");
});

test.describe("Languages", () => {
test("should include correct language values", async () => {
await itemMetadataPage.verifyLanguageText();
});

test("should contain links that are clickable", async () => {
await itemMetadataPage.verifyLanguageLinks();
});
});
});