This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Code.test.jsx
143 lines (130 loc) · 2.95 KB
/
Code.test.jsx
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
const React = require('react');
const { mount } = require('enzyme');
const Code = require('../../src/block-types/Code');
const block = {
type: 'code',
sidebar: undefined,
data: {
codes: [
{
code: 'whjdwhjwejhkwhjk',
language: 'text',
status: 400,
name: 'test',
},
{
code: 'var a = 1',
language: 'javascript',
},
{
code: 'whjdwhjwejhkwhjk',
language: 'text',
name: 'test',
},
],
},
};
const block3 = {
type: 'code',
sidebar: undefined,
data: {
codes: [
{
code: 'whjdwhjwejhkwhjk',
language: 'text',
status: 400,
},
],
},
};
const badBlock = {
type: 'code',
sidebar: undefined,
data: {
codes: {
code: {
code: 'whjdwhjwejhkwhjk',
language: 'text',
status: 400,
},
},
},
};
const block2 = {
type: 'code',
sidebar: undefined,
data: {
codes: [
{
code: 'var a = 1',
language: 'javascript',
},
],
},
};
test('Code will render name if provided within em tag if codes has a status', () => {
const codeInput = mount(<Code block={block} />);
expect(codeInput.find('em').text()).toBe('test');
});
test('Code will render status code within em tag', () => {
const codeInput = mount(<Code block={block3} />);
expect(codeInput.find('em').text()).toBe('Bad Request');
});
test('If codes array is not passed as an array expect empty array', () => {
const codeInput = mount(<Code block={badBlock} />);
expect(codeInput.find('span').text()).toBe('');
});
test('Code will render language if name or status is not provided within a tag if codes has a status', () => {
const codeInput = mount(<Code block={block2} />);
expect(codeInput.find('a').text()).toBe('JavaScript');
});
test('Code will render label if provided within opts', () => {
const codeInput = mount(<Code block={block} opts={{ label: 'label' }} />);
expect(codeInput.find('label').text()).toBe('label');
});
test('Code should switch tabs', () => {
const codeInput = mount(<Code block={block} opts={{}} />);
const anchor = codeInput.find('li a').at(1);
anchor.simulate('click');
expect(anchor.render().hasClass('active')).toBe(true);
});
test('should uppercase known languages', () => {
expect(
mount(
<Code
block={{
data: {
codes: [
{
language: 'http',
code: '',
},
],
},
}}
/>,
)
.find('li a')
.text(),
).toBe('HTTP');
});
test('should pass through unknown languages', () => {
expect(
mount(
<Code
block={{
data: {
codes: [
{
language: 'unknown-language-somehow',
code: '',
},
],
},
}}
/>,
)
.find('li a')
.text(),
).toBe('unknown-language-somehow');
});