Skip to content

Commit

Permalink
Hot fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnestoEsp committed Sep 27, 2022
1 parent 336805a commit 10d85bc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 37 deletions.
42 changes: 30 additions & 12 deletions __tests__/components/CheckBox.test.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,47 @@
import { fireEvent, render } from "@testing-library/react-native"
import React from "react"
import CheckBox from "../../src/components/CheckBox"
import { fireEvent, render } from '@testing-library/react-native'
import React from 'react'
import CheckBox from '../../src/components/CheckBox'

const mockedOpenModal = {
openModal: jest.fn(),
}
const mockedCheckBox = {
checkBox: jest.fn(),
}

it("Should renders correctly", () => {
const { getByText } = render(<CheckBox onPress={function (): void {
throw new Error("Function not implemented.")
}} status={"checked"} />)
it('Should renders correctly', () => {
const { getByText } = render(
<CheckBox
onPressText={function (): void {
throw new Error('Function not implemented.')
}}
status={'checked'}
onCheck={function (): void {
mockedCheckBox.checkBox()
}}
/>
)

const checkBoxText = getByText('Accept terms and conditions')

expect(checkBoxText).toBeTruthy()
})

it("Should open modal when checkbox label is clicked", () => {
const { getByText } = render(<CheckBox onPress={function (): void {
mockedOpenModal.openModal()
}} status={"checked"} />)
it('Should open modal when checkbox label is clicked', () => {
const { getByText } = render(
<CheckBox
onPressText={function (): void {
mockedOpenModal.openModal()
}}
status={'checked'}
onCheck={function (): void {
mockedCheckBox.checkBox()
}}
/>
)

const checkBoxText = getByText('Accept terms and conditions')
fireEvent.press(checkBoxText)

expect(mockedOpenModal.openModal).toHaveBeenCalled()
})

42 changes: 17 additions & 25 deletions __tests__/components/ConfirmationDialog.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { fireEvent, render } from "@testing-library/react-native"
import React from "react"

import ConfirmationDialog from "../../src/components/ConfirmationDialog"
import { fireEvent, render } from '@testing-library/react-native'
import React from 'react'

import ConfirmationDialog from '../../src/components/ConfirmationDialog'

jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper')

const mockedState = {
visible: true,
message: '',
cancelPress: jest.fn,
onPress: jest.fn
onPress: jest.fn,
}

const mockedNavigate = jest.fn()
Expand All @@ -36,49 +35,42 @@ jest.mock('react-native-paper', () => {
})

it('Should shows a dialog and cancel/continue buttons', () => {
const { getByText, getByRole, getByTestId } = render(<ConfirmationDialog
visible={true}
onPress={mockedState.onPress}
message={''}
cancelPress={mockedState.cancelPress} />
const { getByText, getByRole, getByTestId } = render(
<ConfirmationDialog
visible={true}
onPress={mockedState.onPress}
message={''}
cancelPress={mockedState.cancelPress}
/>
)

const dialog = getByText('Confirm transaction:')
const dialog = getByText('Confirm:')
const cancelButton = getByTestId('cancel')
const continueButton = getByTestId('continue')

expect(dialog).toBeTruthy()
expect(cancelButton).toBeTruthy()
expect(continueButton).toBeTruthy()

})

it('Should do nothing and navigate to dashboard screen', () => {
const { getByTestId } = render(<ConfirmationDialog
visible={true}
onPress={mockedNavigate}
message={""}
cancelPress={mockedNavigate} />
const { getByTestId } = render(
<ConfirmationDialog visible={true} onPress={mockedNavigate} message={''} cancelPress={mockedNavigate} />
)

const cancelButton = getByTestId('cancel')
fireEvent.press(cancelButton)

expect(mockedNavigate).toHaveBeenCalled()

})

it('Should execute transaction and navigate to dashboard screen', () => {
const { getByTestId } = render(<ConfirmationDialog
visible={true}
onPress={mockedNavigate}
message={''}
cancelPress={mockedNavigate} />)
const { getByTestId } = render(
<ConfirmationDialog visible={true} onPress={mockedNavigate} message={''} cancelPress={mockedNavigate} />
)

const continueButton = getByTestId('continue')
fireEvent.press(continueButton)

expect(mockedNavigate).toHaveBeenCalled()

})

0 comments on commit 10d85bc

Please sign in to comment.