@simplybusiness/services 0.26.3 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/cjs/index.js +19 -18
- package/dist/esm/index.js +19 -18
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/address-lookup/index.d.ts +1 -1
- package/dist/types/mocks/eventDefinitions.d.ts +1 -1
- package/dist/types/snowplow/Snowplow.d.ts +5 -5
- package/dist/types/snowplow/SnowplowContext.d.ts +1 -1
- package/dist/types/snowplow/contexts.d.ts +1 -1
- package/dist/types/snowplow/event-definitions/base.d.ts +1 -1
- package/dist/types/snowplow/event-definitions/intervention.d.ts +1 -1
- package/dist/types/snowplow/event-definitions/personalised_cover.d.ts +1 -1
- package/dist/types/snowplow/event-definitions/qcp.d.ts +1 -1
- package/dist/types/snowplow/event-definitions/questionnaire.d.ts +1 -1
- package/dist/types/snowplow/event-definitions/redaction.d.ts +1 -1
- package/dist/types/snowplow/event-definitions/referral.d.ts +1 -1
- package/dist/types/snowplow/types.d.ts +1 -1
- package/dist/types/utils/testUtils.d.ts +2 -2
- package/package.json +23 -18
- package/src/address-lookup/index.test.ts +1 -0
- package/src/address-lookup/index.ts +13 -12
- package/src/airbrake/index.ts +1 -1
- package/src/mocks/eventDefinitions.ts +6 -6
- package/src/mocks/snowplowBrowserTrackerMock.js +1 -0
- package/src/snowplow/Snowplow.ts +15 -16
- package/src/snowplow/SnowplowContext.test.tsx +1 -1
- package/src/snowplow/SnowplowContext.tsx +5 -5
- package/src/snowplow/contexts.test.ts +1 -1
- package/src/snowplow/contexts.ts +1 -1
- package/src/snowplow/event-definitions/base.ts +1 -1
- package/src/snowplow/event-definitions/intervention.ts +1 -1
- package/src/snowplow/event-definitions/personalised_cover.ts +1 -1
- package/src/snowplow/event-definitions/qcp.ts +1 -1
- package/src/snowplow/event-definitions/questionnaire.ts +1 -1
- package/src/snowplow/event-definitions/redaction.ts +2 -2
- package/src/snowplow/event-definitions/referral.ts +1 -1
- package/src/snowplow/index.test.ts +35 -26
- package/src/snowplow/types.ts +1 -1
- package/src/utils/isObject.test.tsx +1 -0
- package/src/utils/isObject.tsx +7 -7
- package/src/utils/testUtils.tsx +4 -4
- package/src/utils/text.test.ts +1 -5
- package/src/utils/text.ts +0 -1
- package/dist/cjs/tsconfig.tsbuildinfo +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
AddressError,
|
|
3
3
|
AddressLookupConfig,
|
|
4
4
|
FindAddressResponse,
|
|
@@ -31,46 +31,47 @@ export class AddressLookup {
|
|
|
31
31
|
this.apiKey = apiKey;
|
|
32
32
|
this.limit = limit || LIMIT;
|
|
33
33
|
this.countries = countries || COUNTRIES;
|
|
34
|
-
|
|
34
|
+
const countriesParam = this.countries.join(",");
|
|
35
|
+
this.findUrl = `${FIND_URL}?Key=${this.apiKey}&Limit=${this.limit}&Countries=${countriesParam}`;
|
|
35
36
|
this.retrieveUrl = `${RETRIEVE_URL}?Key=${this.apiKey}`;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
private static async fetchFromApi(
|
|
39
|
+
private static async fetchFromApi<RespType>(
|
|
39
40
|
url: string,
|
|
40
|
-
handleResponse:
|
|
41
|
+
handleResponse: (data: RespType) => unknown,
|
|
41
42
|
): Promise<unknown> {
|
|
42
43
|
return new Promise((resolve, reject) => {
|
|
43
44
|
fetch(url)
|
|
44
|
-
.then(response => response.json())
|
|
45
|
+
.then(response => response.json() as Promise<RespType>)
|
|
45
46
|
.then(data => resolve(handleResponse(data)))
|
|
46
|
-
.catch(error => reject(Error(error)));
|
|
47
|
+
.catch(error => reject(Error(String(error))));
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
public find(partialAddress: string): Promise<Options> {
|
|
51
52
|
return new Promise((resolve, reject) => {
|
|
52
53
|
fetch(`${this.findUrl}&Text=${partialAddress}`)
|
|
53
|
-
.then(response => response.json())
|
|
54
|
+
.then(response => response.json() as Promise<FindAddressResponse>)
|
|
54
55
|
.then(data => resolve(this.formatItems(data)))
|
|
55
|
-
.catch(error => reject(Error(error)));
|
|
56
|
+
.catch(error => reject(Error(String(error))));
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
public findById(id: string): Promise<Options> {
|
|
60
61
|
return new Promise((resolve, reject) => {
|
|
61
62
|
fetch(`${this.findUrl}&Container=${id}`)
|
|
62
|
-
.then(response => response.json())
|
|
63
|
+
.then(response => response.json() as Promise<FindAddressResponse>)
|
|
63
64
|
.then(data => resolve(this.formatItems(data)))
|
|
64
|
-
.catch(error => reject(Error(error)));
|
|
65
|
+
.catch(error => reject(Error(String(error))));
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
public get(id: string): Promise<Record<string, string>> {
|
|
69
70
|
return new Promise((resolve, reject) => {
|
|
70
71
|
fetch(`${this.retrieveUrl}&Id=${id}`)
|
|
71
|
-
.then(response => response.json())
|
|
72
|
+
.then(response => response.json() as Promise<RetrieveAddressResponse>)
|
|
72
73
|
.then(data => resolve(AddressLookup.formatUkAddress(data)))
|
|
73
|
-
.catch(error => reject(Error(error)));
|
|
74
|
+
.catch(error => reject(Error(String(error))));
|
|
74
75
|
});
|
|
75
76
|
}
|
|
76
77
|
|
package/src/airbrake/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParamsType } from "../snowplow";
|
|
1
|
+
import type { ParamsType } from "../snowplow";
|
|
2
2
|
import { redact } from "../snowplow/event-definitions/redaction";
|
|
3
3
|
|
|
4
4
|
export default [
|
|
@@ -19,8 +19,8 @@ export default [
|
|
|
19
19
|
name: "questionAnswered",
|
|
20
20
|
type: "unstructured",
|
|
21
21
|
makePayload: (params: ParamsType) => {
|
|
22
|
-
const { section, context } = params
|
|
23
|
-
const { question, answer } = redact(params
|
|
22
|
+
const { section, context } = params;
|
|
23
|
+
const { question, answer } = redact(params);
|
|
24
24
|
|
|
25
25
|
return {
|
|
26
26
|
schema:
|
|
@@ -43,7 +43,7 @@ export default [
|
|
|
43
43
|
name: "primaryDetailSelected",
|
|
44
44
|
type: "unstructured",
|
|
45
45
|
makePayload: (params: ParamsType) => {
|
|
46
|
-
const { context, answer, vertical } = params
|
|
46
|
+
const { context, answer, vertical } = params;
|
|
47
47
|
const { site } = context;
|
|
48
48
|
let verticalName = vertical || context.vertical;
|
|
49
49
|
|
|
@@ -59,7 +59,7 @@ export default [
|
|
|
59
59
|
site,
|
|
60
60
|
vertical: verticalName,
|
|
61
61
|
primary_detail: answer,
|
|
62
|
-
selected_type:
|
|
62
|
+
selected_type: "trade_selector",
|
|
63
63
|
},
|
|
64
64
|
};
|
|
65
65
|
},
|
|
@@ -68,7 +68,7 @@ export default [
|
|
|
68
68
|
name: "helpTextOpened",
|
|
69
69
|
type: "unstructured",
|
|
70
70
|
makePayload: (params: ParamsType) => {
|
|
71
|
-
const { primaryText, label, context, helpText } = params
|
|
71
|
+
const { primaryText, label, context, helpText } = params;
|
|
72
72
|
|
|
73
73
|
return {
|
|
74
74
|
schema: "iglu:com.simplybusiness/help_text_opened/jsonschema/1-1-0",
|
package/src/snowplow/Snowplow.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
PageViewEvent,
|
|
3
3
|
StructuredEvent,
|
|
4
4
|
TrackerConfiguration,
|
|
5
|
+
} from "@snowplow/browser-tracker";
|
|
6
|
+
import {
|
|
5
7
|
newTracker,
|
|
6
8
|
setCookiePath,
|
|
7
9
|
setUserId,
|
|
@@ -10,7 +12,7 @@ import {
|
|
|
10
12
|
trackStructEvent,
|
|
11
13
|
} from "@snowplow/browser-tracker";
|
|
12
14
|
import { makeContexts, updateIdentityContext } from "./contexts";
|
|
13
|
-
import { EventDefinition, SerialisedEvent, TrackingProps } from "./types";
|
|
15
|
+
import type { EventDefinition, SerialisedEvent, TrackingProps } from "./types";
|
|
14
16
|
|
|
15
17
|
export type FrontOfficeStructuredEvent = StructuredEvent & {
|
|
16
18
|
serviceChannelIdentifier: string;
|
|
@@ -105,9 +107,9 @@ export class Snowplow {
|
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
// Send a page view event
|
|
108
|
-
|
|
110
|
+
trackView(event?: PageViewEvent) {
|
|
109
111
|
if (this.trackPageView) {
|
|
110
|
-
|
|
112
|
+
trackPageView({ ...event, context: this.pvContext }, [
|
|
111
113
|
this.avalancheTrackerName,
|
|
112
114
|
]);
|
|
113
115
|
}
|
|
@@ -115,28 +117,25 @@ export class Snowplow {
|
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
// Send a structured event with contexts
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
trackEvent(event: StructuredEvent) {
|
|
121
|
+
trackStructEvent({ ...event, context: this.structContext }, [
|
|
120
122
|
this.bronzeAvalancheTrackerName,
|
|
121
123
|
]);
|
|
122
124
|
return this;
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
// Send a custom event with defined schema and optional contexts
|
|
126
|
-
|
|
128
|
+
trackUnstructEvent(event: SerialisedEvent, contexts?: string[]) {
|
|
127
129
|
if (!event) {
|
|
128
130
|
return this;
|
|
129
131
|
}
|
|
130
132
|
|
|
131
133
|
if (contexts && Array.isArray(contexts) && contexts.length > 0) {
|
|
132
134
|
// Add context to the event
|
|
133
|
-
const context = makeContexts(contexts
|
|
134
|
-
|
|
135
|
-
await trackSelfDescribingEvent({ event, context }, [
|
|
136
|
-
this.avalancheTrackerName,
|
|
137
|
-
]);
|
|
135
|
+
const context = makeContexts(contexts, this.contexts);
|
|
136
|
+
trackSelfDescribingEvent({ event, context }, [this.avalancheTrackerName]);
|
|
138
137
|
} else {
|
|
139
|
-
|
|
138
|
+
trackSelfDescribingEvent({ event }, [this.avalancheTrackerName]);
|
|
140
139
|
}
|
|
141
140
|
return this;
|
|
142
141
|
}
|
|
@@ -149,7 +148,7 @@ export class Snowplow {
|
|
|
149
148
|
// Convert type into relevant function
|
|
150
149
|
if (type === "structured") {
|
|
151
150
|
this.addEventHandler(name, (params?: Record<string, unknown>) => {
|
|
152
|
-
this.trackEvent(
|
|
151
|
+
void this.trackEvent(
|
|
153
152
|
makePayload({
|
|
154
153
|
...params,
|
|
155
154
|
context,
|
|
@@ -164,9 +163,9 @@ export class Snowplow {
|
|
|
164
163
|
}) as SerialisedEvent;
|
|
165
164
|
|
|
166
165
|
if (contexts && Array.isArray(contexts) && contexts.length > 0) {
|
|
167
|
-
this.trackUnstructEvent(payload, contexts);
|
|
166
|
+
void this.trackUnstructEvent(payload, contexts);
|
|
168
167
|
} else {
|
|
169
|
-
this.trackUnstructEvent(payload);
|
|
168
|
+
void this.trackUnstructEvent(payload);
|
|
170
169
|
}
|
|
171
170
|
});
|
|
172
171
|
}
|
|
@@ -2,7 +2,7 @@ import { render, screen } from "@testing-library/react";
|
|
|
2
2
|
import { pageData } from "../mocks/scripts-mock";
|
|
3
3
|
import { getSnowplowConfig } from "./getSnowplowConfig";
|
|
4
4
|
import { SnowplowProvider } from "./SnowplowContext";
|
|
5
|
-
import { PageDataProps } from "./types";
|
|
5
|
+
import type { PageDataProps } from "./types";
|
|
6
6
|
|
|
7
7
|
const pageDataWithoutScripts = {
|
|
8
8
|
...pageData,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import { getContexts } from "./contexts";
|
|
12
12
|
import { eventDefinitions } from "./event-definitions";
|
|
13
13
|
import { Snowplow } from "./Snowplow";
|
|
14
|
-
import { EventDefinition, TrackingProps } from "./types";
|
|
14
|
+
import type { EventDefinition, TrackingProps } from "./types";
|
|
15
15
|
|
|
16
16
|
export interface SnowplowContextInterface {
|
|
17
17
|
config: TrackingProps;
|
|
@@ -34,11 +34,11 @@ export const SnowplowProvider = ({ scripts, children }: ProviderProps) => {
|
|
|
34
34
|
if (snowplow.current && scripts) {
|
|
35
35
|
const contexts = getContexts(config);
|
|
36
36
|
|
|
37
|
-
snowplow.current
|
|
38
|
-
.setContexts(contexts)
|
|
39
|
-
.addEventHandlers(eventDefinitions as EventDefinition[]);
|
|
37
|
+
snowplow.current.setContexts(contexts).addEventHandlers(eventDefinitions);
|
|
40
38
|
// Send page view event
|
|
41
|
-
if (config.trackPageView)
|
|
39
|
+
if (config.trackPageView) {
|
|
40
|
+
void snowplow.current.trackView();
|
|
41
|
+
}
|
|
42
42
|
}
|
|
43
43
|
}, [config, snowplow, scripts]);
|
|
44
44
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { pageData } from "../mocks/scripts-mock";
|
|
2
2
|
import { getContexts, makeContexts, updateIdentityContext } from "./contexts";
|
|
3
3
|
import { getSnowplowConfig } from "./getSnowplowConfig";
|
|
4
|
-
import { PageDataProps, TrackingProps } from "./types";
|
|
4
|
+
import type { PageDataProps, TrackingProps } from "./types";
|
|
5
5
|
|
|
6
6
|
describe("Snowplow Contexts", () => {
|
|
7
7
|
it("should extract all context records from snowplow props", () => {
|
package/src/snowplow/contexts.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParamsType } from "../types";
|
|
1
|
+
import type { ParamsType } from "../types";
|
|
2
2
|
|
|
3
3
|
const PII_ANSWER = [
|
|
4
4
|
"customer_title",
|
|
@@ -131,7 +131,7 @@ const RADIO_ANSWER_FROM_QUESTIONS = [
|
|
|
131
131
|
const ANSWER_SUFFIX_PATTERN = /_(yes|no)$/;
|
|
132
132
|
|
|
133
133
|
export const redact = (params: ParamsType) => {
|
|
134
|
-
let { question, answer } = params
|
|
134
|
+
let { question, answer } = params;
|
|
135
135
|
|
|
136
136
|
const piiAnswer = new Set(PII_ANSWER);
|
|
137
137
|
const radioAnswerFromQuestions = new Set(RADIO_ANSWER_FROM_QUESTIONS);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as SnowplowLib from "@snowplow/browser-tracker";
|
|
2
|
-
import { waitFor } from "@testing-library/
|
|
2
|
+
import { waitFor } from "@testing-library/react";
|
|
3
3
|
import eventDefinitions from "../mocks/eventDefinitions";
|
|
4
4
|
import { pageData } from "../mocks/scripts-mock";
|
|
5
5
|
import { getContexts, makeContexts } from "./contexts";
|
|
6
6
|
import { getSnowplowConfig } from "./getSnowplowConfig";
|
|
7
7
|
import { Snowplow } from "./Snowplow";
|
|
8
|
-
import { EventDefinition, PageDataProps, TrackingProps } from "./types";
|
|
8
|
+
import type { EventDefinition, PageDataProps, TrackingProps } from "./types";
|
|
9
9
|
|
|
10
10
|
const snowplowProps = getSnowplowConfig(pageData as PageDataProps);
|
|
11
11
|
const contexts = getContexts(snowplowProps as TrackingProps);
|
|
@@ -49,17 +49,26 @@ describe("Snowplow Analytics Class", () => {
|
|
|
49
49
|
.spyOn(SnowplowLib, "trackPageView")
|
|
50
50
|
.mockImplementation(() => {});
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
testSnowplow.trackView();
|
|
53
53
|
|
|
54
|
-
waitFor(() => {
|
|
54
|
+
await waitFor(() => {
|
|
55
55
|
expect(trackViewSpy).toHaveBeenCalledTimes(1);
|
|
56
|
+
});
|
|
57
|
+
await waitFor(() => {
|
|
56
58
|
expect(trackViewSpy).toHaveBeenCalledWith();
|
|
59
|
+
});
|
|
60
|
+
await waitFor(() => {
|
|
57
61
|
expect(innerSpy).toHaveBeenCalledTimes(1);
|
|
58
|
-
|
|
62
|
+
});
|
|
63
|
+
await waitFor(() => {
|
|
64
|
+
expect(innerSpy).toHaveBeenCalledWith(
|
|
65
|
+
{ context: testSnowplow.pvContext },
|
|
66
|
+
["sb-ava"],
|
|
67
|
+
);
|
|
59
68
|
});
|
|
60
69
|
});
|
|
61
70
|
|
|
62
|
-
it("tracks structured event and adds contexts",
|
|
71
|
+
it("tracks structured event and adds contexts", () => {
|
|
63
72
|
const trackStructEventSpy = jest.spyOn(testSnowplow, "trackEvent");
|
|
64
73
|
const innerSpy = jest
|
|
65
74
|
.spyOn(SnowplowLib, "trackStructEvent")
|
|
@@ -71,7 +80,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
71
80
|
label: "test-label",
|
|
72
81
|
};
|
|
73
82
|
|
|
74
|
-
|
|
83
|
+
testSnowplow.trackEvent(payload);
|
|
75
84
|
|
|
76
85
|
expect(trackStructEventSpy).toHaveBeenCalledTimes(1);
|
|
77
86
|
expect(trackStructEventSpy).toHaveBeenCalledWith(payload);
|
|
@@ -82,7 +91,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
82
91
|
);
|
|
83
92
|
});
|
|
84
93
|
|
|
85
|
-
it("tracks self-describing event and adds contexts",
|
|
94
|
+
it("tracks self-describing event and adds contexts", () => {
|
|
86
95
|
const trackUnstructEventSpy = jest.spyOn(
|
|
87
96
|
testSnowplow,
|
|
88
97
|
"trackUnstructEvent",
|
|
@@ -102,7 +111,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
102
111
|
},
|
|
103
112
|
};
|
|
104
113
|
|
|
105
|
-
|
|
114
|
+
testSnowplow.trackUnstructEvent(testEvent);
|
|
106
115
|
expect(trackUnstructEventSpy).toHaveBeenCalledTimes(1);
|
|
107
116
|
expect(trackUnstructEventSpy).toHaveBeenCalledWith(testEvent);
|
|
108
117
|
expect(innerSpy).toHaveBeenCalledTimes(1);
|
|
@@ -125,7 +134,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
125
134
|
]);
|
|
126
135
|
});
|
|
127
136
|
|
|
128
|
-
it("triggers an added structured event",
|
|
137
|
+
it("triggers an added structured event", () => {
|
|
129
138
|
testSnowplow.addEventHandlers(eventDefinitions as EventDefinition[]);
|
|
130
139
|
|
|
131
140
|
const trackStructEventSpy = jest.spyOn(testSnowplow, "trackEvent");
|
|
@@ -133,7 +142,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
133
142
|
.spyOn(SnowplowLib, "trackStructEvent")
|
|
134
143
|
.mockImplementation(() => {});
|
|
135
144
|
|
|
136
|
-
|
|
145
|
+
testSnowplow.trigger("navButtonClicked", { label: "test-label" });
|
|
137
146
|
|
|
138
147
|
const expectedPayload = {
|
|
139
148
|
category: "navigation",
|
|
@@ -151,7 +160,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
151
160
|
);
|
|
152
161
|
});
|
|
153
162
|
|
|
154
|
-
it("triggers an added unstructured event",
|
|
163
|
+
it("triggers an added unstructured event", () => {
|
|
155
164
|
testSnowplow.addEventHandlers(eventDefinitions as EventDefinition[]);
|
|
156
165
|
|
|
157
166
|
const trackUnstructEventSpy = jest.spyOn(
|
|
@@ -162,7 +171,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
162
171
|
.spyOn(SnowplowLib, "trackSelfDescribingEvent")
|
|
163
172
|
.mockImplementation(() => {});
|
|
164
173
|
|
|
165
|
-
|
|
174
|
+
testSnowplow.trigger("questionAnswered", {
|
|
166
175
|
question: "test-question",
|
|
167
176
|
section: "test-section",
|
|
168
177
|
answer: "test-answer",
|
|
@@ -197,7 +206,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
197
206
|
);
|
|
198
207
|
});
|
|
199
208
|
|
|
200
|
-
it("triggers an added unstructured event and readact the pii information and replace question name",
|
|
209
|
+
it("triggers an added unstructured event and readact the pii information and replace question name", () => {
|
|
201
210
|
testSnowplow.addEventHandlers(eventDefinitions as EventDefinition[]);
|
|
202
211
|
|
|
203
212
|
const trackUnstructEventSpy = jest.spyOn(
|
|
@@ -208,7 +217,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
208
217
|
.spyOn(SnowplowLib, "trackSelfDescribingEvent")
|
|
209
218
|
.mockImplementation(() => {});
|
|
210
219
|
|
|
211
|
-
|
|
220
|
+
testSnowplow.trigger("questionAnswered", {
|
|
212
221
|
question: "sof_bankrupt_yes",
|
|
213
222
|
section: "agreements",
|
|
214
223
|
answer: "Yes",
|
|
@@ -243,7 +252,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
243
252
|
);
|
|
244
253
|
});
|
|
245
254
|
|
|
246
|
-
it("triggers an added unstructured event and replace radio answer from questions",
|
|
255
|
+
it("triggers an added unstructured event and replace radio answer from questions", () => {
|
|
247
256
|
testSnowplow.addEventHandlers(eventDefinitions as EventDefinition[]);
|
|
248
257
|
|
|
249
258
|
const trackUnstructEventSpy = jest.spyOn(
|
|
@@ -254,7 +263,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
254
263
|
.spyOn(SnowplowLib, "trackSelfDescribingEvent")
|
|
255
264
|
.mockImplementation(() => {});
|
|
256
265
|
|
|
257
|
-
|
|
266
|
+
testSnowplow.trigger("questionAnswered", {
|
|
258
267
|
question: "have_secondary_trade_yes",
|
|
259
268
|
section: "about_your_business",
|
|
260
269
|
answer: "Yes",
|
|
@@ -289,7 +298,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
289
298
|
);
|
|
290
299
|
});
|
|
291
300
|
|
|
292
|
-
it("triggers an added unstructured event for address lookup type questions",
|
|
301
|
+
it("triggers an added unstructured event for address lookup type questions", () => {
|
|
293
302
|
testSnowplow.addEventHandlers(eventDefinitions as EventDefinition[]);
|
|
294
303
|
|
|
295
304
|
const trackUnstructEventSpy = jest.spyOn(
|
|
@@ -300,7 +309,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
300
309
|
.spyOn(SnowplowLib, "trackSelfDescribingEvent")
|
|
301
310
|
.mockImplementation(() => {});
|
|
302
311
|
|
|
303
|
-
|
|
312
|
+
testSnowplow.trigger("questionAnswered", {
|
|
304
313
|
question: "address_lookup",
|
|
305
314
|
section: "about_your_business",
|
|
306
315
|
answer: "123 Test Street",
|
|
@@ -348,7 +357,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
348
357
|
["Anything", "test", "Anything"],
|
|
349
358
|
])(
|
|
350
359
|
"triggers an primary_detail_selected event %s",
|
|
351
|
-
|
|
360
|
+
(initialVertical, answer, vertical) => {
|
|
352
361
|
testSnowplow.addEventHandlers(eventDefinitions as EventDefinition[]);
|
|
353
362
|
|
|
354
363
|
const trackUnstructEventSpy = jest.spyOn(
|
|
@@ -359,7 +368,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
359
368
|
.spyOn(SnowplowLib, "trackSelfDescribingEvent")
|
|
360
369
|
.mockImplementation(() => {});
|
|
361
370
|
|
|
362
|
-
|
|
371
|
+
testSnowplow.trigger("primaryDetailSelected", {
|
|
363
372
|
answer,
|
|
364
373
|
vertical: initialVertical,
|
|
365
374
|
});
|
|
@@ -371,7 +380,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
371
380
|
vertical,
|
|
372
381
|
primary_detail: answer,
|
|
373
382
|
site: "simplybusiness_us",
|
|
374
|
-
selected_type: "trade_selector"
|
|
383
|
+
selected_type: "trade_selector",
|
|
375
384
|
},
|
|
376
385
|
};
|
|
377
386
|
|
|
@@ -387,7 +396,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
387
396
|
},
|
|
388
397
|
);
|
|
389
398
|
|
|
390
|
-
it("triggers an added unstructured help_text_opened event",
|
|
399
|
+
it("triggers an added unstructured help_text_opened event", () => {
|
|
391
400
|
testSnowplow.addEventHandlers(eventDefinitions as EventDefinition[]);
|
|
392
401
|
|
|
393
402
|
const trackUnstructEventSpy = jest.spyOn(
|
|
@@ -398,7 +407,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
398
407
|
.spyOn(SnowplowLib, "trackSelfDescribingEvent")
|
|
399
408
|
.mockImplementation(() => {});
|
|
400
409
|
|
|
401
|
-
|
|
410
|
+
testSnowplow.trigger("helpTextOpened", {
|
|
402
411
|
primaryText: "Sample text",
|
|
403
412
|
label: "Sample label",
|
|
404
413
|
helpText: "Sample help text",
|
|
@@ -427,7 +436,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
427
436
|
);
|
|
428
437
|
});
|
|
429
438
|
|
|
430
|
-
it("uses server-supplied context in events",
|
|
439
|
+
it("uses server-supplied context in events", () => {
|
|
431
440
|
testSnowplow.addEventHandlers(eventDefinitions as EventDefinition[]);
|
|
432
441
|
|
|
433
442
|
const trackUnstructEventSpy = jest.spyOn(
|
|
@@ -438,7 +447,7 @@ describe("Snowplow Analytics Class", () => {
|
|
|
438
447
|
.spyOn(SnowplowLib, "trackSelfDescribingEvent")
|
|
439
448
|
.mockImplementation(() => {});
|
|
440
449
|
|
|
441
|
-
|
|
450
|
+
testSnowplow.trigger("questionAnswered", {
|
|
442
451
|
question: "test-question",
|
|
443
452
|
section: "test-section",
|
|
444
453
|
answer: "test-answer",
|
package/src/snowplow/types.ts
CHANGED
|
@@ -29,6 +29,7 @@ describe("isObject", () => {
|
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
it("should return false for objects with different prototypes", () => {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
32
33
|
const obj = Object.create(null);
|
|
33
34
|
expect(isObject(obj)).toBeFalsy();
|
|
34
35
|
});
|
package/src/utils/isObject.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export function isObject(value: unknown): value is Record<string, unknown> {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
return (
|
|
3
|
+
typeof value === "object" &&
|
|
4
|
+
value !== null &&
|
|
5
|
+
!Array.isArray(value) &&
|
|
6
|
+
Object.getPrototypeOf(value) === Object.prototype
|
|
7
|
+
);
|
|
8
|
+
}
|
package/src/utils/testUtils.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { ReactElement, ReactNode } from "react";
|
|
1
|
+
import type { RenderOptions } from "@testing-library/react";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import type { ReactElement, ReactNode } from "react";
|
|
4
4
|
import { pageData } from "../mocks/scripts-mock";
|
|
5
5
|
import { SnowplowProvider } from "../snowplow/SnowplowContext";
|
|
6
6
|
import { getSnowplowConfig } from "../snowplow/getSnowplowConfig";
|
|
7
|
-
import { PageDataProps } from "../snowplow/types";
|
|
7
|
+
import type { PageDataProps } from "../snowplow/types";
|
|
8
8
|
|
|
9
9
|
// Snowplow analytics
|
|
10
10
|
const snowplowProps = getSnowplowConfig(pageData as PageDataProps);
|
package/src/utils/text.test.ts
CHANGED
package/src/utils/text.ts
CHANGED