Skip to content

Commit 52a77e3

Browse files
author
Nir Maoz
authored
Refactor components and code style (#220)
1 parent d2f0305 commit 52a77e3

33 files changed

+879
-906
lines changed

__tests__/audio.test.js

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable no-unused-vars */
2-
import React from 'react'
2+
import React from 'react';
33
/* eslint-enable no-unused-vars */
4-
import { shallow, mount } from 'enzyme'
5-
import { Audio, Transformation } from 'cloudinary-react'
4+
import { shallow, mount } from 'enzyme';
5+
import { Audio, Transformation } from 'cloudinary-react';
66

77
describe('Audio', () => {
88
it('should include child transformation for a single source type', function () {
@@ -17,30 +17,30 @@ describe('Audio', () => {
1717
>
1818
<Transformation quality='70' />
1919
</Audio>
20-
)
21-
expect(tag.props().src).toEndWith('/q_70/du_3/dog.wav')
22-
})
20+
);
21+
expect(tag.props().src).toEndWith('/q_70/du_3/dog.wav');
22+
});
2323

2424
it('should support startOffset parameter', function () {
2525
let tag = shallow(
2626
<Audio cloudName='demo' sourceTypes='wav' publicId='dog'>
2727
<Transformation startOffset='auto' />
2828
</Audio>
29-
)
30-
expect(tag.props().src).toEndWith('/so_auto/dog.wav')
29+
);
30+
expect(tag.props().src).toEndWith('/so_auto/dog.wav');
3131
tag = shallow(
3232
<Audio cloudName='demo' sourceTypes='wav' publicId='dog'>
3333
<Transformation startOffset='2' />
3434
</Audio>
35-
)
36-
expect(tag.props().src).toEndWith('/so_2/dog.wav')
35+
);
36+
expect(tag.props().src).toEndWith('/so_2/dog.wav');
3737
tag = shallow(
3838
<Audio cloudName='demo' sourceTypes='wav' publicId='dog'>
3939
<Transformation startOffset='2.34' />
4040
</Audio>
41-
)
42-
expect(tag.props().src).toEndWith('/so_2.34/dog.wav')
43-
})
41+
);
42+
expect(tag.props().src).toEndWith('/so_2.34/dog.wav');
43+
});
4444

4545
it('should include child transformation for multiple source types', function () {
4646
const tag = shallow(
@@ -55,26 +55,26 @@ describe('Audio', () => {
5555
>
5656
<Transformation duration='2' />
5757
</Audio>
58-
)
58+
);
5959
expect(tag.find('[type="audio/vnd.wav"]').props().src).toEndWith(
6060
'/du_2/e_volume:30/dog.wav'
61-
)
61+
);
6262
expect(tag.find('[type="audio/mpeg"]').props().src).toEndWith(
6363
'/du_2/e_volume:45/dog.mp3'
64-
)
65-
})
64+
);
65+
});
6666

6767
it('should support inner text', function () {
6868
const tag = shallow(
6969
<Audio cloudName='demo' publicId='dog'>
7070
Your browser does not support the audio tag.
7171
</Audio>
72-
)
73-
expect(tag.type()).toEqual('audio')
74-
})
72+
);
73+
expect(tag.type()).toEqual('audio');
74+
});
7575

7676
it('Should support forwarding innerRef to underlying audio element', function () {
77-
const myRef = React.createRef()
77+
const myRef = React.createRef();
7878

7979
const tag = mount(
8080
<Audio
@@ -86,43 +86,44 @@ describe('Audio', () => {
8686
ogg: { duration: 2 }
8787
}}
8888
/>
89-
)
89+
);
9090

91-
const audio = myRef.current
91+
const audio = myRef.current;
9292

93-
expect(tag.find('audio').prop('src')).toEndWith('/du_2/dog.ogg')
93+
expect(tag.find('audio').prop('src')).toEndWith('/du_2/dog.ogg');
9494
expect(audio.src).toEndWith('/du_2/dog.ogg')
9595
;['play', 'pause', 'canPlayType', 'addTextTrack'].forEach((func) =>
9696
expect(typeof audio[func]).toBe('function')
97-
)
98-
})
97+
);
98+
});
9999

