Skip to content

Commit

Permalink
tests: add maestro tests and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
theo-mesnil committed Aug 17, 2024
1 parent c1df3cd commit 1a877e5
Show file tree
Hide file tree
Showing 64 changed files with 549 additions and 41 deletions.
49 changes: 36 additions & 13 deletions __tests__/Movie.test.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,60 @@
import Movie from 'app/movie/[id]';

import { MOCK_LOGO, MOCK_LOGO_EMPTY } from 'api/__mocks__/logo';
import { MOCK_MOVIE, MOCK_MOVIE_WITH_NETWORK } from 'api/__mocks__/movie';

import * as logo from '../src/api/logo';
import * as movie from '../src/api/movie';
import { mockQuery, render, screen } from '../tests/render';

describe('<Movie />', () => {
test('should render correctly', () => {
jest.spyOn(movie, 'useGetMovie').mockReturnValue(mockQuery(MOCK_MOVIE));
jest.spyOn(logo, 'useGetContentLogo').mockReturnValue(mockQuery(MOCK_LOGO));

render(<Movie />);

const releaseDate = screen.getByTestId('release-date');
expect(releaseDate).toHaveTextContent('November 16, 2001');

const runtime = screen.getByTestId('runtime');
expect(runtime).toHaveTextContent('2h32m');

const votes = screen.getByTestId('votes');
expect(votes).toHaveTextContent('7.9 (26908)');

const network = screen.queryByTestId('network-1234');
expect(network).toBeFalsy();
expect(screen.getByTestId('release-date')).toHaveTextContent(
'November 16, 2001'
);
expect(screen.getByTestId('runtime')).toHaveTextContent('2h32m');
expect(screen.getByTestId('votes')).toHaveTextContent('7.9 (26908)');
expect(screen.queryByTestId('network-1234')).toBeFalsy();
expect(screen.queryByTestId('subtitle')).toHaveTextContent(
'Adventure - Fantasy'
);
expect(screen.queryByTestId('cover-title')).toBeFalsy();
expect(screen.queryByTestId('cover-image')).toHaveProp('source', {
uri: 'https://image.tmdb.org/t/p/w780/hziiv14OpD73u9gAak4XDDfBKa2.jpg'
});
expect(screen.queryByTestId('cover-logo')).toHaveProp(
'src',
'https://image.tmdb.org/t/p/w500url-logo.png'
);
});

test('should render correctly with network', () => {
jest
.spyOn(movie, 'useGetMovie')
.mockReturnValue(mockQuery(MOCK_MOVIE_WITH_NETWORK));
jest.spyOn(logo, 'useGetContentLogo').mockReturnValue(mockQuery(MOCK_LOGO));

render(<Movie />);

expect(screen.getByTestId('network-213')).toBeTruthy();
});

test('should render correctly without logo', () => {
jest.spyOn(movie, 'useGetMovie').mockReturnValue(mockQuery(MOCK_MOVIE));
jest
.spyOn(logo, 'useGetContentLogo')
.mockReturnValue(mockQuery(MOCK_LOGO_EMPTY));

render(<Movie />);

const network = screen.queryByTestId('network-213');
expect(network).toBeTruthy();
expect(screen.queryByTestId('cover-title')).toHaveTextContent(
"Harry Potter and the Philosopher's Stone"
);
expect(screen.queryByTestId('cover-logo')).toBeFalsy();
});
});
55 changes: 55 additions & 0 deletions __tests__/person.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Person from 'app/person/[id]';

import {
MOCK_PERSON,
MOCK_PERSON_MOVIES,
MOCK_PERSON_TV
} from 'api/__mocks__/person';

import * as person from '../src/api/person';
import { mockQuery, render, screen } from '../tests/render';

