Skip to content

Commit

Permalink
Fix pattern matching for path strings
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkedev committed Feb 24, 2024
1 parent 4069468 commit 5f139f2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions test/e2e/index.ts
Original file line number Diff line number Diff line change
@@ -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 };
30 changes: 15 additions & 15 deletions test/e2e/periods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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));
});
});
12 changes: 6 additions & 6 deletions test/e2e/primals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});

0 comments on commit 5f139f2

Please sign in to comment.