Skip to content

Commit 1f4c8b7

Browse files
committed
test: add cinema tests
1 parent 362b178 commit 1f4c8b7

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

src/helpers/cinema.helper.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ export const getId = (url: string): number => {
2424
return null;
2525
};
2626

27-
export const getName = (el: HTMLElement | null): string => {
28-
return el.querySelector('h1').innerText.trim();
29-
};
30-
3127
export const getCoords = (el: HTMLElement | null): { lat: number; lng: number } => {
3228

3329
const linkMapsEl = el.querySelector('a[href*="q="]');

tests/cinema.helper.test.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { HTMLElement, parse } from 'node-html-parser';
22
import { describe, expect, test } from 'vitest';
3-
43
import {
54
getCinemaId,
65
getCinemaUrl,
76
getCoords,
7+
getFilms,
88
getGroupedFilmsByDate,
9-
parseCinema
9+
getId,
10+
parseCinema,
11+
parseMeta
1012
} from './../src/helpers/cinema.helper';
1113
import { cinemaMock } from './mocks/cinema.html';
1214

@@ -20,6 +22,15 @@ describe('Cinema info', () => {
2022
expect(item).toEqual<number>(110);
2123
});
2224

25+
test('getId returns correct id from url', () => {
26+
// /film/456 should return 456
27+
expect(getId('/film/456')).toBe(456);
28+
});
29+
30+
test('getId returns null for empty string', () => {
31+
expect(getId('')).toBeNull();
32+
});
33+
2334
test('cinemaUrl 0', () => {
2435
const item = getCinemaUrl(contentNode[0]);
2536
expect(item).toEqual<string>('http://www.cinestar.cz/cz/praha5/domu');
@@ -38,6 +49,12 @@ describe('Cinema info', () => {
3849
});
3950
});
4051

52+
test('getCoords returns null if no linkMapsEl', () => {
53+
// create html element without map link to test the null return
54+
const el = new HTMLElement('section', {}, '');
55+
expect(getCoords(el)).toBe(null);
56+
});
57+
4158
test('parseCinema', () => {
4259
const item = parseCinema(contentNode[10]);
4360
expect(item).toEqual({
@@ -54,9 +71,32 @@ describe('Cinema films by date', () => {
5471
expect(item[0]?.films[0].title).toEqual('13 dní, 13 nocí');
5572
});
5673

74+
test('getFilms returns correct film data', () => {
75+
const table = contentNode[2].querySelector('.cinema-table');
76+
const films = getFilms('', table);
77+
expect(Array.isArray(films)).toBe(true);
78+
if (films.length > 0) {
79+
expect(films[0]).toHaveProperty('id');
80+
expect(films[0]).toHaveProperty('title');
81+
expect(films[0]).toHaveProperty('url');
82+
expect(films[0]).toHaveProperty('colorRating');
83+
expect(films[0]).toHaveProperty('showTimes');
84+
expect(films[0]).toHaveProperty('meta');
85+
}
86+
});
87+
5788
test('getSubtitles', () => {
5889
const filmNode = contentNode[0].querySelectorAll('.cinema-table tr');
5990
const meta = filmNode[0].querySelector('.td-title span')?.text.trim();
6091
expect(meta).toEqual('T');
6192
});
6293
});
94+
95+
describe('parseMeta', () => {
96+
test('parseMeta converts T and D', () => {
97+
expect(parseMeta(['T', 'D', 'X'])).toEqual(['subtitles', 'dubbing', 'X']);
98+
});
99+
test('parseMeta empty array', () => {
100+
expect(parseMeta([])).toEqual([]);
101+
});
102+
});

0 commit comments

Comments
 (0)