Skip to content

Commit e33a989

Browse files
committed
test(cinema): test coords
1 parent 27c1bec commit e33a989

File tree

2 files changed

+152
-10
lines changed

2 files changed

+152
-10
lines changed

tests/cinema.helper.test.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,77 @@ describe('Cinema info', () => {
5555
expect(getCinemaCoords(el)).toBe(null);
5656
});
5757

58+
test('getCoords returns null if element is null', () => {
59+
expect(getCinemaCoords(null)).toBe(null);
60+
});
61+
62+
test('getCoords returns null if coordinates are not finite - latitude is Infinity', () => {
63+
const el = parse('<div><a href="https://maps.google.cz/maps?q=Infinity,14.4605098">Infinite latitude</a></div>');
64+
expect(getCinemaCoords(el)).toBe(null);
65+
});
66+
67+
test('getCoords returns null if coordinates are not finite - longitude is Infinity', () => {
68+
const el = parse('<div><a href="https://maps.google.cz/maps?q=50.0779486,Infinity">Infinite longitude</a></div>');
69+
expect(getCinemaCoords(el)).toBe(null);
70+
});
71+
72+
test('getCoords returns null if coordinates are not finite - latitude is -Infinity', () => {
73+
const el = parse('<div><a href="https://maps.google.cz/maps?q=-Infinity,14.4605098">Negative infinite latitude</a></div>');
74+
expect(getCinemaCoords(el)).toBe(null);
75+
});
76+
77+
test('getCoords returns null if coordinates are not finite - longitude is -Infinity', () => {
78+
const el = parse('<div><a href="https://maps.google.cz/maps?q=50.0779486,-Infinity">Negative infinite longitude</a></div>');
79+
expect(getCinemaCoords(el)).toBe(null);
80+
});
81+
82+
test('getCoords returns null if coordinates are not finite - latitude is NaN', () => {
83+
const el = parse('<div><a href="https://maps.google.cz/maps?q=notanumber,14.4605098">NaN latitude</a></div>');
84+
expect(getCinemaCoords(el)).toBe(null);
85+
});
86+
87+
test('getCoords returns null if coordinates are not finite - longitude is NaN', () => {
88+
const el = parse('<div><a href="https://maps.google.cz/maps?q=50.0779486,notanumber">NaN longitude</a></div>');
89+
expect(getCinemaCoords(el)).toBe(null);
90+
});
91+
92+
test('getCoords returns null if both coordinates are not finite', () => {
93+
const el = parse('<div><a href="https://maps.google.cz/maps?q=Infinity,NaN">Both invalid</a></div>');
94+
expect(getCinemaCoords(el)).toBe(null);
95+
});
96+
97+
test('getCoords returns null if linkMapsEl exists but has no href attribute', () => {
98+
const el = parse('<div><a>No href</a></div>');
99+
expect(getCinemaCoords(el)).toBe(null);
100+
});
101+
102+
test('getCoords returns valid coordinates for proper format', () => {
103+
const el = parse('<div><a href="https://maps.google.cz/maps?q=50.1234567,14.9876543">Valid coordinates</a></div>');
104+
const result = getCinemaCoords(el);
105+
expect(result).toEqual({
106+
lat: 50.1234567,
107+
lng: 14.9876543
108+
});
109+
});
110+
111+
test('getCoords handles negative coordinates correctly', () => {
112+
const el = parse('<div><a href="https://maps.google.cz/maps?q=-50.1234567,-14.9876543">Negative coordinates</a></div>');
113+
const result = getCinemaCoords(el);
114+
expect(result).toEqual({
115+
lat: -50.1234567,
116+
lng: -14.9876543
117+
});
118+
});
119+
120+
test('getCoords handles zero coordinates correctly', () => {
121+
const el = parse('<div><a href="https://maps.google.cz/maps?q=0,0">Zero coordinates</a></div>');
122+
const result = getCinemaCoords(el);
123+
expect(result).toEqual({
124+
lat: 0,
125+
lng: 0
126+
});
127+
});
128+
58129
test('parseCinema', () => {
59130
const item = parseCinema(contentNode[10]);
60131
expect(item).toEqual({

tests/user-ratings.test.ts

Lines changed: 81 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,93 @@ describe('Get year', () => {
101101
});
102102

103103
describe('Get color rating', () => {
104-
// test('Black', () => {
105-
// const movie = getUserRatingColorRating(movies[7]);
106-
// expect(movie).toEqual<CSFDColorRating>('bad');
107-
// });
108-
// test('Gray', () => {
109-
// const movie = getUserRatingColorRating(movies[29]);
110-
// expect(movie).toEqual<CSFDColorRating>('unknown');
111-
// });
112-
test('Blue', () => {
104+
test('Blue color should return average', () => {
113105
const movie = getUserRatingColorRating(movies[3]);
114106
expect(movie).toEqual<CSFDColorRating>('average');
115107
});
116-
test('Red', () => {
108+
109+
test('Red color should return good', () => {
117110
const movie = getUserRatingColorRating(movies[1]);
118111
expect(movie).toEqual<CSFDColorRating>('good');
119112
});
113+
114+
test('Grey color should return bad', () => {
115+
// Create a mock element with grey class
116+
const mockElement = parse(`
117+
<tr>
118+
<td class="name">
119+
<span class="icon grey"></span>
120+
</td>
121+
</tr>
122+
`);
123+
const result = getUserRatingColorRating(mockElement);
124+
expect(result).toEqual<CSFDColorRating>('bad');
125+
});
126+
127+
test('Lightgrey color should return unknown', () => {
128+
// Create a mock element with lightgrey class
129+
const mockElement = parse(`
130+
<tr>
131+
<td class="name">
132+
<span class="icon lightgrey"></span>
133+
</td>
134+
</tr>
135+
`);
136+
const result = getUserRatingColorRating(mockElement);
137+
expect(result).toEqual<CSFDColorRating>('unknown');
138+
});
139+
140+
test('Unknown/invalid color should return unknown (default case)', () => {
141+
// Create a mock element with an unknown color class
142+
const mockElement = parse(`
143+
<tr>
144+
<td class="name">
145+
<span class="icon purple"></span>
146+
</td>
147+
</tr>
148+
`);
149+
const result = getUserRatingColorRating(mockElement);
150+
expect(result).toEqual<CSFDColorRating>('unknown');
151+
});
152+
153+
test('No color class should return unknown (default case)', () => {
154+
// Create a mock element with no color class
155+
const mockElement = parse(`
156+
<tr>
157+
<td class="name">
158+
<span class="icon"></span>
159+
</td>
160+
</tr>
161+
`);
162+
const result = getUserRatingColorRating(mockElement);
163+
expect(result).toEqual<CSFDColorRating>('unknown');
164+
});
165+
166+
test('Empty string color should return unknown (default case)', () => {
167+
// Create a mock element with empty class
168+
const mockElement = parse(`
169+
<tr>
170+
<td class="name">
171+
<span class="icon "></span>
172+
</td>
173+
</tr>
174+
`);
175+
const result = getUserRatingColorRating(mockElement);
176+
expect(result).toEqual<CSFDColorRating>('unknown');
177+
});
178+
179+
test('Multiple classes with valid color should work', () => {
180+
// Create a mock element with multiple classes including a valid color
181+
const mockElement = parse(`
182+
<tr>
183+
<td class="name">
184+
<span class="icon some-other-class another-class red"></span>
185+
</td>
186+
</tr>
187+
`);
188+
const result = getUserRatingColorRating(mockElement);
189+
expect(result).toEqual<CSFDColorRating>('good');
190+
});
120191
});
121192

122193
describe('Get date', () => {

0 commit comments

Comments
 (0)