100100
it('Should not set a poster attribute', function () {
101-
const tag = shallow(<Audio cloudName='demo' publicId='dog' />)
101+
const tag = shallow(<Audio cloudName='demo' publicId='dog' />);
102102

103-
expect(tag.props().poster).toEqual(undefined)
104-
})
103+
expect(tag.props().poster).toEqual(undefined);
104+
});
105105

106106
it('Should pass camelCase attributes to Audio component', function () {
107107
const tag = shallow(
108108
<Audio playsInline autoPlay cloudName='demo' publicId='dog' />
109-
)
109+
);
110110

111-
const { autoPlay, auto_play } = tag.props()
111+
// eslint-disable-next-line camelcase
112+
const { autoPlay, auto_play } = tag.props();
112113

113-
expect(autoPlay).toEqual(true)
114+
expect(autoPlay).toEqual(true);
114115

115-
expect(auto_play).toEqual(undefined)
116-
})
116+
expect(auto_play).toEqual(undefined);
117+
});
117118
it('Should pass camelCase attributes to inner audio element', function () {
118-
const tag = mount(<Audio autoPlay cloudName='demo' publicId='dog' />)
119+
const tag = mount(<Audio autoPlay cloudName='demo' publicId='dog' />);
119120

120-
const audio = tag.find('audio')
121-
expect(audio.prop('autoPlay')).toEqual(true)
121+
const audio = tag.find('audio');
122+
expect(audio.prop('autoPlay')).toEqual(true);
122123

123-
expect(audio.prop('plays_inline')).toEqual(undefined)
124-
expect(audio.prop('auto_play')).toEqual(undefined)
125-
})
124+
expect(audio.prop('plays_inline')).toEqual(undefined);
125+
expect(audio.prop('auto_play')).toEqual(undefined);
126+
});
126127
it('should generate default source tags', function () {
127128
const tag = shallow(
128129
<Audio
@@ -136,15 +137,15 @@ describe('Audio', () => {
136137
>
137138
<Transformation quality='70' />
138139
</Audio>
139-
)
140+
);
140141
expect(tag.find('[type="audio/aac"]').props().src).toEndWith(
141142
'/du_1/dog.aac'
142-
)
143+
);
143144
expect(tag.find('[type="audio/mpeg"]').props().src).toEndWith(
144145
'/du_2/dog.mp3'
145-
)
146+
);
146147
expect(tag.find('[type="audio/ogg"]').props().src).toEndWith(
147148
'/du_3/dog.ogg'
148-
)
149-
})
150-
})
149+
);
150+
});
151+
});

__tests__/context.test.js

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import React from 'react'
2-
import { mount } from 'enzyme'
1+
import React from 'react';
2+
import { mount } from 'enzyme';
33

4-
import { Image, CloudinaryContext } from 'cloudinary-react'
4+
import { Image, CloudinaryContext } from 'cloudinary-react';
55

66
describe('CloudinaryContext', () => {
77
it('should pass properties to children', function () {
88
const tag = mount(
99
<CloudinaryContext className='root' cloudName='demo'>
1010
<Image publicId='sample' />
1111
</CloudinaryContext>
12-
)
12+
);
1313

14-
expect(tag.html().startsWith('<div')).toEqual(true)
15-
expect(tag.find('div').hasClass('root')).toEqual(true)
16-
expect(tag.children()).toHaveLength(1)
17-
const img = tag.find('div').childAt(0)
14+
expect(tag.html().startsWith('<div')).toEqual(true);
15+
expect(tag.find('div').hasClass('root')).toEqual(true);
16+
expect(tag.children()).toHaveLength(1);
17+
const img = tag.find('div').childAt(0);
1818
expect(img.html()).toEqual(
19-
`<img src="http://res.cloudinary.com/demo/image/upload/sample">`
20-
)
21-
})
19+
'<img src="http://res.cloudinary.com/demo/image/upload/sample">'
20+
);
21+
});
2222

2323
it('should render without div', function () {
2424
const tag = mount(
2525
<CloudinaryContext className='root' cloudName='demo' includeOwnBody>
2626
<Image publicId='sample' />
2727
</CloudinaryContext>
28-
)
28+
);
2929

30-
expect(tag.html().startsWith('<div')).toEqual(false)
31-
})
30+
expect(tag.html().startsWith('<div')).toEqual(false);
31+
});
3232
it('should render with div', function () {
3333
const tag = mount(
3434
<CloudinaryContext
@@ -38,36 +38,36 @@ describe('CloudinaryContext', () => {
3838
>
3939
<Image publicId='sample' />
4040
</CloudinaryContext>
41-
)
41+
);
4242

43-
expect(tag.html().startsWith('<div')).toEqual(true)
44-
})
43+
expect(tag.html().startsWith('<div')).toEqual(true);
44+
});
4545

