-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindMParticlesTemplates.test.ts
More file actions
120 lines (110 loc) · 3.49 KB
/
Copy pathfindMParticlesTemplates.test.ts
File metadata and controls
120 lines (110 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { EpicTest } from '../../../../models/epic';
import { UserCohort } from '../../helpers/shared';
import { findMParticleTemplates } from './findMParticleTemplates';
const baseTest: EpicTest = {
name: 'test',
status: 'Live',
locations: [],
regionTargeting: { targetedCountryGroups: [] },
tagIds: [],
sections: [],
excludedTagIds: [],
excludedSections: [],
alwaysAsk: false,
userCohort: UserCohort.Everyone,
hasCountryName: false,
variants: [],
highPriority: false,
useLocalViewLog: false,
methodologies: [],
};
describe('findMParticleTemplates', () => {
it('returns an empty array when there are no variants', () => {
const result = findMParticleTemplates({ ...baseTest, variants: [] });
expect(result).toEqual([]);
});
it('returns an empty array when variants have no mParticle templates', () => {
const result = findMParticleTemplates({
...baseTest,
variants: [
{
name: 'control',
heading: 'Hello world',
paragraphs: ['No templates here.'],
showTicker: false,
},
],
});
expect(result).toEqual([]);
});
it('finds a template in a variant heading', () => {
const result = findMParticleTemplates({
...baseTest,
variants: [
{ name: 'control', heading: '%%mParticle_firstName%%', paragraphs: [], showTicker: false },
],
});
expect(result).toEqual(['firstName']);
});
it('finds a template in a variant paragraph', () => {
const result = findMParticleTemplates({
...baseTest,
variants: [{ name: 'control', paragraphs: ['Hello %%mParticle_city%%!'], showTicker: false }],
});
expect(result).toEqual(['city']);
});
it('finds multiple distinct templates across heading and paragraphs', () => {
const result = findMParticleTemplates({
...baseTest,
variants: [
{
name: 'control',
heading: '%%mParticle_firstName%%',
paragraphs: ['You live in %%mParticle_city%%.', 'Your tier is %%mParticle_tier%%.'],
showTicker: false,
},
],
});
expect(result).toEqual(['firstName', 'city', 'tier']);
});
it('deduplicates templates that appear more than once', () => {
const result = findMParticleTemplates({
...baseTest,
variants: [
{
name: 'control',
heading: '%%mParticle_firstName%%',
paragraphs: ['Hi %%mParticle_firstName%%, welcome to %%mParticle_city%%.'],
showTicker: false,
},
],
});
expect(result).toEqual(['firstName', 'city']);
});
it('collects templates across multiple variants', () => {
const result = findMParticleTemplates({
...baseTest,
variants: [
{ name: 'control', paragraphs: ['%%mParticle_firstName%%'], showTicker: false },
{ name: 'variant', paragraphs: ['%%mParticle_city%%'], showTicker: false },
],
});
expect(result).toEqual(['firstName', 'city']);
});
it('does not match patterns that are not mParticle templates', () => {
const result = findMParticleTemplates({
...baseTest,
variants: [
{ name: 'control', paragraphs: ['%%ARTICLE_COUNT%% articles'], showTicker: false },
],
});
expect(result).toEqual([]);
});
it('handles a variant with no heading', () => {
const result = findMParticleTemplates({
...baseTest,
variants: [{ name: 'control', paragraphs: ['%%mParticle_country%%'], showTicker: false }],
});
expect(result).toEqual(['country']);
});
});