Skip to content

Commit

Permalink
test: targeting
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVidra committed Jan 18, 2024
1 parent 9eadc2e commit 78dee9b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/types/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type UserProperties = Record<string, string | number | boolean | null | Date>;
export type UserProperties = Record<string, string | number | boolean | null | Date | undefined>;

export interface IdentifyUserOptions {
/**
Expand Down
12 changes: 12 additions & 0 deletions tests/targeting/targeting.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="/tests/reset.css" />
<link rel="stylesheet" href="/public/flows.css" />
</head>
<body>
<script type="module" src="./targeting.ts"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions tests/targeting/targeting.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect, test } from "@playwright/test";

test("Shouldn't show up when used doesn't match", async ({ page }) => {
await page.goto("/targeting/targeting.html");
await expect(page.locator(".flows-modal")).not.toBeVisible();
});

test("Should show up when used matches", async ({ page }) => {
await page.goto("/targeting/targeting.html?john=true");
await expect(page.locator(".flows-modal")).toBeVisible();
});
17 changes: 17 additions & 0 deletions tests/targeting/targeting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { init } from "../../dist";

const john = new URLSearchParams(window.location.search).get("john") === "true";

void init({
flows: [
{
id: "flow",
location: "/",
userProperties: [{ key: "name", eq: "John Doe" }],
steps: [{ title: "Hello" }],
},
],
userProperties: {
name: john ? "John Doe" : undefined,
},
});

0 comments on commit 78dee9b

Please sign in to comment.