Skip to content

Commit

Permalink
test: dataset smoke test #4102
Browse files Browse the repository at this point in the history
  • Loading branch information
MillenniumFalconMechanic committed Jan 30, 2025
1 parent 9e57904 commit b86c207
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 300 deletions.
43 changes: 0 additions & 43 deletions e2e/anvil/anvil-backpages.spec.ts

This file was deleted.

161 changes: 161 additions & 0 deletions e2e/anvil/anvil-dataset.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import { expect, Locator, Page, test } from "@playwright/test";
import {
BUTTON_TEXT_ANALYZE_IN_TERRA,
BUTTON_TEXT_EXPORT,
BUTTON_TEXT_REQUEST_ACCESS,
BUTTON_TEXT_REQUEST_FILE_MANIFEST,
CHIP_TEXT_ACCESS_GRANTED,
CHIP_TEXT_ACCESS_REQUIRED,
DatasetAccess,
} from "./common/constants";
import {
MUI_ALERT_ROOT,
MUI_BUTTON_GROUP_ROOT,
MUI_TABLE_CELL_ROOT,
MUI_TABLE_ROOT,
MUI_TABLE_ROW_ROOT,
} from "../features/common/constants";
import { ROUTE_MANIFEST_DOWNLOAD } from "../../site-config/anvil-cmg/dev/export/constants";

const { describe } = test;

describe.parallel("Dataset", () => {
test.beforeEach(async ({ page }) => {
await goToDatasetsList(page);
});

test("displays request access button", async ({ page }) => {
await goToDataset(page, CHIP_TEXT_ACCESS_REQUIRED);

// Confirm export button is visible.
const exportButton = getLinkWithText(page, BUTTON_TEXT_REQUEST_ACCESS);
await expect(exportButton).toBeVisible();
});

test("displays export button", async ({ page }) => {
await goToDataset(page, CHIP_TEXT_ACCESS_GRANTED);

// Confirm export button is visible.
const exportButton = getLinkWithText(page, BUTTON_TEXT_EXPORT);
await expect(exportButton).toBeVisible();
});

test("displays export method", async ({ page }) => {
await goToDataset(page, CHIP_TEXT_ACCESS_GRANTED);

// Confirm export button is visible and click it.
await clickLink(page, BUTTON_TEXT_EXPORT);

// Confim Terra and file manifest export methods are listed.
await expect(
getLinkWithText(page, BUTTON_TEXT_ANALYZE_IN_TERRA)
).toBeVisible();
await expect(
getLinkWithText(page, BUTTON_TEXT_REQUEST_FILE_MANIFEST)
).toBeVisible();
});

test("displays download file manifest", async ({ page }) => {
await goToDataset(page, CHIP_TEXT_ACCESS_GRANTED);

// Confirm export button is visible and click it.
await clickLink(page, BUTTON_TEXT_EXPORT);

// Confirm file manifest export method is visible and click it.
await clickLink(page, BUTTON_TEXT_REQUEST_FILE_MANIFEST);

// Confirm the file manifest page is loaded: check there are two buttons
// (one for download, one for copy to clipboard).
const buttons = page.locator(`${MUI_BUTTON_GROUP_ROOT} button`);

// Ensure there are exactly two buttons.
await expect(buttons).toHaveCount(2);

// Ensure both buttons are visible.
await expect(buttons.nth(0)).toBeVisible();
await expect(buttons.nth(1)).toBeVisible();
});

test("displays login to download file manifest", async ({ page }) => {
await goToDataset(page, CHIP_TEXT_ACCESS_REQUIRED);

// Navigate to the export file manifest page.
const currentUrl = page.url();
await page.goto(`${currentUrl}${ROUTE_MANIFEST_DOWNLOAD}`);

// Confirm the login alert is displayed.
await expect(
page.locator(
`${MUI_ALERT_ROOT}:has-text("To download this dataset manifest, please sign in and, if necessary, request access.")`
)
).toBeVisible();
});

test("displays download analyze in Terra", async ({ page }) => {
await goToDataset(page, CHIP_TEXT_ACCESS_GRANTED);

// Confirm export button is visible and click it.
await clickLink(page, BUTTON_TEXT_EXPORT);

// Confirm Terra export method is visible and click it.
await clickLink(page, BUTTON_TEXT_ANALYZE_IN_TERRA);

// Confirm the analyze in Terra page is loaded: check the "coming soon"
// message is displayed.
await expect(
page.locator(`${MUI_ALERT_ROOT}:has-text("under development")`)
).toBeVisible();
});
});

/**
* Click the link wit the given text.
* @param page - Playwright page object.
* @param buttonText - The text of the button to click.
*/
async function clickLink(page: Page, buttonText: string): Promise<void> {
await getLinkWithText(page, buttonText).click();
}

/**
* Return the link with the given text.
* @param page - Playwright page object.
* @param buttonText - The text of the button to find.
* @returns - Playwright locator object for the dataset export button
*/
function getLinkWithText(page: Page, buttonText: string): Locator {
return page.locator(`a:has-text("${buttonText}")`);
}

/**
* Navigate to the datasets list.
* @param page - Playwright page object.
*/
async function goToDatasetsList(page: Page): Promise<void> {
if (page.url() !== "/") {
await page.goto("/");
}
}

/**
* Select a dataset with the given access from the datasets list and navigate to it.
* @param page - Playwright page object.
* @param access - The access of the dataset, either "Granted" or "Required"
*/
async function goToDataset(page: Page, access: DatasetAccess): Promise<void> {
// Find a dataset that user has access to.
const datasetRow = page
.locator(
`${MUI_TABLE_ROOT} ${MUI_TABLE_ROW_ROOT}:has(${MUI_TABLE_CELL_ROOT}:has-text("${access}"))`
)
.first();
await expect(datasetRow).toBeVisible(); // Confirm at least one dataset has been found.
const datasetLink = datasetRow.locator(
`${MUI_TABLE_CELL_ROOT}:first-child a`
);
const datasetTitle = await datasetLink.innerText();
await datasetLink.click();

// Wait for the dataset detail page to load (specifically the dataset title).
await page.waitForSelector(`h1:has-text("${datasetTitle}")`);
}
10 changes: 10 additions & 0 deletions e2e/anvil/common/constants.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const CHIP_TEXT_ACCESS_GRANTED = "Granted";
export const CHIP_TEXT_ACCESS_REQUIRED = "Required";
export const BUTTON_TEXT_ANALYZE_IN_TERRA = "Analyze in Terra";
export const BUTTON_TEXT_EXPORT = "Export";
export const BUTTON_TEXT_REQUEST_ACCESS = "Request Access";
export const BUTTON_TEXT_REQUEST_FILE_MANIFEST = "Request File Manifest";

export type DatasetAccess =
| typeof CHIP_TEXT_ACCESS_GRANTED
| typeof CHIP_TEXT_ACCESS_REQUIRED;
5 changes: 5 additions & 0 deletions e2e/features/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const MUI_ALERT_ROOT = ".MuiAlert-root";
export const MUI_BUTTON_GROUP_ROOT = ".MuiButtonGroup-root";
export const MUI_TABLE_CELL_ROOT = ".MuiTableCell-root";
export const MUI_TABLE_ROOT = ".MuiTable-root";
export const MUI_TABLE_ROW_ROOT = ".MuiTableRow-root";
Loading

0 comments on commit b86c207

Please sign in to comment.