Skip to content

Commit

Permalink
fix test 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Quanmuito committed Jan 27, 2024
1 parent db52dd0 commit 9b45b8d
Showing 1 changed file with 47 additions and 23 deletions.
70 changes: 47 additions & 23 deletions src/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { cleanup, render, screen } from '@testing-library/react';
import { act, cleanup, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import App from '../App';

Expand Down Expand Up @@ -35,9 +35,12 @@ describe('Test cart value input', () => {
const cartValueInput = await screen.findByLabelText(/cart value/i);
expect(cartValueInput).toBeInTheDocument();

userEvent.clear(cartValueInput);
userEvent.type(cartValueInput, input);
userEvent.keyboard('{Enter}');
act(() => {
userEvent.clear(cartValueInput);
userEvent.type(cartValueInput, input);
userEvent.keyboard('{Enter}');
});

expect(cartValueInput).toHaveValue(expected);
}
);
Expand All @@ -55,8 +58,10 @@ describe('Test cart value input', () => {
const cartValueInput = await screen.findByLabelText(/cart value/i);
expect(cartValueInput).toBeInTheDocument();

userEvent.clear(cartValueInput);
userEvent.type(cartValueInput, input);
act(() => {
userEvent.clear(cartValueInput);
userEvent.type(cartValueInput, input);
});

const tooltip = await screen.findByText(expected);
expect(tooltip).toBeInTheDocument();
Expand All @@ -73,9 +78,12 @@ describe('Test cart value input', () => {
const cartValueInput = await screen.findByLabelText(/cart value/i);
expect(cartValueInput).toBeInTheDocument();

userEvent.clear(cartValueInput);
userEvent.type(cartValueInput, input);
userEvent.keyboard('{Enter}');
act(() => {
userEvent.clear(cartValueInput);
userEvent.type(cartValueInput, input);
userEvent.keyboard('{Enter}');
});

const error = await screen.findByText(pattern);
expect(error).toBeInTheDocument();
}
Expand Down Expand Up @@ -104,8 +112,11 @@ describe('Test user event on delivery distance input', () => {
const deliveryDistanceInput = await screen.findByLabelText(/delivery distance/i);
expect(deliveryDistanceInput).toBeInTheDocument();

userEvent.clear(deliveryDistanceInput);
userEvent.type(deliveryDistanceInput, input);
act(() => {
userEvent.clear(deliveryDistanceInput);
userEvent.type(deliveryDistanceInput, input);
});

expect(deliveryDistanceInput).toHaveValue(expected);
}
);
Expand All @@ -125,8 +136,10 @@ describe('Test user event on delivery distance input', () => {
const deliveryDistanceInput = await screen.findByLabelText(/delivery distance/i);
expect(deliveryDistanceInput).toBeInTheDocument();

userEvent.clear(deliveryDistanceInput);
userEvent.type(deliveryDistanceInput, input);
act(() => {
userEvent.clear(deliveryDistanceInput);
userEvent.type(deliveryDistanceInput, input);
});

const tooltip = await screen.findByText(expected);
expect(tooltip).toBeInTheDocument();
Expand All @@ -142,9 +155,12 @@ describe('Test user event on delivery distance input', () => {
const deliveryDistanceInput = await screen.findByLabelText(/delivery distance/i);
expect(deliveryDistanceInput).toBeInTheDocument();

userEvent.clear(deliveryDistanceInput);
userEvent.type(deliveryDistanceInput, input);
userEvent.keyboard('{Enter}');
act(() => {
userEvent.clear(deliveryDistanceInput);
userEvent.type(deliveryDistanceInput, input);
userEvent.keyboard('{Enter}');
});

const error = await screen.findByText(pattern);
expect(error).toBeInTheDocument();
}
Expand Down Expand Up @@ -173,8 +189,11 @@ describe('Test user event on number of items input', () => {
const numberOfItemsInput = await screen.findByLabelText(/number of items/i);
expect(numberOfItemsInput).toBeInTheDocument();

userEvent.clear(numberOfItemsInput);
userEvent.type(numberOfItemsInput, input);
act(() => {
userEvent.clear(numberOfItemsInput);
userEvent.type(numberOfItemsInput, input);
});

expect(numberOfItemsInput).toHaveValue(expected);
}
);
Expand All @@ -195,8 +214,10 @@ describe('Test user event on number of items input', () => {
const numberOfItemsInput = await screen.findByLabelText(/number of items/i);
expect(numberOfItemsInput).toBeInTheDocument();

userEvent.clear(numberOfItemsInput);
userEvent.type(numberOfItemsInput, input);
act(() => {
userEvent.clear(numberOfItemsInput);
userEvent.type(numberOfItemsInput, input);
});

const tooltip = await screen.findByText(expected);
expect(tooltip).toBeInTheDocument();
Expand All @@ -212,9 +233,12 @@ describe('Test user event on number of items input', () => {
const numberOfItemsInput = await screen.findByLabelText(/number of items/i);
expect(numberOfItemsInput).toBeInTheDocument();

userEvent.clear(numberOfItemsInput);
userEvent.type(numberOfItemsInput, input);
userEvent.keyboard('{Enter}');
act(() => {
userEvent.clear(numberOfItemsInput);
userEvent.type(numberOfItemsInput, input);
userEvent.keyboard('{Enter}');
});

const error = await screen.findByText(pattern);
expect(error).toBeInTheDocument();
}
Expand Down

0 comments on commit 9b45b8d

Please sign in to comment.