Skip to content

Commit

Permalink
try to fix with-registration test
Browse files Browse the repository at this point in the history
  • Loading branch information
raiyaj committed Feb 15, 2023
1 parent 4f3dd08 commit 614549f
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ beforeEach(() => {

afterEach(() => {
jest.resetModules()
sessionStorage.clear()
})

test('should execute onClick for registered users', async () => {
const onClick = jest.fn()

renderWithProviders(<MockedComponent onClick={onClick} />)
await renderWithProviders(<MockedComponent onClick={onClick} />)

await waitFor(() => {
// we wait for login to complete and user's firstName to show up on screen.
Expand All @@ -65,24 +65,30 @@ test('should execute onClick for registered users', async () => {
const trigger = screen.getByText(/button/i)
user.click(trigger)

expect(onClick).toHaveBeenCalledTimes(1)
await waitFor(() => {
expect(onClick).toHaveBeenCalledTimes(1)
})
})

test('should show login modal if user not registered', () => {
test('should show login modal if user not registered', async () => {
global.server.use(
rest.get('*/customers/:customerId', (req, res, ctx) => {
return res(ctx.delay(0), ctx.status(200), ctx.json(mockedGuestCustomer))
})
)
const onClick = jest.fn()
await renderWithProviders(<MockedComponent onClick={onClick} />)

renderWithProviders(<MockedComponent onClick={onClick} />)

const trigger = screen.getByText(/button/i)
user.click(trigger)
let trigger
await waitFor(() => {
trigger = screen.getByText(/button/i)
})

expect(screen.getByLabelText(/email/i)).toBeInTheDocument()
expect(screen.getByLabelText(/Password/)).toBeInTheDocument()
expect(screen.getByText(/forgot password/i)).toBeInTheDocument()
expect(screen.getByText(/sign in/i)).toBeInTheDocument()
await waitFor(() => {
user.click(trigger)
expect(screen.getByLabelText(/email/i)).toBeInTheDocument()
expect(screen.getByLabelText(/Password/)).toBeInTheDocument()
expect(screen.getByText(/forgot password/i)).toBeInTheDocument()
expect(screen.getByText(/sign in/i)).toBeInTheDocument()
})
})

0 comments on commit 614549f

Please sign in to comment.