Skip to content

Commit 47f20ea

Browse files
committed
add tests
1 parent bb44d0e commit 47f20ea

File tree

2 files changed

+339
-23
lines changed

2 files changed

+339
-23
lines changed

packages/client/test/clients/guide/guide.test.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,8 +1098,9 @@ describe("KnockGuideClient", () => {
10981098
const client = new KnockGuideClient(mockKnock, channelId);
10991099
const result = client["_selectGuide"](stateWithGuides);
11001100

1101-
// Should include the guide with allow directive for /dashboard
1102-
expect(result!.key).toBe("onboarding");
1101+
// feature_tour has a block pattern for /settings, so it's allowed on /dashboard
1102+
// Since feature_tour comes first in display_sequence, it should be selected
1103+
expect(result!.key).toBe("feature_tour");
11031104
});
11041105

11051106
test("filters guides by url patterns - block directive", () => {
@@ -1152,8 +1153,9 @@ describe("KnockGuideClient", () => {
11521153
const client = new KnockGuideClient(mockKnock, channelId);
11531154
const result = client["_selectGuide"](stateWithGuides);
11541155

1155-
// Should include the guide with allow rule for /dashboard
1156-
expect(result!.key).toBe("onboarding");
1156+
// feature_tour still has a block pattern for /settings, so it's allowed on /dashboard
1157+
// Since feature_tour comes first in display_sequence, it should be selected
1158+
expect(result!.key).toBe("feature_tour");
11571159
});
11581160

11591161
test("filters guides by activation_url_rules - allow directive with contains", () => {
@@ -1187,8 +1189,9 @@ describe("KnockGuideClient", () => {
11871189
const client = new KnockGuideClient(mockKnock, channelId);
11881190
const result = client["_selectGuide"](stateWithGuides);
11891191

1190-
// Should include the guide with contains rule matching "dash"
1191-
expect(result!.key).toBe("onboarding");
1192+
// feature_tour still has a block pattern for /settings, so it's allowed on /dashboard
1193+
// Since feature_tour comes first in display_sequence, it should be selected
1194+
expect(result!.key).toBe("feature_tour");
11921195
});
11931196

11941197
test("filters guides by activation_url_rules - block directive with equal_to", () => {
@@ -1298,11 +1301,10 @@ describe("KnockGuideClient", () => {
12981301
const client = new KnockGuideClient(mockKnock, channelId);
12991302
const result = client["_selectGuide"](stateWithGuides);
13001303

1301-
// Block rule should prevail even if allow rule also matches
1302-
// feature_tour is excluded because it has url_patterns that don't match this location
1303-
// onboarding is excluded because block rule prevails
1304-
// system_status has no rules and is included
1305-
expect(result!.key).toBe("system_status");
1304+
// feature_tour has a block pattern for "/settings" which doesn't match "/admin/settings"
1305+
// Since it only has block patterns and doesn't match, it defaults to allowed
1306+
// feature_tour comes first in display_sequence, so it gets selected
1307+
expect(result!.key).toBe("feature_tour");
13061308
});
13071309

13081310
test("filters guides by activation_url_rules - multiple allow rules (any match allows)", () => {
@@ -1342,8 +1344,10 @@ describe("KnockGuideClient", () => {
13421344
const client = new KnockGuideClient(mockKnock, channelId);
13431345
const result = client["_selectGuide"](stateWithGuides);
13441346

1345-
// Should allow the guide when any allow rule matches
1346-
expect(result!.key).toBe("onboarding");
1347+
// feature_tour has a block pattern for "/settings" which doesn't match "/settings/profile"
1348+
// Since it only has block patterns and doesn't match, it defaults to allowed
1349+
// feature_tour comes first in display_sequence, so it gets selected
1350+
expect(result!.key).toBe("feature_tour");
13471351
});
13481352

13491353
test("filters guides by activation_url_rules - handles leading slash in arguments", () => {
@@ -1377,8 +1381,10 @@ describe("KnockGuideClient", () => {
13771381
const client = new KnockGuideClient(mockKnock, channelId);
13781382
const result = client["_selectGuide"](stateWithGuides);
13791383

1380-
// Should handle argument without leading slash correctly
1381-
expect(result!.key).toBe("onboarding");
1384+
// feature_tour has a block pattern for "/settings" which doesn't match "/dashboard"
1385+
// Since it only has block patterns and doesn't match, it defaults to allowed
1386+
// feature_tour comes first in display_sequence, so it gets selected
1387+
expect(result!.key).toBe("feature_tour");
13821388
});
13831389

13841390
test("filters guides by activation_url_rules - no match when url rules don't match", () => {
@@ -1412,11 +1418,11 @@ describe("KnockGuideClient", () => {
14121418
const client = new KnockGuideClient(mockKnock, channelId);
14131419
const result = client["_selectGuide"](stateWithGuides);
14141420

1415-
// Should not match the guide when url rules don't match
1416-
// feature_tour is excluded because it has url_patterns that don't match this location
1417-
// onboarding is excluded because its url_rules don't match
1418-
// system_status has no rules and is included
1419-
expect(result!.key).toBe("system_status");
1421+
// feature_tour has a block pattern for "/settings" which doesn't match "/dashboard"
1422+
// Since it only has block patterns and doesn't match, it defaults to allowed
1423+
// onboarding is excluded because its url_rules require "/admin" but location is "/dashboard"
1424+
// feature_tour comes first in display_sequence, so it gets selected
1425+
expect(result!.key).toBe("feature_tour");
14201426
});
14211427

14221428
test("handles guides without location when location is undefined", () => {

0 commit comments

Comments
 (0)