Skip to content

Commit

Permalink
chore: add missing files
Browse files Browse the repository at this point in the history
Signed-off-by: Márk Kővári <kovarimarkofficial@gmail.com>
  • Loading branch information
markkovari committed Jul 13, 2024
1 parent 8af8ffa commit 8ae4fa5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 34 deletions.
9 changes: 9 additions & 0 deletions frontend/src/mocks/handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { http, HttpResponse } from 'msw'

export const handlers = [

http.post('http://localhost:8080/register', () => {
return HttpResponse.json({ message: 'User registered successfully' })

})
]
4 changes: 4 additions & 0 deletions frontend/src/mocks/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { setupServer } from 'msw/node'
import { handlers } from './handler'

export const server = setupServer(...handlers)
34 changes: 0 additions & 34 deletions frontend/src/pages/Register.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import { BrowserRouter as Router } from 'react-router-dom';
import { userEvent } from "@testing-library/user-event";
import "@testing-library/jest-dom";


import { server } from "../mocks/server";
import { http, HttpResponse } from "msw";
import { setupServer } from "msw/node";

describe("Register component", () => {
test("has a heading 'Register'", async () => {
// Arrange
Expand Down Expand Up @@ -100,33 +95,4 @@ describe("Register component", () => {
expect(passwordField).toHaveTextContent("")
expect(emailField).toHaveTextContent("")
});

test("successfull registration should clear the form", async () => {
// Arrange
render(
<Router>
<Register />
</Router>
);
const user = userEvent.setup();

const passwordField = screen.getByLabelText('pass');
const firstNameField = screen.getByLabelText("firstName")
const lastNameField = screen.getByLabelText("lastName")
const emailField = screen.getByLabelText("email")

// Act
await user.type(passwordField, "Ajg65657h")
await user.type(firstNameField, "John")
await user.type(lastNameField, "Doe")
await user.type(emailField, "johndoe@gmail.com")

await user.click(screen.getByRole('button', { name: 'Register' }));

// Assert
expect(firstNameField).toHaveTextContent("")
expect(lastNameField).toHaveTextContent("")
expect(passwordField).toHaveTextContent("")
expect(emailField).toHaveTextContent("")
});
});

0 comments on commit 8ae4fa5

Please sign in to comment.