1
1
import { HTMLElement , parse } from 'node-html-parser' ;
2
2
import { describe , expect , test } from 'vitest' ;
3
-
4
3
import {
5
4
getCinemaId ,
6
5
getCinemaUrl ,
7
6
getCoords ,
7
+ getFilms ,
8
8
getGroupedFilmsByDate ,
9
- parseCinema
9
+ getId ,
10
+ parseCinema ,
11
+ parseMeta
10
12
} from './../src/helpers/cinema.helper' ;
11
13
import { cinemaMock } from './mocks/cinema.html' ;
12
14
@@ -20,6 +22,15 @@ describe('Cinema info', () => {
20
22
expect ( item ) . toEqual < number > ( 110 ) ;
21
23
} ) ;
22
24
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
+
23
34
test ( 'cinemaUrl 0' , ( ) => {
24
35
const item = getCinemaUrl ( contentNode [ 0 ] ) ;
25
36
expect ( item ) . toEqual < string > ( 'http://www.cinestar.cz/cz/praha5/domu' ) ;
@@ -38,6 +49,12 @@ describe('Cinema info', () => {
38
49
} ) ;
39
50
} ) ;
40
51
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
+
41
58
test ( 'parseCinema' , ( ) => {
42
59
const item = parseCinema ( contentNode [ 10 ] ) ;
43
60
expect ( item ) . toEqual ( {
@@ -54,9 +71,32 @@ describe('Cinema films by date', () => {
54
71
expect ( item [ 0 ] ?. films [ 0 ] . title ) . toEqual ( '13 dní, 13 nocí' ) ;
55
72
} ) ;
56
73
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
+
57
88
test ( 'getSubtitles' , ( ) => {
58
89
const filmNode = contentNode [ 0 ] . querySelectorAll ( '.cinema-table tr' ) ;
59
90
const meta = filmNode [ 0 ] . querySelector ( '.td-title span' ) ?. text . trim ( ) ;
60
91
expect ( meta ) . toEqual ( 'T' ) ;
61
92
} ) ;
62
93
} ) ;
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