Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add maestro and unit testing #108

Merged
merged 5 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions __tests__/Movie.test.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,60 @@
import Movie from 'app/movie/[id]';

import { MOCK_MOVIE } from 'api/__mocks__/movie';
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 { render, screen } from '../tests/render';
import { mockQuery, render, screen } from '../tests/render';

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

render(<Movie />);

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(MOCK_MOVIE as movie.UseMovie);
.mockReturnValue(mockQuery(MOCK_MOVIE_WITH_NETWORK));
jest.spyOn(logo, 'useGetContentLogo').mockReturnValue(mockQuery(MOCK_LOGO));

render(<Movie />);

const textLabel = screen.getByTestId('release-date');
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 />);

expect(textLabel).toHaveTextContent('June 20, 2024');
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/index2'
- 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/index3'
- 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/index4'
- tapOn: 'Action & Adventure Action & Adventure'
- tapOn:
id: 'header-back-button'
- scroll
- takeScreenshot: 'maestro/screenshots/discover/index5'
- 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/movie2'
- 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/tv2'
- tapOn:
point: '19%,26%'
- tapOn:
id: 'header-back-button'
- tapOn:
id: 'header-back-button'
7 changes: 0 additions & 7 deletions maestro/index.yml

This file was deleted.

40 changes: 37 additions & 3 deletions maestro/movie.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@ appId: com.theomesnil.WhatToWatch
---
- launchApp
- tapOn: 'Search, tab, 2 of 3'
- waitForAnimationToEnd:
timeout: 5000
- takeScreenshot: 'maestro/screenshots/Search'
- tapOn: 'What would you like to watch?'
- inputText: 'Harry potter philosopher'
- doubleTapOn: "Harry Potter and the Philosopher's Stone"
- waitForAnimationToEnd
- takeScreenshot: 'maestro/screenshots/movie/index'
- tapOn: 'Watch the trailer'
- assertVisible:
id: 'video'
- takeScreenshot: 'maestro/screenshots/movie/trailer'
- tapOn:
id: 'header-close-button'
- scroll
- takeScreenshot: 'maestro/screenshots/movie/index2'
- tapOn: 'Daniel Radcliffe Harry Potter'
- assertVisible: 'Daniel Radcliffe'
- tapOn:
id: 'header-back-button'
- tapOn: 'Official Trailer'
- takeScreenshot: 'maestro/screenshots/movie/video'
- tapOn:
id: 'header-close-button'
- scroll
- takeScreenshot: 'maestro/screenshots/movie/index3'
- tapOn: 'Backdrops'
- swipe:
direction: LEFT
- takeScreenshot: 'maestro/screenshots/movie/backdrops'
- tapOn:
id: 'header-close-button'
- tapOn: 'Posters'
- swipe:
direction: LEFT
- takeScreenshot: 'maestro/screenshots/movie/posters'
- tapOn:
id: 'header-close-button'
- tapOn:
id: 'header-back-button'
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/streaming2'
- 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/index2'
- 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/index2'
- 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 removed maestro/screenshots/Home.png
Binary file not shown.
Binary file removed maestro/screenshots/Search.png
Binary file not shown.
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/discover/index2.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/index3.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/index4.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/index5.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/movie2.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 added maestro/screenshots/genre/tv2.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/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 added 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 added maestro/screenshots/movie/index2.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/movie/index3.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/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 added 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 added 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.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/index2.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/network/streaming2.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/index2.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
Binary file added maestro/screenshots/person/pictures.png
Binary file added maestro/screenshots/person/series.png
Binary file added maestro/screenshots/search/end.png
Binary file added maestro/screenshots/search/index.png
Binary file added 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.png
Binary file added maestro/screenshots/tv/index2.png
Binary file added maestro/screenshots/tv/index3.png
Binary file added maestro/screenshots/tv/index4.png
Binary file added maestro/screenshots/tv/index5.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
Loading