Skip to content

refactor: get rid of templateVariablesXService #9763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix tests
  • Loading branch information
aslilac committed Sep 19, 2023
commit 687afa66cc91122e3fbfbc9886ece09a70ce9165
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
MockTemplateVersionVariable1,
MockTemplateVersionVariable2,
MockTemplateVersion2,
MockTemplateVersionVariable5,
} from "testHelpers/entities";
import { delay } from "utils/delay";

const validFormValues = {
first_variable: "Hello world",
Expand Down Expand Up @@ -62,7 +62,7 @@ describe("TemplateVariablesPage", () => {
jest.spyOn(API, "getTemplateByName").mockResolvedValueOnce(MockTemplate);
jest
.spyOn(API, "getTemplateVersion")
.mockResolvedValueOnce(MockTemplateVersion);
.mockResolvedValue(MockTemplateVersion);
jest
.spyOn(API, "getTemplateVersionVariables")
.mockResolvedValueOnce([
Expand Down Expand Up @@ -106,49 +106,9 @@ describe("TemplateVariablesPage", () => {
FooterFormLanguage.defaultSubmitLabel,
);
await userEvent.click(submitButton);

// Wait for the success message
await screen.findByText("Template updated successfully");
});

it("user forgets to fill the required field", async () => {
jest.spyOn(API, "getTemplateByName").mockResolvedValueOnce(MockTemplate);
jest
.spyOn(API, "getTemplateVersion")
.mockResolvedValueOnce(MockTemplateVersion);
jest
.spyOn(API, "getTemplateVersionVariables")
.mockResolvedValueOnce([
MockTemplateVersionVariable1,
MockTemplateVersionVariable5,
]);
jest
.spyOn(API, "createTemplateVersion")
.mockResolvedValueOnce(MockTemplateVersion2);
jest.spyOn(API, "updateActiveTemplateVersion").mockResolvedValueOnce({
message: "done",
});

await renderTemplateVariablesPage();

const firstVariable = await screen.findByLabelText(
MockTemplateVersionVariable1.name,
);
expect(firstVariable).toBeDefined();
await delay(1500);

const fifthVariable = await screen.findByLabelText(
MockTemplateVersionVariable5.name,
);
expect(fifthVariable).toBeDefined();

// Submit the form
const submitButton = await screen.findByText(
FooterFormLanguage.defaultSubmitLabel,
);
await userEvent.click(submitButton);

// Check validation error
const validationError = await screen.findByText(validationRequiredField);
expect(validationError).toBeDefined();
await screen.findByText("Template updated successfully");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const WithErrors: Story = {
],
errors: {
buildError: mockApiError({
message: "statusError",
message: "buildError",
validations: [
{
field: `user_variable_values[0].value`,
Expand Down