-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit testing and update the language selector (#49)
Signed-off-by: Vijay <[email protected]>
- Loading branch information
1 parent
358630f
commit c563e43
Showing
19 changed files
with
316 additions
and
46 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.
18 changes: 18 additions & 0 deletions
18
inji-web/src/__tests__/components/Common/EmptyListContainer.test.tsx
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 React,{act} from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import {EmptyListContainer} from "../../../components/Common/EmptyListContainer"; | ||
|
||
|
||
describe("Test Empty List Container",() => { | ||
test('check the presence of the container', () => { | ||
render(<EmptyListContainer content={"No Issuers Found"} />); | ||
const emptyElement = screen.getByTestId("EmptyList-Outer-Container"); | ||
expect(emptyElement).toBeInTheDocument(); | ||
}); | ||
test('check if content is rendered properly', () => { | ||
render(<EmptyListContainer content={"No Issuers Found"} />); | ||
const emptyElement = screen.getByTestId("EmptyList-Outer-Container"); | ||
expect(emptyElement).toHaveTextContent("No Issuers Found") | ||
}); | ||
}) | ||
|
19 changes: 19 additions & 0 deletions
19
inji-web/src/__tests__/components/Common/HeaderTile.test.tsx
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,19 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import {HeaderTile} from "../../../components/Common/HeaderTile"; | ||
|
||
|
||
|
||
describe("Test Header Tile Container",() => { | ||
test('check the presence of the container', () => { | ||
render(<HeaderTile content={"No Issuers Found"} />); | ||
const headerElement = screen.getByTestId("HeaderTile-Text"); | ||
expect(headerElement).toBeInTheDocument(); | ||
}); | ||
test('check if content is rendered properly', () => { | ||
render(<HeaderTile content={"No Issuers Found"} />); | ||
const headerElement = screen.getByTestId("HeaderTile-Text"); | ||
expect(headerElement).toHaveTextContent("No Issuers Found") | ||
}); | ||
}) | ||
|
37 changes: 37 additions & 0 deletions
37
inji-web/src/__tests__/components/Common/IntroBox.test.tsx
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 { render, screen } from '@testing-library/react'; | ||
import {IntroBox} from "../../../components/Common/IntroBox"; | ||
|
||
|
||
|
||
describe("Test Intro Box Layout",() => { | ||
test('check the presence of the container', () => { | ||
render(<IntroBox />); | ||
const introBoxElement = screen.getByTestId("IntroBox-Container"); | ||
expect(introBoxElement).toBeInTheDocument(); | ||
}); | ||
test('check the presence of the title', () => { | ||
render(<IntroBox />); | ||
const introBoxElement = screen.getByTestId("IntroBox-Text"); | ||
expect(introBoxElement).toBeInTheDocument(); | ||
}); | ||
test('check the presence of the subTitle', () => { | ||
render(<IntroBox />); | ||
const introBoxElement = screen.getByTestId("IntroBox-SubText"); | ||
expect(introBoxElement).toBeInTheDocument(); | ||
}); | ||
}) | ||
|
||
|
||
describe("Test Intro Box Content",() => { | ||
test('check if content is rendered properly', () => { | ||
render(<IntroBox />); | ||
const headerElement = screen.getByTestId("IntroBox-Text"); | ||
expect(headerElement).toHaveTextContent("Intro.title") | ||
}); | ||
test('check if content is rendered properly', () => { | ||
render(<IntroBox />); | ||
const headerElement = screen.getByTestId("IntroBox-SubText"); | ||
expect(headerElement).toHaveTextContent("Intro.subTitle") | ||
}); | ||
}) |
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,26 @@ | ||
import React from 'react'; | ||
import {fireEvent, render, screen} from '@testing-library/react'; | ||
import {ItemBox} from "../../../components/Common/ItemBox"; | ||
describe("Test Item Box Container",() => { | ||
test('check the presence of the container', () => { | ||
const clickHandler = jest.fn(); | ||
render(<ItemBox index={1} url={"/"} title={"TitleOfItemBox"} onClick={clickHandler} />); | ||
const itemBoxElement = screen.getByTestId("ItemBox-Outer-Container"); | ||
expect(itemBoxElement).toBeInTheDocument(); | ||
}); | ||
test('check if content is rendered properly', () => { | ||
const clickHandler = jest.fn(); | ||
render(<ItemBox index={1} url={"/"} title={"TitleOfItemBox"} onClick={clickHandler} />); | ||
const itemBoxElement = screen.getByTestId("ItemBox-Outer-Container"); | ||
expect(itemBoxElement).toHaveTextContent("TitleOfItemBox") | ||
}); | ||
|
||
test('check if item box onClick handler is working', () => { | ||
const clickHandler = jest.fn(); | ||
render(<ItemBox index={1} url={"/"} title={"TitleOfItemBox"} onClick={clickHandler} />); | ||
const itemBoxElement = screen.getByTestId("ItemBox-Outer-Container"); | ||
fireEvent.click(itemBoxElement); | ||
expect(clickHandler).toBeCalled() | ||
}); | ||
}) | ||
|
14 changes: 14 additions & 0 deletions
14
inji-web/src/__tests__/components/Common/SpinningLoader.test.tsx
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,14 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import {SpinningLoader} from "../../../components/Common/SpinningLoader"; | ||
|
||
|
||
|
||
describe("Test Spinning Loader Container",() => { | ||
test('check the presence of the container', () => { | ||
render(<SpinningLoader />); | ||
const spinningElement = screen.getByTestId("SpinningLoader-Container"); | ||
expect(spinningElement).toBeInTheDocument(); | ||
}); | ||
}) | ||
|
45 changes: 45 additions & 0 deletions
45
inji-web/src/__tests__/components/Credentials/Credentials.test.tsx
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,45 @@ | ||
import React from 'react'; | ||
import {fireEvent, render, screen} from '@testing-library/react'; | ||
import {Credential} from "../../../components/Credentials/Crendential"; | ||
import {CredentialWellknownObject, DisplayArrayObject, LogoObject} from "../../../types/data"; | ||
import {Provider} from "react-redux"; | ||
|
||
const getCredentialObject = (): CredentialWellknownObject => { | ||
return { | ||
format: "ldp_vc", | ||
id: "id", | ||
scope: "mosip_ldp_vc", | ||
display: { | ||
name: "Name", | ||
language: "en", | ||
locale: "en", | ||
logo: { | ||
url: "https://url.com", | ||
alt_text: "alt text of the url" | ||
}, | ||
title: "Title", | ||
description: "Description", | ||
} | ||
} | ||
} | ||
describe("Test Credentials Item Layout",() => { | ||
test.skip('check the presence of the container', () => { | ||
const clickHandler = jest.fn(); | ||
const credential:CredentialWellknownObject = getCredentialObject(); | ||
render( | ||
<Provider store={{credentials: credential}}> | ||
<Credential credential={credential} index={1} /> | ||
</Provider> | ||
); | ||
const itemBoxElement = screen.getByTestId("ItemBox-Outer-Container"); | ||
expect(itemBoxElement).toBeInTheDocument(); | ||
}); | ||
test.skip('check if content is rendered properly', () => { | ||
const clickHandler = jest.fn(); | ||
const credential:CredentialWellknownObject = getCredentialObject(); | ||
render(<Credential credential={credential} index={1} />); | ||
const itemBoxElement = screen.getByTestId("ItemBox-Outer-Container"); | ||
expect(itemBoxElement).toHaveTextContent("TitleOfItemBox") | ||
}); | ||
}) | ||
|
49 changes: 49 additions & 0 deletions
49
inji-web/src/__tests__/components/Help/HelpAccordion.test.tsx
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,49 @@ | ||
import React from 'react'; | ||
import {fireEvent, render, screen} from '@testing-library/react'; | ||
import {HelpAccordion} from "../../../components/Help/HelpAccordion"; | ||
|
||
describe("Test Help Accordion Container",() => { | ||
test('check the presence of the container', () => { | ||
render(<HelpAccordion />); | ||
const helpElement = screen.getByTestId("Help-Accordion-Container"); | ||
expect(helpElement).toBeInTheDocument(); | ||
}); | ||
|
||
test('check the presence of the container', () => { | ||
render(<HelpAccordion />); | ||
const helpItemElement = screen.getAllByTestId("Help-Item-Container"); | ||
expect(helpItemElement.length).toBe(7) | ||
}); | ||
test('check first item should be expanded', () => { | ||
render(<HelpAccordion />); | ||
const helpItemElement = screen.getAllByTestId("Help-Item-Title-Text"); | ||
expect(helpItemElement.length).toBe(7) | ||
}); | ||
test('check first item should be expanded', () => { | ||
render(<HelpAccordion />); | ||
const helpItemElement = screen.getAllByTestId("Help-Item-Content-Text"); | ||
expect(helpItemElement.length).toBe(1) | ||
}); | ||
}) | ||
|
||
describe("Test Help Accordion Working",() => { | ||
test('The Description should open when we press on the title', () => { | ||
render(<HelpAccordion />); | ||
const helpItemElement = screen.getAllByTestId("Help-Item-Container")[1]; | ||
const button = screen.getAllByTestId("Help-Item-Title-Button")[1]; | ||
expect(helpItemElement.childElementCount).toBe(1) | ||
fireEvent.click(button); | ||
expect(helpItemElement.childElementCount).toBe(2) | ||
}); | ||
|
||
test('only one description should be open at a time, rest should close', () => { | ||
render(<HelpAccordion />); | ||
const helpItemElement = screen.getAllByTestId("Help-Item-Container")[1]; | ||
const button = screen.getAllByTestId("Help-Item-Title-Button")[1]; | ||
expect(helpItemElement.childElementCount).toBe(1) | ||
fireEvent.click(button); | ||
expect(helpItemElement.childElementCount).toBe(2) | ||
const overallDescElemet = screen.getAllByTestId("Help-Item-Content-Text"); | ||
expect(overallDescElemet.length).toBe(1) | ||
}); | ||
}) |
35 changes: 35 additions & 0 deletions
35
inji-web/src/__tests__/components/Help/HelpAccordionItem.test.tsx
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,35 @@ | ||
import React from 'react'; | ||
import {fireEvent, render, screen} from '@testing-library/react'; | ||
import {HelpAccordionItem} from "../../../components/Help/HelpAccordionItem"; | ||
|
||
describe("Test Help Accordion Container",() => { | ||
test('check the presence of the container', () => { | ||
const openHandler = jest.fn(); | ||
render(<HelpAccordionItem id={1} title={"HelpTitle"} content={["HelpContent"]} open={1} setOpen={openHandler} />); | ||
const helpElement = screen.getByTestId("Help-Item-Container"); | ||
expect(helpElement).toBeInTheDocument(); | ||
}); | ||
|
||
test('if current help item is not open, it should not show description', () => { | ||
const openHandler = jest.fn(); | ||
render(<HelpAccordionItem id={1} title={"HelpTitle"} content={["HelpContent"]} open={0} setOpen={openHandler} />); | ||
const helpElement = screen.getByTestId("Help-Item-Container"); | ||
expect(helpElement.childElementCount).toBe(1); | ||
}); | ||
test('if current help item is open, it should show description', () => { | ||
const openHandler = jest.fn(); | ||
render(<HelpAccordionItem id={1} title={"HelpTitle"} content={["HelpContent"]} open={1} setOpen={openHandler} />); | ||
const helpElement = screen.getByTestId("Help-Item-Container"); | ||
expect(helpElement.childElementCount).toBe(2); | ||
}); | ||
|
||
test('if current help item is open, it should show description', () => { | ||
const openHandler = jest.fn(); | ||
render(<HelpAccordionItem id={1} title={"HelpTitle"} content={["HelpContent"]} open={0} setOpen={openHandler} />); | ||
const helpElement = screen.getByTestId("Help-Item-Container"); | ||
expect(helpElement.childElementCount).toBe(1); | ||
const buttonElement = screen.getByTestId("Help-Item-Title-Button"); | ||
fireEvent.click(buttonElement); | ||
expect(openHandler).toHaveBeenCalled(); | ||
}); | ||
}) |
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,14 @@ | ||
export const mockUseTranslation = () => { | ||
return jest.mock('react-i18next', () => ({ | ||
useTranslation: () => ({ | ||
t: (key:string) => key, | ||
}), | ||
})); | ||
} | ||
|
||
export const mockUseNavigate = () => { | ||
return jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useNavigate: jest.fn(), | ||
})); | ||
} |
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
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.