Skip to content

Commit

Permalink
tests: add tests on utils
Browse files Browse the repository at this point in the history
  • Loading branch information
theo-mesnil committed Aug 17, 2024
1 parent 1a877e5 commit 8f9ca94
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/utils/images.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getImageUrl } from './images';

describe('Images utils', () => {
test('getImageUrl', () => {
expect(getImageUrl('image-url.png')).toBe(
'https://image.tmdb.org/t/p/w185image-url.png'
);
expect(getImageUrl('image-url.png', 'w1280')).toBe(
'https://image.tmdb.org/t/p/w1280image-url.png'
);
});
});
24 changes: 24 additions & 0 deletions src/utils/networks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NETWORK_HBO_ID, NETWORK_NETFLIX_ID } from 'constants/networks';

import { getNetworkColor, getNetworkFromUrl } from './networks';

describe('Networks utils', () => {
test('getNetworkFromUrl', () => {
expect(getNetworkFromUrl('this-is-url.com')).toBe(undefined);
expect(getNetworkFromUrl('https://www.netflix.com/link-to')).toBe(
NETWORK_NETFLIX_ID
);
expect(getNetworkFromUrl('hbo.com/house-of-dragon')).toBe(NETWORK_HBO_ID);
});

test('getNetworkColor', () => {
expect(getNetworkColor(NETWORK_NETFLIX_ID)).toStrictEqual([
'#E50914',
'#b70710'
]);
expect(getNetworkColor(NETWORK_HBO_ID)).toStrictEqual([
'#7B2ABF',
'#441769'
]);
});
});
9 changes: 9 additions & 0 deletions src/utils/time.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { formatTime } from './time';

describe('Time utils', () => {
test('formatTime', () => {
expect(formatTime(10)).toBe('10min');
expect(formatTime(60)).toBe('1h');
expect(formatTime(78)).toBe('1h18m');
});
});
21 changes: 21 additions & 0 deletions src/utils/videos.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getVideo } from './videos';

describe('Videos utils', () => {
test('getVideo for unknown platform', () => {
const { imageUrl, isYoutube } = getVideo({ id: '1', platform: 'unknown' });
expect(imageUrl).toBe('https://i.vimeocdn.com/video/1_640.jpg');
expect(isYoutube).toBe(false);
});

test('getVideo for vimeo platform', () => {
const { imageUrl, isYoutube } = getVideo({ id: '1', platform: 'vimeo' });
expect(imageUrl).toBe('https://i.vimeocdn.com/video/1_640.jpg');
expect(isYoutube).toBe(false);
});

test('getVideo for youtube platform', () => {
const { imageUrl, isYoutube } = getVideo({ id: '1', platform: 'YouTube' });
expect(imageUrl).toBe('https://i.ytimg.com/vi/1/hqdefault.jpg');
expect(isYoutube).toBe(true);
});
});

0 comments on commit 8f9ca94

Please sign in to comment.