Skip to content

Commit

Permalink
makes variable names for result and feedback more consistent in forms…
Browse files Browse the repository at this point in the history
… tests
  • Loading branch information
jschuurk-kr committed Jul 15, 2024
1 parent 4d3a795 commit d6f6852
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ describe("Test CandidatesVotesForm", () => {

const submitButton = screen.getByRole("button", { name: "Volgende" });
await user.click(submitButton);
const result = await screen.findByTestId("feedback-server-error");
expect(result).toHaveTextContent(/^Error422 error from mock$/);
const feedbackServerError = await screen.findByTestId("feedback-server-error");
expect(feedbackServerError).toHaveTextContent(/^Error422 error from mock$/);
});

test("500 response results in display of error message", async () => {
Expand All @@ -305,8 +305,8 @@ describe("Test CandidatesVotesForm", () => {

const submitButton = screen.getByRole("button", { name: "Volgende" });
await user.click(submitButton);
const result = await screen.findByTestId("feedback-server-error");
expect(result).toHaveTextContent(/^Error500 error from mock$/);
const feedbackServerError = await screen.findByTestId("feedback-server-error");
expect(feedbackServerError).toHaveTextContent(/^Error500 error from mock$/);
});

describe("CandidatesVotesForm errors", () => {
Expand Down Expand Up @@ -335,8 +335,8 @@ describe("Test CandidatesVotesForm", () => {
const submitButton = screen.getByRole("button", { name: "Volgende" });
await user.click(submitButton);

const result = await screen.findByTestId("feedback-error");
expect(result).toHaveTextContent(/^IncorrectTotal$/);
const feedbackError = await screen.findByTestId("feedback-error");
expect(feedbackError).toHaveTextContent(/^IncorrectTotal$/);
expect(screen.queryByTestId("feedback-warning")).toBeNull();
expect(screen.queryByTestId("server-feedback-error")).toBeNull();
});
Expand Down
12 changes: 6 additions & 6 deletions frontend/app/component/form/differences/DifferencesForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ describe("Test DifferencesForm", () => {

const submitButton = screen.getByRole("button", { name: "Volgende" });
await user.click(submitButton);
const result = await screen.findByTestId("feedback-server-error");
expect(result).toHaveTextContent(/^Error422 error from mock$/);
const feedbackServerError = await screen.findByTestId("feedback-server-error");
expect(feedbackServerError).toHaveTextContent(/^Error422 error from mock$/);
});

test("500 response results in display of error message", async () => {
Expand All @@ -232,8 +232,8 @@ describe("Test DifferencesForm", () => {

const submitButton = screen.getByRole("button", { name: "Volgende" });
await user.click(submitButton);
const result = await screen.findByTestId("feedback-server-error");
expect(result).toHaveTextContent(/^Error500 error from mock$/);
const feedbackServerError = await screen.findByTestId("feedback-server-error");
expect(feedbackServerError).toHaveTextContent(/^Error500 error from mock$/);
});

// TODO: Add validation test once backend validation is implemented
Expand All @@ -253,7 +253,7 @@ describe("Test DifferencesForm", () => {
const submitButton = screen.getByRole("button", { name: "Volgende" });
await user.click(submitButton);

const result = await screen.findByTestId("feedback-error");
expect(result).toHaveTextContent(/^IncorrectTotal,IncorrectTotal$/);
const feedbackError = await screen.findByTestId("feedback-error");
expect(feedbackError).toHaveTextContent(/^IncorrectTotal,IncorrectTotal$/);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,11 @@ describe("Test VotersAndVotesForm", () => {

const submitButton = screen.getByRole("button", { name: "Volgende" });
await user.click(submitButton);
const result = await screen.findByTestId("feedback-server-error");
expect(result).toHaveTextContent(/^Error422 error from mock$/);
const feedbackServerError = await screen.findByTestId("feedback-server-error");
expect(feedbackServerError).toHaveTextContent(/^Error422 error from mock$/);

expect(screen.queryByTestId("result")).not.toBeNull();
expect(screen.queryByTestId("result")).toHaveTextContent(/^422 error from mock$/);
});

test("500 response results in display of error message", async () => {
Expand All @@ -247,8 +250,11 @@ describe("Test VotersAndVotesForm", () => {

const submitButton = screen.getByRole("button", { name: "Volgende" });
await user.click(submitButton);
const result = await screen.findByTestId("feedback-server-error");
expect(result).toHaveTextContent(/^Error500 error from mock$/);
const feedbackServerError = await screen.findByTestId("feedback-server-error");
expect(feedbackServerError).toHaveTextContent(/^Error500 error from mock$/);

expect(screen.queryByTestId("result")).not.toBeNull();
expect(screen.queryByTestId("result")).toHaveTextContent(/^500 error from mock$/);
});

test("Incorrect total is caught by validation", async () => {
Expand Down Expand Up @@ -297,8 +303,9 @@ describe("Test VotersAndVotesForm", () => {
const submitButton = screen.getByRole("button", { name: "Volgende" });
await user.click(submitButton);

const result = await screen.findByTestId("feedback-error");
expect(result).toHaveTextContent(/^IncorrectTotalIncorrectTotal$/);
const feedbackError = await screen.findByTestId("feedback-error");
expect(feedbackError).toHaveTextContent(/^IncorrectTotalIncorrectTotal$/);
expect(screen.queryByTestId("result")).toBeNull();
});

test("Error with non-existing fields is displayed", async () => {
Expand Down Expand Up @@ -350,8 +357,8 @@ describe("Test VotersAndVotesForm", () => {
const submitButton = screen.getByRole("button", { name: "Volgende" });
await user.click(submitButton);

const result = await screen.findByTestId("feedback-server-error");
expect(result).toHaveTextContent(/^Error$/);
const feedbackServerError = await screen.findByTestId("feedback-server-error");
expect(feedbackServerError).toHaveTextContent(/^Error$/);
expect(screen.queryByTestId("feedback-warning")).toBeNull();
expect(screen.queryByTestId("feedback-error")).toBeNull();
});
Expand Down Expand Up @@ -388,8 +395,8 @@ describe("Test VotersAndVotesForm", () => {
const submitButton = screen.getByRole("button", { name: "Volgende" });
await user.click(submitButton);

const result = await screen.findByTestId("feedback-error");
expect(result).toHaveTextContent(/^IncorrectTotal$/);
const feedbackError = await screen.findByTestId("feedback-error");
expect(feedbackError).toHaveTextContent(/^IncorrectTotal$/);
expect(screen.queryByTestId("feedback-warning")).toBeNull();
expect(screen.queryByTestId("server-feedback-error")).toBeNull();
});
Expand Down Expand Up @@ -430,8 +437,8 @@ describe("Test VotersAndVotesForm", () => {
const submitButton = screen.getByRole("button", { name: "Volgende" });
await user.click(submitButton);

const result = await screen.findByTestId("feedback-error");
expect(result).toHaveTextContent(/^IncorrectTotal$/);
const feedbackError = await screen.findByTestId("feedback-error");
expect(feedbackError).toHaveTextContent(/^IncorrectTotal$/);
expect(screen.queryByTestId("feedback-warning")).toBeNull();
expect(screen.queryByTestId("server-feedback-error")).toBeNull();
});
Expand Down Expand Up @@ -468,8 +475,8 @@ describe("Test VotersAndVotesForm", () => {
const submitButton = screen.getByRole("button", { name: "Volgende" });
await user.click(submitButton);

const result = await screen.findByTestId("feedback-warning");
expect(result).toHaveTextContent(/^AboveThreshold$/);
const feedbackWarning = await screen.findByTestId("feedback-warning");
expect(feedbackWarning).toHaveTextContent(/^AboveThreshold$/);
expect(screen.queryByTestId("feedback-server-error")).toBeNull();
expect(screen.queryByTestId("feedback-error")).toBeNull();
});
Expand Down Expand Up @@ -504,8 +511,8 @@ describe("Test VotersAndVotesForm", () => {
const submitButton = screen.getByRole("button", { name: "Volgende" });
await user.click(submitButton);

const result = await screen.findByTestId("feedback-warning");
expect(result).toHaveTextContent(/^AboveThreshold$/);
const feedbackWarning = await screen.findByTestId("feedback-warning");
expect(feedbackWarning).toHaveTextContent(/^AboveThreshold$/);
expect(screen.queryByTestId("feedback-server-error")).toBeNull();
expect(screen.queryByTestId("feedback-error")).toBeNull();
});
Expand Down Expand Up @@ -547,8 +554,8 @@ describe("Test VotersAndVotesForm", () => {
const submitButton = screen.getByRole("button", { name: "Volgende" });
await user.click(submitButton);

const result = await screen.findByTestId("feedback-warning");
expect(result).toHaveTextContent(/^EqualInput$/);
const feedbackWarning = await screen.findByTestId("feedback-warning");
expect(feedbackWarning).toHaveTextContent(/^EqualInput$/);
expect(screen.queryByTestId("feedback-server-error")).toBeNull();
expect(screen.queryByTestId("feedback-error")).toBeNull();
});
Expand Down

0 comments on commit d6f6852

Please sign in to comment.