describe('<Person />', () => {
test('should render correctly', () => {
jest.spyOn(person, 'useGetPerson').mockReturnValue(mockQuery(MOCK_PERSON));
jest
.spyOn(person, 'useGetPersonMovieCredits')
.mockReturnValue(mockQuery(MOCK_PERSON_MOVIES));
jest
.spyOn(person, 'useGetPersonTvCredits')
.mockReturnValue(mockQuery(MOCK_PERSON_TV));

render(<Person />);

expect(screen.getByTestId('department')).toHaveTextContent('Acting');
expect(screen.getByTestId('birthday')).toHaveTextContent(
'Born on July 23, 1989 (35y)'
);
expect(screen.getByTestId('place-of-birth')).toHaveTextContent(
'Hammersmith, London, England, UK'
);
expect(screen.getByTestId('movies')).toHaveTextContent('1 movie');
expect(screen.getByTestId('series')).toHaveTextContent('1 serie');
expect(screen.queryByTestId('cover-title')).toHaveTextContent(
'Daniel Radcliffe'
);
expect(screen.queryByTestId('cover-image')).toHaveProp('source', {
uri: 'https://image.tmdb.org/t/p/w780/iPg0J9UzAlPj1fLEJNllpW9IhGe.jpg'
});
});

test('should render correctly with deathday', () => {
jest
.spyOn(person, 'useGetPerson')
.mockReturnValue(mockQuery({ ...MOCK_PERSON, deathday: '2024-07-23' }));

render(<Person />);

expect(screen.getByTestId('birthday')).toHaveTextContent(
'Born on July 23, 1989'
);
expect(screen.getByTestId('deathday')).toHaveTextContent(
'Died on July 23, 2024 (35y)'
);
});
});
56 changes: 56 additions & 0 deletions __tests__/tv.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import Tv from 'app/tv/[id]';

import { MOCK_LOGO, MOCK_LOGO_EMPTY } from 'api/__mocks__/logo';
import { MOCK_TV, MOCK_TV_WITH_NETWORK } from 'api/__mocks__/tv';

import * as logo from '../src/api/logo';
import * as tv from '../src/api/tv';
import { mockQuery, render, screen } from '../tests/render';

