|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import { handleConsentPopup, waitFor } from "./util"; |
| 3 | + |
| 4 | +test.describe("Testing for tabs shortcode", () => { |
| 5 | + test.beforeEach(async ({ page }) => { |
| 6 | + const tabsUrl = "test-product/tab-group/tab-group/"; |
| 7 | + await page.goto(`/${tabsUrl}`); |
| 8 | + await waitFor(async () => await handleConsentPopup(page)); |
| 9 | + }); |
| 10 | + |
| 11 | + test("tabs render", async ({ page }) => { |
| 12 | + const section = await page.getByTestId("tabs-test__basic"); |
| 13 | + const tabsContainer = await section.getByTestId("tabs-container"); |
| 14 | + const tabLabels = await tabsContainer.getByTestId("tab-labels"); |
| 15 | + const tabContents = await tabsContainer.getByTestId("tab-contents"); |
| 16 | + |
| 17 | + expect(await tabsContainer.count()).toBeTruthy(); |
| 18 | + expect(await tabLabels.count()).toBeTruthy(); |
| 19 | + expect(await tabContents.count()).toBeTruthy(); |
| 20 | + }); |
| 21 | + |
| 22 | + test("tabs shift content when clicked", async ({ page }) => { |
| 23 | + const section = await page.getByTestId("tabs-test__basic"); |
| 24 | + const tabsContainer = await section.getByTestId("tabs-container"); |
| 25 | + const tabLabels = await tabsContainer.getByTestId("tab-labels"); |
| 26 | + const tabContents = await tabsContainer.getByTestId("tab-contents"); |
| 27 | + |
| 28 | + const tabsList = await tabLabels.locator("li").all(); |
| 29 | + for (const tab of tabsList) { |
| 30 | + const label = tab.getByTestId("tab-label"); |
| 31 | + const labelId = await label.getAttribute("id"); |
| 32 | + const title = labelId.substring(0, labelId.lastIndexOf("tab") - 1); |
| 33 | + const labelIndex = parseInt( |
| 34 | + labelId.substring(labelId.lastIndexOf("-") + 1), |
| 35 | + ); |
| 36 | + |
| 37 | + await label.click(); |
| 38 | + const content = tabContents.locator(`#${title}-panel-${labelIndex}`); |
| 39 | + await expect(content).toBeVisible(); |
| 40 | + } |
| 41 | + }); |
| 42 | +}); |
0 commit comments