Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danieladov committed May 2, 2022
1 parent fa95fdf commit 4e606ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 8 additions & 1 deletion webapp/src/components/administrator/AdminView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@ import userEvent from "@testing-library/user-event";


test('add product button calls the api to add a product', async () => {
const { getByText } = render(<Router><AdminView /></Router>);
const { getByText,getByTestId } = render(<Router><AdminView /></Router>);

const spy = jest.spyOn(api,"addProduct").mockImplementation(():Promise<boolean> => Promise.resolve(true));
userEvent.type(getByTestId("input-name"), "P1");
userEvent.type(getByTestId("input-description"), "P1 description");
userEvent.type(getByTestId("input-number"), "79.99");
userEvent.type(getByTestId("input-category"), "Test");

fireEvent.click(getByText("Add Product"));
expect(spy).toHaveBeenCalledTimes(1);
});




/**
* Test that the delete product button calls the api to delete a product.
*
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/components/administrator/AdminView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function AdminView(): JSX.Element {
return (

<Box justifyContent="center">
<Button onClick={() => logOut()}>
<Button data-testid="logout" onClick={() => logOut()}>
<Logout></Logout>
</Button>
<Box justifyContent="center">
Expand All @@ -87,6 +87,7 @@ function AdminView(): JSX.Element {
sx={{ input: { color: 'black' } }}
value={name}
onChange={(e:any) => setName(e.target.value)}
inputProps={{ "data-testid": "input-name" }}

/>

Expand Down Expand Up @@ -125,7 +126,7 @@ function AdminView(): JSX.Element {
sx={{ input: { color: 'black' } }}
value={category}
onChange={(e:any) => setCategory(e.target.value)}
inputProps={{ "data-testid": "input-email" }}
inputProps={{ "data-testid": "input-category" }}

/>
<Button variant="contained" component="label">
Expand Down

0 comments on commit 4e606ce

Please sign in to comment.