|
| 1 | +import { expect, Locator, Page, test } from "@playwright/test"; |
| 2 | +import { |
| 3 | + BUTTON_TEXT_ANALYZE_IN_TERRA, |
| 4 | + BUTTON_TEXT_EXPORT, |
| 5 | + BUTTON_TEXT_REQUEST_ACCESS, |
| 6 | + BUTTON_TEXT_REQUEST_FILE_MANIFEST, |
| 7 | + CHIP_TEXT_ACCESS_GRANTED, |
| 8 | + CHIP_TEXT_ACCESS_REQUIRED, |
| 9 | + DatasetAccess, |
| 10 | +} from "./common/constants"; |
| 11 | +import { |
| 12 | + MUI_ALERT_ROOT, |
| 13 | + MUI_BUTTON_GROUP_ROOT, |
| 14 | + MUI_TABLE_CELL_ROOT, |
| 15 | + MUI_TABLE_ROOT, |
| 16 | + MUI_TABLE_ROW_ROOT, |
| 17 | +} from "../features/common/constants"; |
| 18 | +import { ROUTE_MANIFEST_DOWNLOAD } from "../../site-config/anvil-cmg/dev/export/constants"; |
| 19 | + |
| 20 | +const { describe } = test; |
| 21 | + |
| 22 | +describe.parallel("Dataset", () => { |
| 23 | + test.beforeEach(async ({ page }) => { |
| 24 | + await goToDatasetsList(page); |
| 25 | + }); |
| 26 | + |
| 27 | + test("displays request access button", async ({ page }) => { |
| 28 | + await goToDataset(page, CHIP_TEXT_ACCESS_REQUIRED); |
| 29 | + |
| 30 | + // Confirm export button is visible. |
| 31 | + const exportButton = getLinkWithText(page, BUTTON_TEXT_REQUEST_ACCESS); |
| 32 | + await expect(exportButton).toBeVisible(); |
| 33 | + }); |
| 34 | + |
| 35 | + test("displays export button", async ({ page }) => { |
| 36 | + await goToDataset(page, CHIP_TEXT_ACCESS_GRANTED); |
| 37 | + |
| 38 | + // Confirm export button is visible. |
| 39 | + const exportButton = getLinkWithText(page, BUTTON_TEXT_EXPORT); |
| 40 | + await expect(exportButton).toBeVisible(); |
| 41 | + }); |
| 42 | + |
| 43 | + test("displays export method", async ({ page }) => { |
| 44 | + await goToDataset(page, CHIP_TEXT_ACCESS_GRANTED); |
| 45 | + |
| 46 | + // Confirm export button is visible and click it. |
| 47 | + await clickLink(page, BUTTON_TEXT_EXPORT); |
| 48 | + |
| 49 | + // Confim Terra and file manifest export methods are listed. |
| 50 | + await expect( |
| 51 | + getLinkWithText(page, BUTTON_TEXT_ANALYZE_IN_TERRA) |
| 52 | + ).toBeVisible(); |
| 53 | + await expect( |
| 54 | + getLinkWithText(page, BUTTON_TEXT_REQUEST_FILE_MANIFEST) |
| 55 | + ).toBeVisible(); |
| 56 | + }); |
| 57 | + |
| 58 | + test("displays download file manifest", async ({ page }) => { |
| 59 | + await goToDataset(page, CHIP_TEXT_ACCESS_GRANTED); |
| 60 | + |
| 61 | + // Confirm export button is visible and click it. |
| 62 | + await clickLink(page, BUTTON_TEXT_EXPORT); |
| 63 | + |
| 64 | + // Confirm file manifest export method is visible and click it. |
| 65 | + await clickLink(page, BUTTON_TEXT_REQUEST_FILE_MANIFEST); |
| 66 | + |
| 67 | + // Confirm the file manifest page is loaded: check there are two buttons |
| 68 | + // (one for download, one for copy to clipboard). |
| 69 | + const buttons = page.locator(`${MUI_BUTTON_GROUP_ROOT} button`); |
| 70 | + |
| 71 | + // Ensure there are exactly two buttons. |
| 72 | + await expect(buttons).toHaveCount(2); |
| 73 | + |
| 74 | + // Ensure both buttons are visible. |
| 75 | + await expect(buttons.nth(0)).toBeVisible(); |
| 76 | + await expect(buttons.nth(1)).toBeVisible(); |
| 77 | + }); |
| 78 | + |
| 79 | + test("displays login to download file manifest", async ({ page }) => { |
| 80 | + await goToDataset(page, CHIP_TEXT_ACCESS_REQUIRED); |
| 81 | + |
| 82 | + // Navigate to the export file manifest page. |
| 83 | + const currentUrl = page.url(); |
| 84 | + await page.goto(`${currentUrl}${ROUTE_MANIFEST_DOWNLOAD}`); |
| 85 | + |
| 86 | + // Confirm the login alert is displayed. |
| 87 | + await expect( |
| 88 | + page.locator( |
| 89 | + `${MUI_ALERT_ROOT}:has-text("To download this dataset manifest, please sign in and, if necessary, request access.")` |
| 90 | + ) |
| 91 | + ).toBeVisible(); |
| 92 | + }); |
| 93 | + |
| 94 | + test("displays download analyze in Terra", async ({ page }) => { |
| 95 | + await goToDataset(page, CHIP_TEXT_ACCESS_GRANTED); |
| 96 | + |
| 97 | + // Confirm export button is visible and click it. |
| 98 | + await clickLink(page, BUTTON_TEXT_EXPORT); |
| 99 | + |
| 100 | + // Confirm Terra export method is visible and click it. |
| 101 | + await clickLink(page, BUTTON_TEXT_ANALYZE_IN_TERRA); |
| 102 | + |
| 103 | + // Confirm the analyze in Terra page is loaded: check the "coming soon" |
| 104 | + // message is displayed. |
| 105 | + await expect( |
| 106 | + page.locator(`${MUI_ALERT_ROOT}:has-text("under development")`) |
| 107 | + ).toBeVisible(); |
| 108 | + }); |
| 109 | +}); |
| 110 | + |
| 111 | +/** |
| 112 | + * Click the link wit the given text. |
| 113 | + * @param page - Playwright page object. |
| 114 | + * @param buttonText - The text of the button to click. |
| 115 | + */ |
| 116 | +async function clickLink(page: Page, buttonText: string): Promise<void> { |
| 117 | + await getLinkWithText(page, buttonText).click(); |
| 118 | +} |
| 119 | + |
| 120 | +/** |
| 121 | + * Return the link with the given text. |
| 122 | + * @param page - Playwright page object. |
| 123 | + * @param buttonText - The text of the button to find. |
| 124 | + * @returns - Playwright locator object for the dataset export button |
| 125 | + */ |
| 126 | +function getLinkWithText(page: Page, buttonText: string): Locator { |
| 127 | + return page.locator(`a:has-text("${buttonText}")`); |
| 128 | +} |
| 129 | + |
| 130 | +/** |
| 131 | + * Navigate to the datasets list. |
| 132 | + * @param page - Playwright page object. |
| 133 | + */ |
| 134 | +async function goToDatasetsList(page: Page): Promise<void> { |
| 135 | + if (page.url() !== "/") { |
| 136 | + await page.goto("/"); |
| 137 | + } |
| 138 | +} |
| 139 | + |
| 140 | +/** |
| 141 | + * Select a dataset with the given access from the datasets list and navigate to it. |
| 142 | + * @param page - Playwright page object. |
| 143 | + * @param access - The access of the dataset, either "Granted" or "Required" |
| 144 | + */ |
| 145 | +async function goToDataset(page: Page, access: DatasetAccess): Promise<void> { |
| 146 | + // Find a dataset that user has access to. |
| 147 | + const datasetRow = page |
| 148 | + .locator( |
| 149 | + `${MUI_TABLE_ROOT} ${MUI_TABLE_ROW_ROOT}:has(${MUI_TABLE_CELL_ROOT}:has-text("${access}"))` |
| 150 | + ) |
| 151 | + .first(); |
| 152 | + await expect(datasetRow).toBeVisible(); // Confirm at least one dataset has been found. |
| 153 | + const datasetLink = datasetRow.locator( |
| 154 | + `${MUI_TABLE_CELL_ROOT}:first-child a` |
| 155 | + ); |
| 156 | + const datasetTitle = await datasetLink.innerText(); |
| 157 | + await datasetLink.click(); |
| 158 | + |
| 159 | + // Wait for the dataset detail page to load (specifically the dataset title). |
| 160 | + await page.waitForSelector(`h1:has-text("${datasetTitle}")`); |
| 161 | +} |
0 commit comments