UNPKG

1.01 kBJavaScriptView Raw
1import { swatchUrl } from 'SRC'
2
3describe('(Util) swatchUrl', () => {
4 describe('when a custom swatch has been provided', () => {
5 test('returns a cloudinary url for the custom swatch', () => {
6 const colorway = buildColorway({
7 swatch_cloudinary_key: 'test/custom_swatch'
8 })
9
10 const url = swatchUrl(colorway)
11
12 expect(url).toMatch(/test\/custom_swatch.jpg$/)
13 })
14 })
15
16 describe('when a custom swatch has not been provided', () => {
17 test('returns a cloudinary url for the default swatch', () => {
18 const colorway = buildColorway({
19 swatch_cloudinary_key: null
20 })
21
22 const url = swatchUrl(colorway)
23
24 expect(url).toMatch(/test\/front.jpg$/)
25 expect(url).toMatch(/t_swatch_v2/)
26 })
27 })
28})
29
30function buildColorway(overrides = {}) {
31 return {
32 shots: [
33 { shot_type: 'back', cloudinary_key: 'test/back' },
34 { shot_type: 'front', cloudinary_key: 'test/front' }
35 ],
36 swatch_cloudinary_key: null,
37 ...overrides
38 }
39}