generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#29 Se añaden tests unitarios a los componentes y pantallas, tambien …
…se añade el covarage de estos componentes
- Loading branch information
1 parent
29141c5
commit a8ba435
Showing
18 changed files
with
421 additions
and
54 deletions.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ import './App.scss'; | |
function App() { | ||
|
||
return ( | ||
<Content/> | ||
<Content data-testid='app-content'/> | ||
); | ||
} | ||
|
||
|
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,89 @@ | ||
import { screen, render, fireEvent, act } from "@testing-library/react" | ||
import Aside from "./Aside" | ||
import i18n from '../../translation/i18n'; | ||
import { MemoryRouter } from "react-router-dom"; | ||
|
||
describe('Header', () => { | ||
beforeAll(() => { | ||
i18n.changeLanguage('Spain'); | ||
}); | ||
|
||
test('Aside renders correctly', () => { | ||
render(<Aside elements={[]} username={"Alvaro"} />) | ||
|
||
const element = screen.getByTestId('syg-aside-container') | ||
expect(element).toBeInTheDocument(); | ||
}) | ||
|
||
test('Header components renders correctly', () => { | ||
render(<Aside elements={[]} username={"Alvaro"} />) | ||
|
||
const asideNavigationMenu = screen.getByTestId('syg-aside-navigation-menu') | ||
expect(asideNavigationMenu).toBeInTheDocument(); | ||
|
||
const asideMenu = screen.getByTestId('syg-aside-login-menu') | ||
expect(asideMenu).toBeInTheDocument(); | ||
|
||
const asideUsernameContent = screen.getByTestId('syg-aside-username') | ||
expect(asideUsernameContent).toBeInTheDocument(); | ||
|
||
const asideUsernameInitial = screen.getByTestId('syg-aside-username-initial') | ||
expect(asideUsernameInitial).toBeInTheDocument(); | ||
|
||
const asideUsername = screen.getByTestId('syg-aside-username-complete') | ||
expect(asideUsername).toBeInTheDocument(); | ||
|
||
const asideLogout = screen.getByTestId('syg-aside-logout') | ||
expect(asideLogout).toBeInTheDocument(); | ||
|
||
const asideLogoutText = screen.getByTestId('syg-aside-logout-text') | ||
expect(asideLogoutText).toBeInTheDocument(); | ||
}) | ||
|
||
test('Aside login user info text', () => { | ||
render(<Aside elements={[]} username={"Alvaro"} />) | ||
|
||
const asideUsernameInitial = screen.getByTestId('syg-aside-username-initial') | ||
expect(asideUsernameInitial).toHaveTextContent("A"); | ||
|
||
const asideUsername = screen.getByTestId('syg-aside-username-complete') | ||
expect(asideUsername).toHaveTextContent("Alvaro"); | ||
}) | ||
|
||
test('Aside logout user info text', () => { | ||
render(<Aside elements={[]} username={"Alvaro"} />) | ||
|
||
const asideLogoutText = screen.getByTestId('syg-aside-logout-text') | ||
expect(asideLogoutText).toHaveTextContent("LOGOUT"); | ||
}) | ||
|
||
test('Aside change component option', () => { | ||
const onClickAsideElementMockOption1 = jest.fn(); | ||
const onClickAsideElementMockOption2 = jest.fn(); | ||
|
||
render(<Aside elements={[ | ||
{ | ||
text:"Juego", | ||
icon: <></>, | ||
onClickAsideElement: onClickAsideElementMockOption1 | ||
}, | ||
{ | ||
text:"Historico", | ||
icon: <></>, | ||
onClickAsideElement: onClickAsideElementMockOption2 | ||
} | ||
]} username={"Alvaro"} />) | ||
|
||
const buttonOption2 = screen.getByText('HISTORICO'); | ||
|
||
fireEvent.click(buttonOption2); | ||
|
||
expect(onClickAsideElementMockOption2).toHaveBeenCalledTimes(1); | ||
|
||
const buttonOption1 = screen.getByText('JUEGO'); | ||
|
||
fireEvent.click(buttonOption1); | ||
|
||
expect(onClickAsideElementMockOption2).toHaveBeenCalledTimes(1); | ||
}) | ||
}) |
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,46 @@ | ||
import { screen, render, fireEvent } from "@testing-library/react" | ||
import UserInfoCard from "./UserInfoCard"; | ||
import i18n from '../../translation/i18n'; | ||
|
||
describe('UserInfoCard', () => { | ||
beforeAll(() => { | ||
i18n.changeLanguage('Spain'); | ||
}); | ||
|
||
test('UserInfoCard renders correctly', () => { | ||
render(<UserInfoCard title={"TotalGames"} info={"4"}/>) | ||
|
||
const element = screen.getByTestId('syg-historic-card-container') | ||
expect(element).toBeInTheDocument(); | ||
}) | ||
|
||
test('UserInfoCard components renders correctly', () => { | ||
render(<UserInfoCard title={"TotalGames"} info={"4"}/>) | ||
|
||
const historicHeaderCard = screen.getByTestId('syg-historic-card-header') | ||
expect(historicHeaderCard).toBeInTheDocument(); | ||
|
||
const historicCardHeaderContent = screen.getByTestId('syg-historic-card-header-content') | ||
expect(historicCardHeaderContent).toBeInTheDocument(); | ||
|
||
const historicCardHeaderTitle = screen.getByTestId('syg-historic-card-header-title') | ||
expect(historicCardHeaderTitle).toBeInTheDocument(); | ||
|
||
const historicCardContent = screen.getByTestId('syg-historic-card-content') | ||
expect(historicCardContent).toBeInTheDocument(); | ||
|
||
const historicCardContentInfo = screen.getByTestId('syg-historic-card-content-info') | ||
expect(historicCardContentInfo).toBeInTheDocument(); | ||
}) | ||
|
||
test('UserInfoCard header and content text', () => { | ||
render(<UserInfoCard title={"Juegos totales"} info={"4"}/>) | ||
|
||
const historicHeader = screen.getByTestId('syg-historic-card-header-title') | ||
expect(historicHeader).toHaveTextContent("Juegos totales"); | ||
|
||
const historicCardContent = screen.getByTestId('syg-historic-card-content-info') | ||
expect(historicCardContent).toHaveTextContent("4"); | ||
|
||
}) | ||
}) |
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,71 @@ | ||
import { screen, render, fireEvent } from "@testing-library/react" | ||
import Header from "./Header" | ||
import i18n from '../../translation/i18n'; | ||
|
||
describe('Header', () => { | ||
beforeAll(() => { | ||
i18n.changeLanguage('Spain'); | ||
}); | ||
|
||
test('Header renders correctly', () => { | ||
render(<Header info={"game"}/>) | ||
|
||
const element = screen.getByTestId('syg-header-container') | ||
expect(element).toBeInTheDocument(); | ||
}) | ||
|
||
test('Header components renders correctly', () => { | ||
render(<Header info={"historics"}/>) | ||
|
||
const headerContainer = screen.getByTestId('syg-header-logo-container') | ||
expect(headerContainer).toBeInTheDocument(); | ||
|
||
const headerLogo = screen.getByTestId('syg-header-logo') | ||
expect(headerLogo).toBeInTheDocument(); | ||
|
||
const headerLogoLetters = screen.getByTestId('syg-header-logo-letters') | ||
expect(headerLogoLetters).toBeInTheDocument(); | ||
|
||
const laguageSwitch = screen.getByTestId('syg-header-language-switch') | ||
expect(laguageSwitch).toBeInTheDocument(); | ||
|
||
const subHeaderText = screen.getByTestId('syg-header-info') | ||
expect(subHeaderText).toBeInTheDocument(); | ||
}) | ||
|
||
test('Header active language', () => { | ||
render(<Header info={"game"}/>) | ||
|
||
const languageActive = screen.getByTestId('syg-header-language-switch-element-active') | ||
expect(languageActive).toHaveTextContent('Español'); | ||
}) | ||
|
||
test('Header subtitle text', () => { | ||
render(<Header info={"ranking"}/>) | ||
|
||
const subHeader = screen.getByTestId('syg-header-info') | ||
expect(subHeader).toHaveTextContent('Ranking'); | ||
}) | ||
|
||
test('Header subtitle text in another language', () => { | ||
i18n.changeLanguage('English'); | ||
|
||
render(<Header info={"game"}/>) | ||
|
||
const subHeader = screen.getByTestId('syg-header-info') | ||
expect(subHeader).toHaveTextContent('Game'); | ||
}) | ||
|
||
test('Header button chagne language', () => { | ||
i18n.changeLanguage('Spain'); | ||
|
||
render(<Header info={"game"}/>) | ||
|
||
const button = screen.getByText('Ingles'); // Encuentra el botón que cambia el idioma | ||
|
||
fireEvent.click(button); | ||
|
||
const languageActive = screen.getByText('English'); | ||
expect(languageActive).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
Oops, something went wrong.