Skip to content

Commit

Permalink
automation test 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Quanmuito committed Jan 24, 2024
1 parent 8325051 commit 8a542a0
Showing 1 changed file with 50 additions and 35 deletions.
85 changes: 50 additions & 35 deletions src/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,63 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import App from '../App';

describe('Test render', () => {
test('Test heading', async () => {
render(<App />);
expect(await screen.findByText(/delivery fee calculator/i)).toBeInTheDocument();
test('Test render heading', async () => {
render(<App />);
expect(await screen.findByText(/delivery fee calculator/i)).toBeInTheDocument();

expect(await screen.findByLabelText(/number of items/i)).toBeInTheDocument();
expect(await screen.findByLabelText(/order time/i)).toBeInTheDocument();
expect(await screen.findByLabelText(/total delivery fee/i)).toBeInTheDocument();
});
expect(await screen.findByLabelText(/number of items/i)).toBeInTheDocument();
expect(await screen.findByLabelText(/order time/i)).toBeInTheDocument();
expect(await screen.findByLabelText(/total delivery fee/i)).toBeInTheDocument();
});

test('Test cart value input', async () => {
render(<App />);
let input = await screen.findByLabelText(/cart value/i);
let description = await screen.findByText(/value of the shopping cart in euros/i);
expect(input).toBeInTheDocument();
expect(description).toBeInTheDocument();
describe('Test cart value input', () => {
const cartValueCases: [string, number][] = [
['10', 10],
['200', 200],
['20.6', 20.6],
['40,6', 40.6],
];
test.each(cartValueCases)(
'Cart value is %p and display value should be %p',
async (input, expected) => {
render(<App />);
let cartValueInput = await screen.findByLabelText(/cart value/i);
expect(cartValueInput).toBeInTheDocument();

userEvent.type(input, '10');
expect(input).toHaveValue(10);
userEvent.type(cartValueInput, input);
expect(cartValueInput).toHaveValue(expected);
}
);
});

userEvent.type(input, '20,6');
expect(input).toHaveValue(20.60);
describe('Test user event on delivery distance input', () => {
const deliveryDistanceCases: [string, number][] = [
['500', 500],
['1000', 1000],
['1200', 1200],
['1499', 1499],
['1500', 1500],
['1501', 1501],
];
test.each(deliveryDistanceCases)(
'Delivery distance is %p and display value should be %p',
async (input, expected) => {
render(<App />);
let deliveryDistanceInput = await screen.findByLabelText(/delivery distance/i);
expect(deliveryDistanceInput).toBeInTheDocument();

userEvent.type(input, '200');
expect(input).toHaveValue(200);
});
userEvent.type(deliveryDistanceInput, input);
expect(deliveryDistanceInput).toHaveValue(expected);
}
);

test('Test delivery distance input', async () => {
test('Test input float instead of integer', async () => {
render(<App />);
let input = await screen.findByLabelText(/delivery distance/i);
let description = await screen.findByText(/the distance between the store and location of customer in meters/i);
expect(input).toBeInTheDocument();
expect(description).toBeInTheDocument();

userEvent.type(input, '1000');
expect(input).toHaveValue(1000);

userEvent.type(input, '1500');
expect(input).toHaveValue(1500);
let deliveryDistanceInput = await screen.findByLabelText(/delivery distance/i);
expect(deliveryDistanceInput).toBeInTheDocument();

userEvent.type(input, '1000.5');
let errorText = await screen.findByText(/invalid input error: please input an integer/i);
expect(errorText).toBeInTheDocument();
userEvent.type(deliveryDistanceInput, '1000.5');
let errorMessage = await screen.findByText(/invalid input. error: please input an integer/i);
expect(errorMessage).toBeInTheDocument();
});
});

0 comments on commit 8a542a0

Please sign in to comment.