Refactor: Fix eslint problems in tests
This commit is contained in:
parent
dd47b36890
commit
765443ebc2
|
@ -28,6 +28,111 @@ import {
|
|||
} from "./test-helper";
|
||||
import QuestionAnswersList from "../components/QuestionAnswerList";
|
||||
|
||||
function renderQuestionAnswerList(additionalMocks?: Array<MockedResponse>) {
|
||||
const initialMocks = [
|
||||
...getAllQuestionAnswersMock,
|
||||
...getAnswerByQuestionAndPersonMock,
|
||||
];
|
||||
const allMocks = additionalMocks
|
||||
? [...initialMocks, ...additionalMocks]
|
||||
: initialMocks;
|
||||
return render(
|
||||
<MockedProvider mocks={allMocks}>
|
||||
<MemoryRouter>
|
||||
<SnackbarProvider>
|
||||
<QuestionAnswersList personRowId={2} />
|
||||
</SnackbarProvider>
|
||||
</MemoryRouter>
|
||||
</MockedProvider>
|
||||
);
|
||||
}
|
||||
|
||||
const waitForQuestionsToRender = async (): Promise<Array<HTMLElement>> => {
|
||||
const numberOfAnswersInMockQuery = questionAnswersMock.length;
|
||||
let questionAnswerCards: Array<HTMLElement> = [];
|
||||
await waitFor(() => {
|
||||
questionAnswerCards = screen.queryAllByRole("button", {
|
||||
name: /Question [1-3]/,
|
||||
});
|
||||
expect(questionAnswerCards.length).toEqual(numberOfAnswersInMockQuery);
|
||||
});
|
||||
return questionAnswerCards;
|
||||
};
|
||||
|
||||
const getSaveAnswerButton = (parent: HTMLElement) => {
|
||||
return findByRole(parent, "button", { name: /speichern/i });
|
||||
};
|
||||
|
||||
const getResetAnswerButton = (parent: HTMLElement) => {
|
||||
return findByRole(parent, "button", { name: /zurücksetzen/i });
|
||||
};
|
||||
|
||||
interface PositionIconButtons {
|
||||
positive: HTMLElement;
|
||||
neutral: HTMLElement;
|
||||
negative: HTMLElement;
|
||||
skipped: HTMLElement;
|
||||
}
|
||||
|
||||
const getCandidatePositionButtons = async (
|
||||
parent: HTMLElement
|
||||
): Promise<PositionIconButtons> => {
|
||||
const labelAboveButtons = await findByText(parent, /Deine Position/i);
|
||||
const parentElement = labelAboveButtons.parentElement as HTMLElement;
|
||||
const positive = queryAllIconButtons(
|
||||
getPositivePositionPath(),
|
||||
parentElement
|
||||
)[0];
|
||||
const neutral = queryAllIconButtons(
|
||||
getNeutralPositionPath(),
|
||||
parentElement
|
||||
)[0];
|
||||
const negative = queryAllIconButtons(
|
||||
getNegativePositionPath(),
|
||||
parentElement
|
||||
)[0];
|
||||
const skipped = queryAllIconButtons(
|
||||
getSkippedPositionPath(),
|
||||
parentElement
|
||||
)[0];
|
||||
expect(positive).toBeDefined();
|
||||
expect(neutral).toBeDefined();
|
||||
expect(negative).toBeDefined();
|
||||
expect(skipped).toBeDefined();
|
||||
return {
|
||||
positive,
|
||||
neutral,
|
||||
negative,
|
||||
skipped,
|
||||
};
|
||||
};
|
||||
|
||||
interface AccordionAnswerSection {
|
||||
positionIconButtons: PositionIconButtons;
|
||||
textField: HTMLElement;
|
||||
saveButton: HTMLElement;
|
||||
resetButton: HTMLElement;
|
||||
}
|
||||
|
||||
const expandAccordionAndGetAnswerSection = async (
|
||||
accordionExpandArea: HTMLElement
|
||||
): Promise<AccordionAnswerSection | undefined> => {
|
||||
fireEvent.click(accordionExpandArea);
|
||||
let fullAccordion = accordionExpandArea.parentElement;
|
||||
expect(fullAccordion).not.toBeNull();
|
||||
fullAccordion = fullAccordion as HTMLElement;
|
||||
const textField = await findByRole(fullAccordion, "textbox");
|
||||
const saveButton = await getSaveAnswerButton(fullAccordion);
|
||||
const resetButton = await getResetAnswerButton(fullAccordion);
|
||||
const positionIconButtons = await getCandidatePositionButtons(fullAccordion);
|
||||
return {
|
||||
positionIconButtons,
|
||||
textField,
|
||||
saveButton,
|
||||
resetButton,
|
||||
};
|
||||
};
|
||||
|
||||
describe("The AnswerList", () => {
|
||||
test("displays the existing answers, but not the details of it", async () => {
|
||||
renderQuestionAnswerList();
|
||||
|
@ -145,108 +250,3 @@ describe("The AnswerList", () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
function renderQuestionAnswerList(additionalMocks?: Array<MockedResponse>) {
|
||||
const initialMocks = [
|
||||
...getAllQuestionAnswersMock,
|
||||
...getAnswerByQuestionAndPersonMock,
|
||||
];
|
||||
const allMocks = additionalMocks
|
||||
? [...initialMocks, ...additionalMocks]
|
||||
: initialMocks;
|
||||
return render(
|
||||
<MockedProvider mocks={allMocks}>
|
||||
<MemoryRouter>
|
||||
<SnackbarProvider>
|
||||
<QuestionAnswersList personRowId={2} />
|
||||
</SnackbarProvider>
|
||||
</MemoryRouter>
|
||||
</MockedProvider>
|
||||
);
|
||||
}
|
||||
|
||||
const waitForQuestionsToRender = async (): Promise<Array<HTMLElement>> => {
|
||||
const numberOfAnswersInMockQuery = questionAnswersMock.length;
|
||||
let questionAnswerCards: Array<HTMLElement> = [];
|
||||
await waitFor(() => {
|
||||
questionAnswerCards = screen.queryAllByRole("button", {
|
||||
name: /Question [1-3]/,
|
||||
});
|
||||
expect(questionAnswerCards.length).toEqual(numberOfAnswersInMockQuery);
|
||||
});
|
||||
return questionAnswerCards;
|
||||
};
|
||||
|
||||
const getSaveAnswerButton = (parent: HTMLElement) => {
|
||||
return findByRole(parent, "button", { name: /speichern/i });
|
||||
};
|
||||
|
||||
const getResetAnswerButton = (parent: HTMLElement) => {
|
||||
return findByRole(parent, "button", { name: /zurücksetzen/i });
|
||||
};
|
||||
|
||||
interface PositionIconButtons {
|
||||
positive: HTMLElement;
|
||||
neutral: HTMLElement;
|
||||
negative: HTMLElement;
|
||||
skipped: HTMLElement;
|
||||
}
|
||||
|
||||
const getCandidatePositionButtons = async (
|
||||
parent: HTMLElement
|
||||
): Promise<PositionIconButtons> => {
|
||||
const labelAboveButtons = await findByText(parent, /Deine Position/i);
|
||||
const parentElement = labelAboveButtons.parentElement as HTMLElement;
|
||||
const positive = queryAllIconButtons(
|
||||
getPositivePositionPath(),
|
||||
parentElement
|
||||
)[0];
|
||||
const neutral = queryAllIconButtons(
|
||||
getNeutralPositionPath(),
|
||||
parentElement
|
||||
)[0];
|
||||
const negative = queryAllIconButtons(
|
||||
getNegativePositionPath(),
|
||||
parentElement
|
||||
)[0];
|
||||
const skipped = queryAllIconButtons(
|
||||
getSkippedPositionPath(),
|
||||
parentElement
|
||||
)[0];
|
||||
expect(positive).toBeDefined();
|
||||
expect(neutral).toBeDefined();
|
||||
expect(negative).toBeDefined();
|
||||
expect(skipped).toBeDefined();
|
||||
return {
|
||||
positive,
|
||||
neutral,
|
||||
negative,
|
||||
skipped,
|
||||
};
|
||||
};
|
||||
|
||||
interface AccordionAnswerSection {
|
||||
positionIconButtons: PositionIconButtons;
|
||||
textField: HTMLElement;
|
||||
saveButton: HTMLElement;
|
||||
resetButton: HTMLElement;
|
||||
}
|
||||
|
||||
const expandAccordionAndGetAnswerSection = async (
|
||||
accordionExpandArea: HTMLElement
|
||||
): Promise<AccordionAnswerSection | undefined> => {
|
||||
fireEvent.click(accordionExpandArea);
|
||||
let fullAccordion = accordionExpandArea.parentElement;
|
||||
expect(fullAccordion).not.toBeNull();
|
||||
fullAccordion = fullAccordion as HTMLElement;
|
||||
const textField = await findByRole(fullAccordion, "textbox");
|
||||
const saveButton = await getSaveAnswerButton(fullAccordion);
|
||||
const resetButton = await getResetAnswerButton(fullAccordion);
|
||||
const positionIconButtons = await getCandidatePositionButtons(fullAccordion);
|
||||
return {
|
||||
positionIconButtons,
|
||||
textField,
|
||||
saveButton,
|
||||
resetButton,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -21,6 +21,40 @@ import {
|
|||
queryAllEditIconButtons,
|
||||
} from "./test-helper";
|
||||
|
||||
function renderQuestionList(additionalMocks?: Array<MockedResponse>) {
|
||||
const initialMocks = [
|
||||
...getAllQuestionsMock,
|
||||
...getQuestionByIdMock,
|
||||
...getAllCategoriesMock,
|
||||
];
|
||||
const allMocks = additionalMocks
|
||||
? [...initialMocks, ...additionalMocks]
|
||||
: initialMocks;
|
||||
return render(
|
||||
<MockedProvider mocks={allMocks}>
|
||||
<MemoryRouter>
|
||||
<SnackbarProvider>
|
||||
<QuestionList />
|
||||
</SnackbarProvider>
|
||||
</MemoryRouter>
|
||||
</MockedProvider>
|
||||
);
|
||||
}
|
||||
|
||||
const waitForInitialQuestionsToRender = async (): Promise<
|
||||
Array<HTMLElement>
|
||||
> => {
|
||||
const numberOfQuestionsInMockQuery = questionNodesMock.length;
|
||||
let questionCards: Array<HTMLElement> = [];
|
||||
await waitFor(() => {
|
||||
questionCards = screen.queryAllByRole("button", {
|
||||
name: /Question [1-3]\?/,
|
||||
});
|
||||
expect(questionCards.length).toEqual(numberOfQuestionsInMockQuery);
|
||||
});
|
||||
return questionCards;
|
||||
};
|
||||
|
||||
describe("The QuestionList", () => {
|
||||
test("displays the existing questions, but not the details of it", async () => {
|
||||
renderQuestionList();
|
||||
|
@ -138,37 +172,3 @@ describe("The QuestionList", () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
function renderQuestionList(additionalMocks?: Array<MockedResponse>) {
|
||||
const initialMocks = [
|
||||
...getAllQuestionsMock,
|
||||
...getQuestionByIdMock,
|
||||
...getAllCategoriesMock,
|
||||
];
|
||||
const allMocks = additionalMocks
|
||||
? [...initialMocks, ...additionalMocks]
|
||||
: initialMocks;
|
||||
return render(
|
||||
<MockedProvider mocks={allMocks}>
|
||||
<MemoryRouter>
|
||||
<SnackbarProvider>
|
||||
<QuestionList />
|
||||
</SnackbarProvider>
|
||||
</MemoryRouter>
|
||||
</MockedProvider>
|
||||
);
|
||||
}
|
||||
|
||||
const waitForInitialQuestionsToRender = async (): Promise<
|
||||
Array<HTMLElement>
|
||||
> => {
|
||||
const numberOfQuestionsInMockQuery = questionNodesMock.length;
|
||||
let questionCards: Array<HTMLElement> = [];
|
||||
await waitFor(() => {
|
||||
questionCards = screen.queryAllByRole("button", {
|
||||
name: /Question [1-3]\?/,
|
||||
});
|
||||
expect(questionCards.length).toEqual(numberOfQuestionsInMockQuery);
|
||||
});
|
||||
return questionCards;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue