-
Notifications
You must be signed in to change notification settings - Fork 42
/
shared-slices.base.js
187 lines (176 loc) · 4.37 KB
/
shared-slices.base.js
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import React from "react";
import TestRenderer from "react-test-renderer";
import { SectionContext } from "@times-components/context";
import { iterator } from "@times-components/test-utils";
import {
mockCommentLeadAndCartoonSlice,
mockDailyRegisterSlice,
mockLeadOneAndFourSlice,
mockLeadOneFullWidthSlice,
mockLeadOneAndOneSlice,
mockLeadTwoNoPicAndTwoSlice,
mockLeadersSlice,
mockSecondaryOneSlice,
mockSecondaryOneAndColumnistSlice,
mockSecondaryFourSlice,
mockStandardSlice,
mockListTwoAndSixNoPicSlice,
mockSecondaryTwoAndTwoSlice,
mockSecondaryTwoNoPicAndTwoSlice,
mockSecondaryOneAndFourSlice,
getPuzzleSlices
} from "@times-components/fixture-generator";
import Responsive from "@times-components/responsive";
import "./mocks";
import {
CommentLeadAndCartoonSlice,
DailyRegisterLeadFourSlice,
LeadOneAndFourSlice,
LeadOneAndOneSlice,
LeadOneFullWidthSlice,
LeadTwoNoPicAndTwoSlice,
ListTwoAndSixNoPicSlice,
LeadersSlice,
SecondaryOneSlice,
SecondaryOneAndColumnistSlice,
SecondaryFourSlice,
SecondaryOneAndFourSlice,
SecondaryTwoAndTwoSlice,
SecondaryTwoNoPicAndTwoSlice,
PuzzleSlice,
StandardSlice
} from "../src/slices";
const slices = [
{
mock: mockDailyRegisterSlice(),
name: "daily universal register",
Slice: DailyRegisterLeadFourSlice
},
{
mock: mockLeadOneFullWidthSlice(),
name: "lead one full width",
Slice: LeadOneFullWidthSlice
},
{
mock: mockLeadOneAndOneSlice(),
name: "lead one and one",
Slice: LeadOneAndOneSlice
},
{
mock: mockLeadOneAndFourSlice(),
name: "lead one and four",
Slice: LeadOneAndFourSlice
},
{
mock: mockStandardSlice(),
name: "standard",
Slice: StandardSlice
},
{
mock: mockLeadTwoNoPicAndTwoSlice(),
name: "lead Two No Pic And Two",
Slice: LeadTwoNoPicAndTwoSlice
},
{
mock: mockSecondaryOneSlice(),
name: "secondary one",
Slice: SecondaryOneSlice
},
{
mock: mockSecondaryOneAndColumnistSlice(),
name: "secondary one and columnist",
Slice: SecondaryOneAndColumnistSlice
},
{
mock: mockSecondaryFourSlice(),
name: "secondary four",
Slice: SecondaryFourSlice
},
{
mock: mockSecondaryOneAndFourSlice(),
name: "secondary one and four",
Slice: SecondaryOneAndFourSlice
},
{
mock: mockSecondaryTwoAndTwoSlice(),
name: "secondary two and two",
Slice: SecondaryTwoAndTwoSlice
},
{
mock: mockSecondaryTwoNoPicAndTwoSlice(),
name: "secondary two no pic and two",
Slice: SecondaryTwoNoPicAndTwoSlice
},
{
mock: mockListTwoAndSixNoPicSlice(),
name: "list two and six no pic",
Slice: ListTwoAndSixNoPicSlice
},
{
mock: mockLeadersSlice(),
name: "leaders",
Slice: LeadersSlice
},
{
mock: mockCommentLeadAndCartoonSlice(),
name: "Comment lead and cartoon",
Slice: CommentLeadAndCartoonSlice
},
{
mock: { puzzles: getPuzzleSlices(3) },
name: "puzzle",
Slice: PuzzleSlice
}
];
const slicesWithPubLogo = [
{
mock: mockSecondaryOneAndFourSlice(),
name: "secondary one and four",
Slice: SecondaryOneAndFourSlice
},
{
mock: mockLeadersSlice(),
name: "leaders",
Slice: LeadersSlice
}
];
jest.mock("@times-components/utils", () => {
// eslint-disable-next-line global-require
const actualUtils = jest.requireActual("@times-components/utils");
return {
...actualUtils,
getDimensions: jest.fn(() => ({ height: 700, width: 500 }))
};
});
const testsWithPublictaion = publicationName =>
slicesWithPubLogo.map(({ mock, name, Slice }) => ({
name,
test: () => {
const output = TestRenderer.create(
<Responsive>
<SectionContext.Provider value={{ publicationName }}>
<Slice onPress={() => {}} slice={mock} />
</SectionContext.Provider>
</Responsive>
);
expect(output).toMatchSnapshot();
}
}));
export default () => {
const commonTests = slices.map(({ mock, name, Slice }) => ({
name,
test: () => {
const output = TestRenderer.create(
<Responsive>
<Slice onPress={() => {}} slice={mock} />
</Responsive>
);
expect(output).toMatchSnapshot();
}
}));
const testsForTimes = testsWithPublictaion("TIMES");
const testsForST = testsWithPublictaion("SUNDAYTIMES");
iterator(commonTests);
iterator(testsForST);
iterator(testsForTimes);
};