-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathEmbed-test.js
More file actions
172 lines (140 loc) · 4.48 KB
/
Embed-test.js
File metadata and controls
172 lines (140 loc) · 4.48 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
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
import React from 'react'
import Embed from 'src/modules/Embed/Embed'
import * as common from 'test/specs/commonTests'
const assertIframeSrc = (props, srcPart) => {
const { id = 'default-test-id', source = 'youtube', ...rest } = props
shallow(<Embed active id={id} source={source} {...rest} />)
.find('iframe')
.should.have.attr('src')
.which.contains(srcPart)
}
describe('Embed', () => {
common.isConformant(Embed)
common.forwardsRef(Embed)
common.hasUIClassName(Embed)
common.rendersChildren(Embed, { requiredProps: { active: true } })
common.implementsHTMLIFrameProp(Embed, {
alwaysPresent: true,
assertExactMatch: false,
autoGenerateKey: false,
requiredProps: {
active: true,
id: 'default-test-id',
source: 'youtube',
},
shorthandDefaultProps: {
allowFullScreen: false,
frameBorder: 0,
height: '100%',
scrolling: 'no',
title: 'Embedded content from youtube.',
width: '100%',
},
})
common.implementsIconProp(Embed, {
alwaysPresent: true,
autoGenerateKey: false,
})
common.propKeyOnlyToClassName(Embed, 'active')
common.propValueOnlyToClassName(Embed, 'aspectRatio', ['4:3', '16:9', '21:9'])
describe('active', () => {
it('defaults to false', () => {
mount(<Embed />).should.have.not.className('active')
})
it('applies className', () => {
mount(<Embed active />).should.have.className('active')
})
it('renders nothing when false', () => {
const wrapper = mount(
<Embed>
<p id='foo' />
</Embed>,
)
wrapper.should.not.have.descendants('#foo')
})
})
describe('autoplay', () => {
it('generates url part for source', () => {
assertIframeSrc({ autoplay: true }, '&autoplay=true')
assertIframeSrc({ autoplay: false }, '&autoplay=false')
})
})
describe('brandedUI', () => {
it('generates "modestbranding" url parameter', () => {
assertIframeSrc({ brandedUI: true }, '&modestbranding=true')
assertIframeSrc({ brandedUI: false }, '&modestbranding=false')
})
it('generates "rel" url parameter', () => {
assertIframeSrc({ brandedUI: true }, '&rel=0')
assertIframeSrc({ brandedUI: false }, '&rel=1')
})
})
describe('color', () => {
it('generates url part for source', () => {
const color = 'red'
assertIframeSrc({ color }, `&color=${encodeURIComponent(color)}`)
})
})
describe('defaultActive', () => {
it('sets the initial active state', () => {
mount(<Embed defaultActive />).should.have.className('active')
mount(<Embed defaultActive={false} />).should.have.not.className('active')
})
})
describe('hd', () => {
it('generates url part for source', () => {
assertIframeSrc({ hd: true }, '&hq=true')
assertIframeSrc({ hd: false }, '&hq=false')
})
})
describe('placeholder', () => {
it('omitted by default', () => {
shallow(<Embed />)
.find('img.placeholder')
.should.have.length(0)
})
it('renders img when defined', () => {
const url = '/images/wireframe/image.png'
shallow(<Embed placeholder={url} />).should.contain(<img alt="Placeholder" className='placeholder' src={url} />)
})
})
describe('onClick', () => {
it('sets to active state', () => {
const wrapper = mount(<Embed />)
wrapper.simulate('click')
wrapper.should.have.className('active')
})
it('skips state update if active', () => {
const wrapper = mount(<Embed active />)
wrapper.simulate('click')
wrapper.should.have.className('active')
})
})
describe('source', () => {
it('generates url for YouTube', () => {
const id = 'foo'
assertIframeSrc({ id }, `//www.youtube.com/embed/${id}`)
})
it('generates url for Vimeo', () => {
const id = 'foo'
assertIframeSrc({ source: 'vimeo', id }, `//player.vimeo.com/video/${id}`)
})
it('sets the iframe title', () => {
const sources = ['youtube', 'vimeo']
sources.forEach((source) => {
shallow(<Embed active id='foo' source={source} />)
.find('iframe')
.should.have.attr('title')
.which.equals(`Embedded content from ${source}.`)
})
})
})
describe('url', () => {
it('passes url to iframe', () => {
const url = 'https://example.com'
shallow(<Embed active url={url} />)
.find('iframe')
.should.have.attr('src', url)
})
})
})