|
| 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 | +}); |
0 commit comments