From 5f139f2607de03b2f8db0fcc1a8bb96e9ce4f633 Mon Sep 17 00:00:00 2001 From: Andrew Kirkegaard Date: Sat, 24 Feb 2024 16:36:58 -0500 Subject: [PATCH] Fix pattern matching for path strings --- test/e2e/index.ts | 4 ++-- test/e2e/periods.spec.ts | 30 +++++++++++++++--------------- test/e2e/primals.spec.ts | 12 ++++++------ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/test/e2e/index.ts b/test/e2e/index.ts index 166af07b..d9a85de6 100644 --- a/test/e2e/index.ts +++ b/test/e2e/index.ts @@ -1,4 +1,4 @@ -const path = (length: number): string => - `[MLZ,d]{${length}}`; +const path = (length: number): RegExp => + new RegExp(`[MLZ,0-9]{${length}}`); export { path }; diff --git a/test/e2e/periods.spec.ts b/test/e2e/periods.spec.ts index 40fa486a..2fe11afc 100644 --- a/test/e2e/periods.spec.ts +++ b/test/e2e/periods.spec.ts @@ -11,11 +11,11 @@ test("View data from different time periods", async ({ page }) => { await expect(page.getByText("3M")).toHaveAttribute("data-selected", "false"); await expect(page.getByText("1Y")).toHaveAttribute("data-selected", "false"); - await expect(page.locator("div[class*=cash] path.series")).toHaveAttribute("d", expect.stringMatching(path(964))); - await expect(page.locator("div[class*=cutout] path.series").first()).toHaveAttribute("d", expect.stringMatching(path(977))); - await expect(page.locator("div[class*=cutout] path.series").last()).toHaveAttribute("d", expect.stringMatching(path(979))); - await expect(page.locator("div[class*=purchases] path.series")).toHaveAttribute("d", expect.stringMatching(path(961))); - await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", expect.stringMatching(path(978))); + await expect(page.locator("div[class*=cash] path.series")).toHaveAttribute("d", path(964)); + await expect(page.locator("div[class*=cutout] path.series").first()).toHaveAttribute("d", path(977)); + await expect(page.locator("div[class*=cutout] path.series").last()).toHaveAttribute("d", path(979)); + await expect(page.locator("div[class*=purchases] path.series")).toHaveAttribute("d", path(961)); + await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", path(978)); }); await test.step("View one year of data", async () => { @@ -25,11 +25,11 @@ test("View data from different time periods", async ({ page }) => { await expect(page.getByText("3M")).toHaveAttribute("data-selected", "false"); await expect(page.getByText("6M")).toHaveAttribute("data-selected", "false"); - await expect(page.locator("div[class*=cash] path.series")).toHaveAttribute("d", expect.stringMatching(path(1909))); - await expect(page.locator("div[class*=cutout] path.series").first()).toHaveAttribute("d", expect.stringMatching(path(1935))); - await expect(page.locator("div[class*=cutout] path.series").last()).toHaveAttribute("d", expect.stringMatching(path(1939))); - await expect(page.locator("div[class*=purchases] path.series")).toHaveAttribute("d", expect.stringMatching(path(1915))); - await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", expect.stringMatching(path(1941))); + await expect(page.locator("div[class*=cash] path.series")).toHaveAttribute("d", path(1909)); + await expect(page.locator("div[class*=cutout] path.series").first()).toHaveAttribute("d", path(1935)); + await expect(page.locator("div[class*=cutout] path.series").last()).toHaveAttribute("d", path(1939)); + await expect(page.locator("div[class*=purchases] path.series")).toHaveAttribute("d", path(1915)); + await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", path(1941)); }); await test.step("View three months of data", async () => { @@ -39,10 +39,10 @@ test("View data from different time periods", async ({ page }) => { await expect(page.getByText("6M")).toHaveAttribute("data-selected", "false"); await expect(page.getByText("1Y")).toHaveAttribute("data-selected", "false"); - await expect(page.locator("div[class*=cash] path.series")).toHaveAttribute("d", expect.stringMatching(path(490))); - await expect(page.locator("div[class*=cutout] path.series").first()).toHaveAttribute("d", expect.stringMatching(path(502))); - await expect(page.locator("div[class*=cutout] path.series").last()).toHaveAttribute("d", expect.stringMatching(path(502))); - await expect(page.locator("div[class*=purchases] path.series")).toHaveAttribute("d", expect.stringMatching(path(490))); - await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", expect.stringMatching(path(495))); + await expect(page.locator("div[class*=cash] path.series")).toHaveAttribute("d", path(490)); + await expect(page.locator("div[class*=cutout] path.series").first()).toHaveAttribute("d", path(502)); + await expect(page.locator("div[class*=cutout] path.series").last()).toHaveAttribute("d", path(502)); + await expect(page.locator("div[class*=purchases] path.series")).toHaveAttribute("d", path(490)); + await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", path(495)); }); }); diff --git a/test/e2e/primals.spec.ts b/test/e2e/primals.spec.ts index 1763aeb1..c39e8c28 100644 --- a/test/e2e/primals.spec.ts +++ b/test/e2e/primals.spec.ts @@ -6,31 +6,31 @@ test("View pricing data of each primal", async ({ page }) => { await test.step("View pricing data for hams", async () => { await page.getByText("Ham").click(); - await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", expect.stringMatching(path(540))); + await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", path(504)); }); await test.step("View pricing data for pork loins", async () => { await page.getByText("Loin").click(); - await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", expect.stringMatching(path(495))); + await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", path(495)); }); await test.step("View pricing data for pork butts", async () => { await page.getByText("Butt").click(); - await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", expect.stringMatching(path(501))); + await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", path(501)); }); await test.step("View pricing data for ribs", async () => { await page.getByText("Rib").click(); - await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", expect.stringMatching(path(509))); + await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", path(509)); }); await test.step("View pricing data for picnic cuts", async () => { await page.getByText("Picnic").click(); - await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", expect.stringMatching(path(496))); + await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", path(496)); }); await test.step("View pricing data for pork bellies", async () => { await page.getByText("Belly").click(); - await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", expect.stringMatching(path(495))); + await expect(page.locator("div[class*=primal] path.series")).toHaveAttribute("d", path(495)); }); });