describe('<Tv />', () => {
test('should render correctly', () => {
jest.spyOn(tv, 'useGetTv').mockReturnValue(mockQuery(MOCK_TV));
jest.spyOn(logo, 'useGetContentLogo').mockReturnValue(mockQuery(MOCK_LOGO));

render(<Tv />);

expect(screen.getByTestId('release-date')).toHaveTextContent('2022 - 2024');
expect(screen.getByTestId('runtime')).toHaveTextContent('1h8m');
expect(screen.getByTestId('votes')).toHaveTextContent('8.4 (4773)');
expect(screen.queryByTestId('network-1234')).toBeFalsy();
expect(screen.queryByTestId('subtitle')).toHaveTextContent(
'Sci-Fi & Fantasy - Drama'
);
expect(screen.queryByTestId('cover-title')).toBeFalsy();
expect(screen.queryByTestId('cover-image')).toHaveProp('source', {
uri: 'https://image.tmdb.org/t/p/w780/etj8E2o0Bud0HkONVQPjyCkIvpv.jpg'
});
expect(screen.queryByTestId('cover-logo')).toHaveProp(
'src',
'https://image.tmdb.org/t/p/w500url-logo.png'
);
});

test('should render correctly with network', () => {
jest.spyOn(tv, 'useGetTv').mockReturnValue(mockQuery(MOCK_TV_WITH_NETWORK));
jest.spyOn(logo, 'useGetContentLogo').mockReturnValue(mockQuery(MOCK_LOGO));

render(<Tv />);

expect(screen.getByTestId('network-49')).toBeTruthy();
});

test('should render correctly without logo', () => {
jest.spyOn(tv, 'useGetTv').mockReturnValue(mockQuery(MOCK_TV));
jest
.spyOn(logo, 'useGetContentLogo')
.mockReturnValue(mockQuery(MOCK_LOGO_EMPTY));

render(<Tv />);

expect(screen.queryByTestId('cover-title')).toHaveTextContent(
'House of the Dragon'
);
expect(screen.queryByTestId('cover-logo')).toBeFalsy();
});
});
52 changes: 52 additions & 0 deletions maestro/discover.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
appId: com.theomesnil.WhatToWatch
---
- launchApp
- waitForAnimationToEnd
- takeScreenshot: 'maestro/screenshots/discover/index'
- tapOn: 'Discover'
- tapOn:
id: 'header-back-button'
- tapOn:
point: '14%,79%'
- tapOn:
id: 'header-back-button'
- scroll
- takeScreenshot: 'maestro/screenshots/discover/index-2'
- tapOn: '1'
- tapOn:
id: 'header-back-button'
- tapOn:
point: '18%,52%'
- tapOn:
id: 'header-back-button'
- tapOn: 'Action Action'
- tapOn:
id: 'header-back-button'
- scroll
- takeScreenshot: 'maestro/screenshots/discover/index-3'
- tapOn:
point: '33%,28%'
- tapOn:
id: 'header-back-button'
- tapOn: '1'
- tapOn:
id: 'header-back-button'
- tapOn:
point: '18%,84%'
- tapOn:
id: 'header-back-button'
- scroll
- takeScreenshot: 'maestro/screenshots/discover/index-4'
- tapOn: 'Action & Adventure Action & Adventure'
- tapOn:
id: 'header-back-button'
- scroll
- takeScreenshot: 'maestro/screenshots/discover/index-5'
- tapOn:
point: '33%,48%'
- tapOn:
id: 'header-back-button'
- tapOn:
point: '18%,78%'
- tapOn:
id: 'header-back-button'
35 changes: 35 additions & 0 deletions maestro/genre.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
appId: com.theomesnil.WhatToWatch
---
- launchApp
- scroll
- scroll
- tapOn: 'Action Action'
- takeScreenshot: 'maestro/screenshots/genre/movie'
- tapOn:
point: '50%,31%'
- tapOn:
id: 'header-back-button'
- scroll
- takeScreenshot: 'maestro/screenshots/genre/movie-2'
- tapOn:
point: '19%,26%'
- tapOn:
id: 'header-back-button'
- tapOn:
id: 'header-back-button'
- scroll
- scroll
- tapOn: 'Action & Adventure Action & Adventure'
- takeScreenshot: 'maestro/screenshots/genre/tv'
- tapOn:
point: '50%,31%'
- tapOn:
id: 'header-back-button'
- scroll
- takeScreenshot: 'maestro/screenshots/genre/tv-2'
- tapOn:
point: '19%,26%'
- tapOn:
id: 'header-back-button'
- tapOn:
id: 'header-back-button'
6 changes: 0 additions & 6 deletions maestro/index.yml

This file was deleted.

