forked from villacoder/react-certification-2021
-
Notifications
You must be signed in to change notification settings - Fork 95
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
minichallenge4 solved #85
Open
oscarfiend
wants to merge
3
commits into
cvillanueva84:master
Choose a base branch
from
oscarfiend:Minichallenge4-solved
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {render,screen} from '@testing-library/react' | ||
import React from 'react'; | ||
import ThemeState from '../context/theme/themeState'; | ||
import VideoState from '../context/video/VideoState'; | ||
import Header from '../components/Header' | ||
|
||
describe('Header component tests',()=>{ | ||
|
||
beforeEach(() => { | ||
render(<VideoState><ThemeState><Header/></ThemeState></VideoState>) | ||
}); | ||
|
||
test('should containt a toggle button',()=>{ | ||
const toggle=screen.getByRole('checkbox') | ||
expect(toggle).toBeInTheDocument() | ||
}) | ||
|
||
test('Toggle button should be checkbox type',()=>{ | ||
const toggle=screen.getByRole('checkbox') | ||
expect(toggle).toHaveAttribute('type', 'checkbox') | ||
}) | ||
|
||
test('Toggle button should containt a label',()=>{ | ||
const toggle=screen.queryByLabelText(/Light Mode/i) | ||
expect(toggle).toBeInTheDocument() | ||
}) | ||
|
||
test('should containt a login component',()=>{ | ||
const login=screen.getByTestId(/avatar_login/i) | ||
expect(login).toBeInTheDocument() | ||
}) | ||
|
||
test('should containt a search form',()=>{ | ||
const search=screen.getByTestId(/search_form/i) | ||
expect(search).toBeInTheDocument() | ||
}) | ||
|
||
test('search field should be disabled',()=>{ | ||
const search=screen.getByTestId(/search_field/i) | ||
expect(search).not.toHaveAttribute('disabled') | ||
}) | ||
|
||
test('should containt a hamburguer menu',()=>{ | ||
const menu=screen.getByTestId(/hamburguerMenu/i) | ||
expect(menu).toBeInTheDocument() | ||
}) | ||
|
||
test('menu should be type checkbox',()=>{ | ||
const menu=screen.getByTestId(/hamburguerMenu/i) | ||
expect(menu).toHaveAttribute('type', 'checkbox') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import ThemeState from '../context/theme/themeState'; | ||
import VideoState from '../context/video/videoState'; | ||
|
||
|
||
import Home from '../pages/Home'; | ||
|
||
describe('Home view tests', () => { | ||
beforeEach(() => { | ||
render(<VideoState><ThemeState><Home/></ThemeState></VideoState>) | ||
}); | ||
|
||
test('should containt specific title', () => { | ||
const title = screen.getByText(/Youtube challenge/i) | ||
expect(title).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import useVideoApi from '../hooks/useVideoApi'; | ||
import { renderHook, act } from '@testing-library/react-hooks'; | ||
|
||
describe('UseVideoApi tests', () => { | ||
test('shouldn´t return any videos', async () => { | ||
const { result } = renderHook(() => useVideoApi()); | ||
const { data, loading, error } = result.current; | ||
expect(data).toBe(null); | ||
expect(error).toBe(null); | ||
expect(loading).toBe(false); | ||
}); | ||
|
||
test('should return a video array', async () => { | ||
const params = { q: 'wizeline' }; | ||
const { result, waitForNextUpdate } = renderHook(() => useVideoApi()); | ||
const { fetchVideos } = result.current; | ||
await act(async() => fetchVideos({ params })); | ||
waitForNextUpdate(); | ||
const { data,error,loading } = result.current; | ||
expect(data.items.length).toBe(24); | ||
expect(error).toBe(null); | ||
expect(loading).toBe(false); | ||
}); | ||
|
||
test('should return a video array with the related videos', async () => { | ||
const params = { relatedToVideoId: "lWQ69WX7-hA", type: 'video' }; | ||
const { result, waitForNextUpdate } = renderHook(() => useVideoApi()); | ||
const { fetchVideos } = result.current; | ||
await act(async() => fetchVideos({ params })); | ||
waitForNextUpdate(); | ||
const { data,error,loading } = result.current; | ||
expect(data.items.length).toBe(24); | ||
expect(error).toBe(null); | ||
expect(loading).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import VideoCard from '../components/VideoCard'; | ||
import ThemeState from '../context/theme/themeState'; | ||
import VideoState from '../context/video/videoState'; | ||
|
||
describe('VideoCard component tests', () => { | ||
const video = { | ||
url: 'https://i.ytimg.com/vi/nmXMgqjQzls/mqdefault.jpg', | ||
title: 'Video Tour | Welcome to Wizeline Guadalajara', | ||
description: | ||
'Follow Hector Padilla, Wizeline Director of Engineering, for a lively tour of our office. In 2018, Wizeline opened its stunning new office in Guadalajara, Jalisco, ...', | ||
publishedAt: '2014-09-27', | ||
}; | ||
beforeEach(() => { | ||
render( | ||
<VideoState> | ||
<ThemeState> | ||
<VideoCard | ||
image={video.url} | ||
title={video.title} | ||
description={video.description} | ||
createdAt={video.publishedAt} | ||
/> | ||
</ThemeState> | ||
</VideoState> | ||
); | ||
}); | ||
|
||
test('should containt a card container', () => { | ||
const card = screen.getByTestId(/card_container/i); | ||
expect(card).toBeInTheDocument(); | ||
}); | ||
|
||
test('should containt a header image', () => { | ||
const cardImage = screen.getByTestId(/img_header/i); | ||
expect(cardImage.src).toBe(video.url); | ||
}); | ||
|
||
test('should containt a card title', () => { | ||
const cardTitle = screen.queryByText(video.title); | ||
expect(cardTitle).toBeInTheDocument(); | ||
}); | ||
|
||
test('should containt a card description', () => { | ||
const cardDescription = screen.queryByText(video.description); | ||
expect(cardDescription).toBeInTheDocument(); | ||
}); | ||
|
||
test('should containt a video creation date', () => { | ||
const videoCreation = screen.queryByText(video.publishedAt); | ||
expect(videoCreation).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { render, screen,waitFor } from '@testing-library/react'; | ||
import React from 'react'; | ||
import ThemeState from '../context/theme/themeState'; | ||
import VideoState from '../context/video/videoState'; | ||
import VideoDetails from '../pages/Details'; | ||
import {createMemoryHistory} from 'history' | ||
import {Router} from 'react-router-dom' | ||
|
||
describe('Details view tests', () => { | ||
beforeEach(() => { | ||
const history = createMemoryHistory() | ||
const videoId="lWQ69WX7-hA" | ||
history.push(`/video/${videoId}`) | ||
render( | ||
<Router history={history}> | ||
<VideoState> | ||
<ThemeState> | ||
<VideoDetails /> | ||
</ThemeState> | ||
</VideoState> | ||
</Router> | ||
); | ||
}); | ||
|
||
test('should containt a main container', () => { | ||
const container = screen.getByTestId(/container-details/i); | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
|
||
test('should containt a video description', () => { | ||
// const titleVideo = screen.findByText(/una librería para crear interfaces web/i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remember to remove commented code |
||
waitFor(()=>expect(screen.findByText(/una librería para crear interfaces web/i)).toBeInTheDocument()); | ||
}); | ||
|
||
test('should containt a video title', () => { | ||
// const titleVideo = screen.findByText(/una librería para crear interfaces web/i); | ||
waitFor(()=>expect(screen.findByText(/Qué es React/i)).toBeInTheDocument()); | ||
}); | ||
|
||
test('should containt a video iframe', () => { | ||
// const titleVideo = screen.findByText(/una librería para crear interfaces web/i); | ||
waitFor(()=>expect(screen.findByRole(/iframe/i)).toBeInTheDocument()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { render, screen} from '@testing-library/react'; | ||
import React from 'react'; | ||
import VideoList from '../components/VideoList'; | ||
import ThemeState from '../context/theme/themeState'; | ||
import VideoState from '../context/video/videoState'; | ||
|
||
describe('VideoList component tests', () => { | ||
beforeEach(() => { | ||
render(<VideoState><ThemeState><VideoList/></ThemeState></VideoState>) | ||
}); | ||
|
||
test('should containt a list container', () => { | ||
const list = screen.getByTestId(/container_videos/i); | ||
expect(list).toBeInTheDocument(); | ||
}); | ||
|
||
|
||
test('shouldn´t containt a card video list', () => { | ||
const list = screen.queryAllByTestId(/list_videos/i); | ||
expect(list.length).toBe(0); | ||
}); | ||
|
||
test('should containt a card video list',async () => { | ||
const list = screen.findAllByTestId(/list_videos/i); | ||
expect((await list).length).toBe(24) | ||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This are good test cases, but remember to mock the api call.https://jestjs.io/docs/mock-functions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should remove the next files for this config:
They are part of the current app, so they should be included on the code coverage testing.
Please remove and update the code coverage report.
Any question or comment let me know.