-
Notifications
You must be signed in to change notification settings - Fork 42
/
shared-with-style.native.js
191 lines (178 loc) · 4.58 KB
/
shared-with-style.native.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
188
189
190
191
import React from "react";
import TestRenderer from "react-test-renderer";
import { ContextProviderWithDefaults } from "@times-components/context";
import {
addSerializers,
compose,
flattenStyleTransform,
minimaliseTransform,
minimalNativeTransform,
print
} from "@times-components/jest-serializer";
import { themeFactory } from "@times-components/styleguide";
import { setIsTablet } from "./mocks.native";
import ArticleMagazineStandard from "../src/article-magazine-standard";
import articleFixture, { testFixture } from "../fixtures/full-article";
import sharedProps from "./shared-props";
const article = articleFixture({
...testFixture,
content: [
{
attributes: {
caption: "An image caption",
credits: "The image credits",
display: "primary",
ratio: "1500:1000",
url: "https://image.io"
},
children: [],
name: "image"
},
{
attributes: {},
children: [
{
attributes: {
value: "Some content"
},
children: [],
name: "text"
},
{
attributes: {
href: "https://link.io",
target: "_blank"
},
children: [
{
attributes: {
value: "Some Link"
},
children: [],
name: "text"
}
],
name: "link"
}
],
name: "paragraph"
},
{
attributes: {
caption: {
name: "AName",
text: "a text",
twitter: "@AName"
}
},
children: [
{
attributes: {
value: "The pull quote content"
},
children: [],
name: "text"
}
],
name: "pullQuote"
},
{
attributes: {
brightcoveAccountId: "57838016001",
brightcovePolicyKey: "1.2.3.4",
brightcoveVideoId: "4084164751001",
caption: "This is video caption",
display: "primary",
paidOnly: "false",
posterImageId: "0c0309d4-1aeb-11e8-9010-1eef6ba5d3de",
posterImageUrl: "https://image.io",
skySports: false
},
children: [],
name: "video"
},
{
attributes: {},
children: [],
name: "ad"
},
{
attributes: {
caption: "A Caption",
credits: "Some Credits",
display: "secondary",
ratio: "3:2",
url: "https://image-2.io"
},
children: [],
name: "image"
},
{
attributes: {
caption: "A Caption",
credits: "Some Credits",
display: "inline",
ratio: "9:4",
url: "https://image-inline.io"
},
children: [],
name: "image"
}
]
});
const themeForSection = section => ({
theme: {
...themeFactory(section, "magazinestandard"),
scale: "medium"
}
});
export default () => {
addSerializers(
expect,
compose(
print,
minimalNativeTransform,
minimaliseTransform((value, key) => key !== "style"),
flattenStyleTransform
)
);
it("phone full article with style", () => {
const testRenderer = TestRenderer.create(
<ArticleMagazineStandard {...sharedProps} article={article} />
);
expect(testRenderer).toMatchSnapshot();
});
it("tablet full article with style", () => {
setIsTablet(true);
const testRenderer = TestRenderer.create(
<ArticleMagazineStandard {...sharedProps} article={article} />
);
expect(testRenderer).toMatchSnapshot();
});
it("full article with style in the culture magazine", () => {
const testRenderer = TestRenderer.create(
<ContextProviderWithDefaults value={themeForSection("culture")}>
<ArticleMagazineStandard {...sharedProps} article={article} />
</ContextProviderWithDefaults>
);
expect(testRenderer).toMatchSnapshot();
});
it("full article with style in the style magazine", () => {
const testRenderer = TestRenderer.create(
<ContextProviderWithDefaults value={themeForSection("style")}>
<ArticleMagazineStandard {...sharedProps} article={article} />
</ContextProviderWithDefaults>
);
expect(testRenderer).toMatchSnapshot();
});
it("full article with style in the sunday times magazine", () => {
const testRenderer = TestRenderer.create(
<ContextProviderWithDefaults
value={themeForSection("thesundaytimesmagazine")}
>
<ArticleMagazineStandard {...sharedProps} article={article} />
</ContextProviderWithDefaults>
);
expect(testRenderer).toMatchSnapshot();
});
};