21 changes: 21 additions & 0 deletions maestro/network.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
appId: com.theomesnil.WhatToWatch
---
- launchApp
- tapOn: 'Streaming, tab, 3 of 3'
- waitForAnimationToEnd
- takeScreenshot: 'maestro/screenshots/network/streaming'
- scroll
- takeScreenshot: 'maestro/screenshots/network/streaming-2'
- tapOn:
point: '18%,78%'
- takeScreenshot: 'maestro/screenshots/network/index'
- tapOn:
point: '50%,31%'
- assertVisible: '2 seasons'
- tapOn:
id: 'header-back-button'
- scroll
- takeScreenshot: 'maestro/screenshots/network/index-2'
- tapOn:
point: '50%,28%'
- assertVisible: '7 seasons'
35 changes: 35 additions & 0 deletions maestro/person.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
appId: com.theomesnil.WhatToWatch
---
- launchApp
- tapOn: 'Search, tab, 2 of 3'
- tapOn: 'What would you like to watch?'
- inputText: 'Daniel Radcliffe'
- doubleTapOn:
point: '19%,38%'
- waitForAnimationToEnd
- takeScreenshot: 'maestro/screenshots/person/index'
- scroll
- takeScreenshot: 'maestro/screenshots/person/index-2'
- tapOn:
point: '25%,42%'
- takeScreenshot: 'maestro/screenshots/person/know-for'
- tapOn:
id: 'header-back-button'
- tapOn:
id: 'credits-movie'
- takeScreenshot: 'maestro/screenshots/person/movies'
- tapOn:
id: 'header-back-button'
- tapOn:
id: 'credits-tv'
- takeScreenshot: 'maestro/screenshots/person/series'
- tapOn:
id: 'header-back-button'
- tapOn:
point: '18%,85%'
- swipe:
direction: LEFT
- takeScreenshot: 'maestro/screenshots/person/pictures'
- tapOn:
id: 'header-close-button'
- assertVisible: 'Pictures'
Binary file added maestro/screenshots/discover/index-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/discover/index-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/discover/index-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/discover/index-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/discover/index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/genre/movie-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/genre/movie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/genre/tv-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/genre/tv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed maestro/screenshots/home/index.png
Binary file not shown.
Binary file modified maestro/screenshots/movie/backdrops.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified maestro/screenshots/movie/index-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified maestro/screenshots/movie/index-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified maestro/screenshots/movie/index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified maestro/screenshots/movie/posters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified maestro/screenshots/movie/trailer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified maestro/screenshots/movie/video.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/network/index-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/network/index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/network/streaming-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/network/streaming.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/person/index-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/person/index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/person/know-for.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/person/movies.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maestro/screenshots/person/pictures.png
Binary file added maestro/screenshots/person/series.png
Binary file modified maestro/screenshots/search/end.png
Binary file modified maestro/screenshots/search/index.png
Binary file modified maestro/screenshots/search/input.png
Binary file added maestro/screenshots/tv/backdrops.png
Binary file added maestro/screenshots/tv/casting.png
Binary file added maestro/screenshots/tv/index-2.png
Binary file added maestro/screenshots/tv/index-3.png
Binary file added maestro/screenshots/tv/index-4.png
Binary file added maestro/screenshots/tv/index-5.png
Binary file added maestro/screenshots/tv/index.png
Binary file added maestro/screenshots/tv/posters.png
Binary file added maestro/screenshots/tv/trailer.png
Binary file added maestro/screenshots/tv/video.png
47 changes: 47 additions & 0 deletions maestro/tv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
appId: com.theomesnil.WhatToWatch
---
- launchApp
- tapOn: 'Search, tab, 2 of 3'
- tapOn: 'What would you like to watch?'
- inputText: 'House of the Dragon'
- doubleTapOn:
point: '19%,38%'
- waitForAnimationToEnd
- takeScreenshot: 'maestro/screenshots/tv/index'
- assertVisible: 'Watch on'
- tapOn: 'Watch the trailer'
- assertVisible:
id: 'video'
- takeScreenshot: 'maestro/screenshots/tv/trailer'
- tapOn:
id: 'header-close-button'
- scroll
- takeScreenshot: 'maestro/screenshots/tv/index-2'
- tapOn: 'S2'
- takeScreenshot: 'maestro/screenshots/tv/index-3'
- scroll
- scroll
- waitForAnimationToEnd
- takeScreenshot: 'maestro/screenshots/tv/index-4'
- tapOn: 'Matt Smith Prince Daemon Targaryen'
- takeScreenshot: 'maestro/screenshots/tv/casting'
- tapOn:
id: 'header-back-button'
- scroll
- takeScreenshot: 'maestro/screenshots/tv/index-5'
- tapOn: 'House of the Dragon Opening Credits 4K | Season 1 (HBO) | Game Of Thrones Extras'
- takeScreenshot: 'maestro/screenshots/tv/video'
- tapOn:
id: 'header-close-button'
- tapOn: 'Backdrops'
- swipe:
direction: LEFT
- takeScreenshot: 'maestro/screenshots/tv/backdrops'
- tapOn:
id: 'header-close-button'
- tapOn: 'Posters'
- swipe:
direction: LEFT
- takeScreenshot: 'maestro/screenshots/tv/posters'
- tapOn:
id: 'header-close-button'
8 changes: 8 additions & 0 deletions src/api/__mocks__/logo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { UseGetContentLogo } from 'api/logo';

export const MOCK_LOGO: UseGetContentLogo['data'] = {
url: 'url-logo.png',
aspectRatio: 245 / 234
};

export const MOCK_LOGO_EMPTY: UseGetContentLogo['data'] = null;
Loading

0 comments on commit 1a877e5

Please sign in to comment.