4646
it('should pass properties to children with snake case', function () {
4747
const tag = mount(
4848
<CloudinaryContext className='root' cloudName='demo' fetch_format='auto'>
4949
<Image publicId='sample' />
5050
</CloudinaryContext>
51-
)
51+
);
5252

53-
const img = tag.find('div').childAt(0)
53+
const img = tag.find('div').childAt(0);
5454
expect(img.html()).toEqual(
55-
`<img src="http://res.cloudinary.com/demo/image/upload/f_auto/sample">`
56-
)
57-
})
55+
'<img src="http://res.cloudinary.com/demo/image/upload/f_auto/sample">'
56+
);
57+
});
5858

5959
it('should pass properties to children with kebab case', function () {
6060
const tag = mount(
6161
<CloudinaryContext className='root' cloudName='demo' fetch-format='auto'>
6262
<Image publicId='sample' />
6363
</CloudinaryContext>
64-
)
64+
);
6565

66-
const img = tag.find('div').childAt(0)
66+
const img = tag.find('div').childAt(0);
6767
expect(img.html()).toEqual(
68-
`<img src="http://res.cloudinary.com/demo/image/upload/f_auto/sample">`
69-
)
70-
})
68+
'<img src="http://res.cloudinary.com/demo/image/upload/f_auto/sample">'
69+
);
70+
});
7171

7272
it('should remove Cloudinary custom properties from CloudinaryContext component', function () {
7373
const html = mount(
@@ -81,20 +81,20 @@ describe('CloudinaryContext', () => {
8181
>
8282
<Image publicId='sample' />
8383
</CloudinaryContext>
84-
)
84+
);
8585

86-
const contextDiv = html.find('div')
87-
expect(contextDiv.find('.root').length).toEqual(1)
88-
expect(contextDiv.find("[role='tab']").length).toEqual(1)
89-
expect(contextDiv.find("[aria-live='polite']").length).toEqual(1)
90-
expect(contextDiv.find("[cloudName='demo']").length).toEqual(0)
91-
expect(contextDiv.find('[quality]').length).toEqual(0)
86+
const contextDiv = html.find('div');
87+
expect(contextDiv.find('.root').length).toEqual(1);
88+
expect(contextDiv.find("[role='tab']").length).toEqual(1);
89+
expect(contextDiv.find("[aria-live='polite']").length).toEqual(1);
90+
expect(contextDiv.find("[cloudName='demo']").length).toEqual(0);
91+
expect(contextDiv.find('[quality]').length).toEqual(0);
9292

9393
// Verify that transformations from context are applied to components
9494
expect(contextDiv.find('img').prop('src')).toEqual(
9595
'https://res.cloudinary.com/demo/image/upload/q_auto/sample'
96-
)
97-
})
96+
);
97+
});
9898

9999
it('should allow chained Contexts', function () {
100100
const tag = mount(
@@ -103,25 +103,25 @@ describe('CloudinaryContext', () => {
103103
<Image publicId='sample' />
104104
</CloudinaryContext>
105105
</CloudinaryContext>
106-
)
106+
);
107107
expect(tag.find('img').prop('src')).toEqual(
108108
'http://res.cloudinary.com/demo/image/upload/c_scale,w_100/sample'
109-
)
110-
})
109+
);
110+
});
111111

112112
it('should update url on context change', function () {
113113
const tag = mount(
114114
<CloudinaryContext cloudName='demo'>
115115
<Image publicId='sample' />
116116
</CloudinaryContext>
117-
)
117+
);
118118

119119
expect(tag.find('img').prop('src')).toEqual(
120120
'http://res.cloudinary.com/demo/image/upload/sample'
121-
)
122-
tag.setProps({ cloudName: 'demo2' }).update()
121+
);
122+
tag.setProps({ cloudName: 'demo2' }).update();
123123
expect(tag.find('img').prop('src')).toEqual(
124124
'http://res.cloudinary.com/demo2/image/upload/sample'
125-
)
126-
})
127-
})
125+
);
126+
});
127+
});

0 commit comments

Comments
 (0)