Skip to content

Commit 4f5cb0e

Browse files
committed
reafactor(cinemas): temp
1 parent 4a31984 commit 4f5cb0e

File tree

6 files changed

+11115
-2
lines changed

6 files changed

+11115
-2
lines changed

demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { csfd } from './src';
33

44
// Parse movie
5-
csfd.cinema(1).then((cinema) => console.log(cinema));
5+
csfd.cinema(1, 'today').then((cinema) => console.log(cinema));
66
// csfd.movie(10135).then((movie) => console.log(movie));
77

88
// csfd.search('matrix').then((search) => console.log(search));

src/helpers/cinema.helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const getCoords = (el: HTMLElement | null): { lat: number; lng: number }
3939
};
4040

4141
export const getCinemaUrl = (el: HTMLElement | null): string => {
42-
return el.querySelector('.box-header .cinema-logo a')?.attributes.href;
42+
return el.querySelector('.box-header .cinema-logo a')?.attributes.href ?? '';
4343
};
4444

4545
export const parseCinema = (el: HTMLElement | null): { city: string; name: string } => {

tests/cinema.helper.test.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { HTMLElement, parse } from 'node-html-parser';
2+
import { describe, expect, test } from 'vitest';
3+
4+
import {
5+
getCinemaId,
6+
getCinemaUrl,
7+
getCoords,
8+
getGroupedFilmsByDate,
9+
parseCinema
10+
} from './../src/helpers/cinema.helper';
11+
import { cinemaMock } from './mocks/cinema.html';
12+
13+
const html = parse(cinemaMock);
14+
15+
const contentNode: HTMLElement[] = html.querySelectorAll('#snippet--cinemas section.box');
16+
17+
describe('Cinema info', () => {
18+
test('cinemaId', () => {
19+
const item = getCinemaId(contentNode[0]);
20+
expect(item).toEqual<number>(110);
21+
});
22+
23+
test('cinemaUrl 0', () => {
24+
const item = getCinemaUrl(contentNode[0]);
25+
expect(item).toEqual<string>('http://www.cinestar.cz/cz/praha5/domu');
26+
});
27+
28+
test('cinemaUrl 2', () => {
29+
const item = getCinemaUrl(contentNode[2]);
30+
expect(item).toEqual<string>('');
31+
});
32+
33+
test('cinemaCoords', () => {
34+
const item = getCoords(contentNode[2]);
35+
expect(item).toEqual({
36+
lat: 50.1000546,
37+
lng: 14.4301766
38+
});
39+
});
40+
41+
test('parseCinema', () => {
42+
const item = parseCinema(contentNode[2]);
43+
expect(item).toEqual({
44+
city: 'Praha',
45+
name: 'Bio Oko'
46+
});
47+
});
48+
});
49+
50+
describe('Cinema films by date', () => {
51+
test('getGroupedFilmsByDate', () => {
52+
const item = getGroupedFilmsByDate(contentNode[2]);
53+
expect(item[0]?.date).toEqual('sobota 13.01.2024');
54+
expect(item[0]?.films[0].title).toEqual('Cesta do fantazie');
55+
});
56+
57+
test('getFilms', () => {
58+
const filmNode = contentNode[0].querySelectorAll('.cinema-table tr');
59+
60+
console.log('aas', filmNode[0].querySelectorAll('.td-title span'));
61+
const meta = filmNode[0].querySelectorAll('.td-title span')?.map((x) => x.text.trim());
62+
expect(meta).toEqual({
63+
city: 'Praha',
64+
name: 'Bio Oko'
65+
});
66+
});
67+
});
File renamed without changes.

0 commit comments

Comments
 (0)