Fakultas Ilmu Komputer UI

Commit 6ef45e64 authored by Shafiya Adzhani's avatar Shafiya Adzhani
Browse files

[CHORES] improve test in stepper by using mock

parent ef4d5629
Pipeline #72592 failed with stages
in 4 minutes and 42 seconds
import {render, screen} from '@testing-library/react'
import Stepper from './Stepper'
import userEvent from '@testing-library/user-event'
test('renders Stepper Element', () => {
render(<Stepper />)
expect(screen.getByTestId('step-1')).toBeInTheDocument()
expect(screen.getByTestId('step-2')).toBeInTheDocument()
expect(screen.getByTestId('step-3')).toBeInTheDocument()
})
const handleSubmit = jest.fn()
const onSubmit = jest.fn()
const register = jest.fn()
const setValue = jest.fn()
test('can invoke handle submit, setvalue when click in step 1 white', () => {
render(
<Stepper
currentPage={1}
handleSubmit={handleSubmit}
onSubmit={onSubmit}
register={register}
setValue={setValue}
/>,
)
test('render Stepper Page 1', () => {
render(<Stepper currentPage={1} />)
expect(screen.getByTestId('step-1-white')).toBeInTheDocument()
expect(screen.getByTestId('step-2-gray')).toBeInTheDocument()
expect(screen.getByTestId('step-3-gray')).toBeInTheDocument()
userEvent.click(screen.getByTestId('step-1-white'))
expect(handleSubmit).toHaveBeenCalled()
expect(setValue).toHaveBeenCalled()
})
test('render Stepper Page 2', () => {
render(<Stepper currentPage={2} />)
expect(screen.getByTestId('step-1-blue')).toBeInTheDocument()
expect(screen.getByTestId('step-2-white')).toBeInTheDocument()
expect(screen.getByTestId('step-3-gray')).toBeInTheDocument()
test('can invoke handle submit, setvalue when click in step 2 white', () => {
render(
<Stepper
currentPage={2}
handleSubmit={handleSubmit}
onSubmit={onSubmit}
register={register}
setValue={setValue}
/>,
)
userEvent.click(screen.getByTestId('step-2-white'))
expect(handleSubmit).toHaveBeenCalled()
expect(setValue).toHaveBeenCalled()
})
test('render Stepper Page 3', () => {
render(<Stepper currentPage={3} />)
expect(screen.getByTestId('step-1-blue')).toBeInTheDocument()
expect(screen.getByTestId('step-2-blue')).toBeInTheDocument()
expect(screen.getByTestId('step-3-white')).toBeInTheDocument()
test('can invoke handle submit, setvalue when click in step 3 white', () => {
render(
<Stepper
currentPage={3}
handleSubmit={handleSubmit}
onSubmit={onSubmit}
register={register}
setValue={setValue}
/>,
)
userEvent.click(screen.getByTestId('step-3-white'))
expect(handleSubmit).toHaveBeenCalled()
expect(setValue).toHaveBeenCalled()
})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment