Skip to content

Commit

Permalink
AddressForm test
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaslh01 committed May 2, 2022
1 parent 03315fd commit e898980
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
29 changes: 29 additions & 0 deletions webapp/src/components/user/AddressForm.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { screen, render, queryByText, waitForElementToBeRemoved } from "@testing-library/react";

import AddressForm from './AddressForm';

import userEvent from "@testing-library/user-event";

import { ReactNotifications } from "react-notifications-component";
/**
* Chek that the CheckoutItem component is working as expected with a product.
*/


test('Check alert is shown when an address field is missing', async () => {

render(<div><ReactNotifications/><div><AddressForm/></div></div>);
expect(screen.getByTestId("street-input")).toBeInTheDocument();
expect(screen.getByTestId("locality-input")).toBeInTheDocument();
expect(screen.getByTestId("zipcode-input")).toBeInTheDocument();
expect(screen.getByTestId("country-input")).toBeInTheDocument();
expect(screen.getByText("Example: Valdés Salas.")).toBeInTheDocument();
expect(screen.getByText("Example: Oviedo.")).toBeInTheDocument();
expect(screen.getByText("Example: 33007.")).toBeInTheDocument();
expect(screen.getByText("Example: Spain.")).toBeInTheDocument();
expect(screen.getByText('Set Address')).toBeInTheDocument();
userEvent.click(screen.getByText('Set Address'));
expect(screen.getByText('Attention!')).toBeInTheDocument();
expect(screen.getByText('Please, fill all form fields.')).toBeInTheDocument();

})
10 changes: 5 additions & 5 deletions webapp/src/components/user/AddressForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,19 @@ export default function AddressForm() {
<Typography id="addressTitle" variant='h4'>Create / Update DedEx Address</Typography>
<br></br>
<form id="myform">
<TextField sx={{ width: '85%' }} label="Street" id="Street" aria-describedby="Street-helper-text" required={true} />
<TextField data-testid="street-input" sx={{ width: '85%' }} label="Street" id="Street" aria-describedby="Street-helper-text" required={true} />
<FormHelperText id="Street-helper-text">Example: Valdés Salas.</FormHelperText>
<br></br>
<TextField sx={{ width: '85%' }} label="City" id="City" aria-describedby="City-helper-text" required={true} />
<TextField data-testid="city-input" sx={{ width: '85%' }} label="City" id="City" aria-describedby="City-helper-text" required={true} />
<FormHelperText id="City-helper-text">Example: Oviedo.</FormHelperText>
<br></br>
<TextField sx={{ width: '85%' }} label="Locality" id="Locality" aria-describedby="Locality-helper-text" required={true} />
<TextField data-testid="locality-input" sx={{ width: '85%' }} label="Locality" id="Locality" aria-describedby="Locality-helper-text" required={true} />
<FormHelperText id="Locality-helper-text">Example: Asturias.</FormHelperText>
<br></br>
<TextField sx={{ width: '85%' }} label="ZIP Code" id="ZIPCode" aria-describedby="ZIPCode-helper-text" required={true} />
<TextField data-testid="zipcode-input" sx={{ width: '85%' }} label="ZIP Code" id="ZIPCode" aria-describedby="ZIPCode-helper-text" required={true} />
<FormHelperText id="ZIPCode-helper-text">Example: 33007.</FormHelperText>
<br></br>
<TextField sx={{ width: '85%' }} label="Country" id="Country" aria-describedby="Country-helper-text" required={true} />
<TextField data-testid="country-input" sx={{ width: '85%' }} label="Country" id="Country" aria-describedby="Country-helper-text" required={true} />
<FormHelperText id="Country-helper-text">Example: Spain.</FormHelperText>
<Alert sx={{ width: '82%' }} severity="info">Attention! By clicking "Set Address" you are giving us persmission to write on your VCARD, a public place.</Alert>
<Button type="button" onClick={addAddress} id="addAddress" variant="contained">Set Address</Button>
Expand Down

0 comments on commit e898980

Please sign in to comment.