This repository was archived by the owner on May 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.spec.js
More file actions
146 lines (129 loc) · 4.03 KB
/
index.spec.js
File metadata and controls
146 lines (129 loc) · 4.03 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
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
import React from 'react';
import jest from 'jest';
import {shallow} from 'enzyme';
import LinkToInbox, { StyledInboxButton, StyledInboxLink, StyledInboxInput, InboxButton, InboxInput } from '.';
it('renders with a gmail email', () => {
const rendered = shallow(
<LinkToInbox email={'example@gmail.com'}/>
);
expect(rendered.type()).toBe('a');
expect(rendered.text()).toBe('Open in Gmail');
});
it('renders with a hotmail email', () => {
const rendered = shallow(
<LinkToInbox email={'example@hotmail.com'}/>
);
expect(rendered.type()).toBe('a');
expect(rendered.text()).toBe('Open in Outlook');
});
it('renders with an unrecognized domain if configured', () => {
const rendered = shallow(
<LinkToInbox email={'example@example.com'} guessUnknownDomain={true} />
);
expect(rendered.type()).toBe('a');
expect(rendered.text()).toBe('Open in example.com');
});
it('renders nothing with an unrecognized domain by default', () => {
const rendered = shallow(
<LinkToInbox email={'example@example.com'} />
);
expect(rendered.type()).toBe(null);
});
it('renders as a button', () => {
const rendered = shallow(
<LinkToInbox
email={'example@live.com'}
tag={'button'}
/>
);
expect(rendered.type()).toBe('button');
expect(rendered.text()).toBe('Open in Outlook');
});
it('includes passed classNames', () => {
const className = 'test-class';
const rendered = shallow(
<LinkToInbox
email={'example@live.com'}
className={className}
/>
);
expect(rendered.hasClass(className)).toBe(true);
});
it('navigates on click', () => {
const rendered = shallow(
<LinkToInbox
email={'example@gmail.com'}
tag={'button'}
/>
);
rendered.find('button').simulate('click');
expect(window.location.href).toBe('about:blank');
});
it('renders as an input type button', () => {
const rendered = shallow(
<LinkToInbox
email={'example@outlook.com'}
tag={'input'}
/>
);
expect(rendered.type()).toBe('input');
expect(rendered.is('input[value="Open in Outlook"]')).toBe(true);
});
it('renders text from a template', () => {
const rendered = shallow(
<LinkToInbox
email={'example@gmail.com'}
template={'<%- name %> <%- protocol %> <%- domain %> <%- path %> <%- href %>'}
/>
);
expect(rendered.text()).toBe('Gmail https mail.google.com /mail/u/0/#search/in%3Aanywhere https://mail.google.com/mail/u/0/#search/in%3Aanywhere');
});
it('renders a InboxButton', () => {
const rendered = shallow(
<InboxButton email={'example@gmail.com'}/>
);
expect(rendered.type()).toBe(LinkToInbox);
expect(rendered.text()).toBe('<LinkToInbox />');
});
it('renders a InboxInput', () => {
const rendered = shallow(
<InboxInput email={'example@gmail.com'}/>
);
expect(rendered.type()).toBe(LinkToInbox);
expect(rendered.text()).toBe('<LinkToInbox />');
});
it('renders a StyledInboxButton', () => {
const rendered = shallow(
<StyledInboxButton email={'example@gmail.com'}/>
);
expect(rendered.type()).toBe(InboxButton);
expect(rendered.text()).toBe('<InboxButton />');
});
it('renders a StyledInboxLink', () => {
const rendered = shallow(
<StyledInboxLink email={'example@gmail.com'}/>
);
expect(rendered.type()).toBe(LinkToInbox);
expect(rendered.text()).toBe('<LinkToInbox />');
});
it('renders a StyledInboxInput', () => {
const rendered = shallow(
<StyledInboxInput email={'example@gmail.com'}/>
);
expect(rendered.type()).toBe(InboxInput);
expect(rendered.text()).toBe('<InboxInput />');
});
it('throws on unsupported tag types', () => {
expect(() => shallow(<LinkToInbox
email={'example@live.com'}
tag={'div'}
/>)).toThrow(new Error(`unrecognized tag div`));
});
it('throws on invalid email addresses', () => {
expect(() => shallow(<LinkToInbox
email={'example'}
/>)).toThrow(new Error(`Invalid email address example`));
});
it('throws on unprovided email addresses', () => {
expect(() => shallow(<LinkToInbox/>)).toThrow(new Error(`email is required`));
});