-
Notifications
You must be signed in to change notification settings - Fork 42
/
shared.base.js
91 lines (76 loc) · 2.3 KB
/
shared.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
import React from "react";
import mockDate from "mockdate";
import TestRenderer from "react-test-renderer";
import { mockNativeModules } from "@times-components/mocks";
import { iterator } from "@times-components/test-utils";
import Link from "@times-components/link";
import { withTrackingContext } from "@times-components/tracking";
import ArticleTopics from "../src/article-topics";
import ArticleTopic from "../src/article-topic";
import topicData from "../fixtures/topics";
mockNativeModules();
export default () => {
beforeEach(() => {
mockDate.set(1514764800000, 0);
});
afterEach(() => {
mockDate.reset();
});
const tests = [
{
name: "group of topics",
test: () => {
const testInstance = TestRenderer.create(
<ArticleTopics onPress={() => {}} topics={topicData} />
);
expect(testInstance).toMatchSnapshot();
}
},
{
name: "onPress handler is called with the expected args",
test: () => {
const onPress = jest.fn();
const testInstance = TestRenderer.create(
<ArticleTopics onPress={onPress} topics={topicData} />
);
const [link] = testInstance.root.findAll(node => node.type === Link);
link.props.onPress("event");
expect(onPress.mock.calls).toMatchSnapshot();
}
},
{
name: "onPress sends analytics",
test: () => {
const analyticsStream = jest.fn();
const ArticleTopicsWithTracking = withTrackingContext(ArticleTopics, {
trackingObjectName: "Article"
});
const testInstance = TestRenderer.create(
<ArticleTopicsWithTracking
analyticsStream={analyticsStream}
onPress={() => {}}
topics={topicData}
/>
);
const [link] = testInstance.root.findAll(node => node.type === Link);
link.props.onPress("event");
expect(analyticsStream.mock.calls).toMatchSnapshot();
}
},
{
name: "article topic",
test: () => {
const testInstance = TestRenderer.create(
<ArticleTopic
key="test-slug"
name="Test"
onPress={() => {}}
slug="test-slug"
/>
);
expect(testInstance).toMatchSnapshot();
}
}
];
iterator(tests);
};