-
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.
Merge pull request #44 from expfig/test/12-ComponentTable
test ✅ teste para o componente (Table) para ter cert…
- Loading branch information
Showing
10 changed files
with
265 additions
and
21 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 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,56 @@ | ||
/** | ||
* IMPORTS | ||
*/ | ||
|
||
interface IDataPagesProps { | ||
url: string; | ||
label: string; | ||
active: boolean; | ||
} | ||
|
||
const pages: IDataPagesProps[] = [ | ||
{ | ||
url: "http://localhost.com.br", | ||
active: true, | ||
label: "1", | ||
}, | ||
{ | ||
url: "http://localhost.com.br", | ||
active: false, | ||
label: "2", | ||
}, | ||
]; | ||
|
||
interface IApprovalRequest { | ||
id: string | number; | ||
status: string; | ||
coil_number: string; | ||
trip_number: string; | ||
type: string; | ||
driver_id: number; | ||
driver_name: string; | ||
placa: string; | ||
group_name: string; | ||
created_at: string; | ||
created_at_formatted: string; | ||
} | ||
const dataTable: IApprovalRequest[] = [ | ||
{ | ||
id: 374822, | ||
coil_number: "23370945C", | ||
status: "aguardando", | ||
trip_number: "367217", | ||
type: "bobina", | ||
driver_id: 77, | ||
driver_name: "MARCOS RODRIGO ALMEIDA", | ||
placa: "RNG7A17", | ||
group_name: "Isauro Neto(B)", | ||
created_at: "2023-07-16 16:06:18", | ||
created_at_formatted: "16/07/2023 16:06", | ||
}, | ||
]; | ||
|
||
/** | ||
* EXPORT | ||
*/ | ||
export { type IApprovalRequest, type IDataPagesProps, dataTable, pages }; |
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,6 @@ | ||
# TESTE DO COMPONENTE TABLE | ||
|
||
1 -> Deve ser possível renderizar o componente de table | ||
2 -> Deve ser possível renderizar o icone-svg-oval e o texto (Carregando, por favor, aguarde.) | ||
3 -> Deve ser possível renderizar o titulo da tabela corretamente sendo eles (ID, Data de criação, Status, Viagem, Bobina, Motorista, Placa, Grupo, Tipo) | ||
4 -> Deve ser possivel chama a função onClickNext e onClickPreview pelo menos uma vez |
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,149 @@ | ||
/** | ||
* IMPORTS | ||
*/ | ||
import React from "react"; | ||
import { ThemeProvider } from "styled-components"; | ||
import { BrowserRouter } from "react-router-dom"; | ||
|
||
import { render } from "@testing-library/react"; | ||
import userfireEvent from "@testing-library/user-event"; | ||
|
||
import theme from "../../../global/styles/theme"; | ||
|
||
// components | ||
import { Table } from "../table"; | ||
|
||
// mock-data | ||
import { pages, dataTable } from "../__mock-data__/mock-table"; | ||
|
||
const Providers: React.FC = ({ children }: any) => { | ||
return <ThemeProvider theme={theme}>{children}</ThemeProvider>; | ||
}; | ||
|
||
describe("Table test of components", () => { | ||
it("should render o table component", () => { | ||
render( | ||
<Table | ||
data={[]} | ||
pages={[]} | ||
firstPage={1} | ||
lastPage={2} | ||
isLoading={false} | ||
onClickNext={(pageCount: number) => { | ||
return pageCount; | ||
}} | ||
onClickPreview={(pageCount: number) => {}} | ||
/>, | ||
{ | ||
wrapper: Providers, | ||
} | ||
); | ||
}); | ||
|
||
it("should be possible to view the icon and the loading text when the isLoading property is set to false", () => { | ||
const { getByTestId, getByText } = render( | ||
<Table | ||
data={[]} | ||
pages={[]} | ||
firstPage={1} | ||
lastPage={2} | ||
isLoading={true} | ||
onClickNext={(pageCount: number) => { | ||
return pageCount; | ||
}} | ||
onClickPreview={(pageCount: number) => {}} | ||
/>, | ||
{ | ||
wrapper: Providers, | ||
} | ||
); | ||
|
||
const elementIconSvgOval = getByTestId("oval-loading"); | ||
const textLoadingPleaseWait = getByText("Carregando, por favor, aguarde."); | ||
|
||
expect(elementIconSvgOval).toBeTruthy(); | ||
|
||
expect(textLoadingPleaseWait.textContent).toBe( | ||
"Carregando, por favor, aguarde." | ||
); | ||
}); | ||
|
||
it("should be possible to render the title of the table correctly being them (ID, Date created, Status, Trip, Coil, Driver, Plate, Group, Type)", () => { | ||
const { getByText } = render( | ||
<BrowserRouter> | ||
<Table | ||
data={dataTable} | ||
pages={pages} | ||
firstPage={1} | ||
lastPage={2} | ||
isLoading={false} | ||
onClickNext={(pageCount: number) => { | ||
return pageCount; | ||
}} | ||
onClickPreview={(pageCount: number) => {}} | ||
/> | ||
</BrowserRouter>, | ||
{ | ||
wrapper: Providers, | ||
} | ||
); | ||
|
||
const ElementTitleID = getByText("ID"); | ||
const ElementTitleCreatedAt = getByText("Data de criação"); | ||
const ElementTitleStatus = getByText("Status"); | ||
const ElementTitleTrip = getByText("Viagem"); | ||
const ElementTitleCoil = getByText("Bobina"); | ||
const ElementTitleDriver = getByText("Motorista"); | ||
const ElementTitleGroup = getByText("Grupo"); | ||
const ElementTitleType = getByText("Tipo"); | ||
|
||
expect(ElementTitleID.textContent).toBe("ID"); | ||
expect(ElementTitleCreatedAt.textContent).toBe("Data de criação"); | ||
expect(ElementTitleStatus.textContent).toBe("Status"); | ||
expect(ElementTitleTrip.textContent).toBe("Viagem"); | ||
expect(ElementTitleCoil.textContent).toBe("Bobina"); | ||
expect(ElementTitleDriver.textContent).toBe("Motorista"); | ||
expect(ElementTitleGroup.textContent).toBe("Grupo"); | ||
expect(ElementTitleType.textContent).toBe("Tipo"); | ||
}); | ||
|
||
it("must be possible to call the onClickNext function at least once", async () => { | ||
const handleMockOnclickNext = jest.fn(); | ||
const handleMockOnclickPreview = jest.fn(); | ||
|
||
const { getByTestId } = render( | ||
<BrowserRouter> | ||
<Table | ||
data={dataTable} | ||
pages={pages} | ||
firstPage={1} | ||
lastPage={2} | ||
isLoading={false} | ||
onClickNext={(pageCount: number) => { | ||
handleMockOnclickNext(); | ||
return pageCount; | ||
}} | ||
onClickPreview={(pageCount: number) => { | ||
handleMockOnclickPreview(); | ||
}} | ||
/> | ||
</BrowserRouter>, | ||
{ | ||
wrapper: Providers, | ||
} | ||
); | ||
|
||
const elementButtonClickNext = getByTestId("button-clickNext"); | ||
const elementButtonClickPreview = getByTestId("button-clickPreview"); | ||
|
||
await userfireEvent.setup().click(elementButtonClickNext); | ||
|
||
await userfireEvent.setup().click(elementButtonClickPreview); | ||
|
||
// espero que uma função fictícia seja chamada. | ||
expect(handleMockOnclickNext).toHaveBeenCalledTimes(1); | ||
|
||
// espero que uma função fictícia seja chamada. | ||
expect(handleMockOnclickPreview).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
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.