|
1 |
| -import { screen, waitFor, within } from "@testing-library/react"; |
| 1 | +import { fireEvent, screen, waitFor, within } from "@testing-library/react"; |
2 | 2 | import userEvent from "@testing-library/user-event";
|
3 | 3 | import { API } from "api/api";
|
4 | 4 | import {
|
|
8 | 8 | MockTemplateVersionVariable1,
|
9 | 9 | MockTemplateVersionVariable2,
|
10 | 10 | MockTemplateVersionVariable3,
|
| 11 | + mockApiError, |
11 | 12 | } from "testHelpers/entities";
|
12 | 13 | import { renderWithAuth } from "testHelpers/renderHelpers";
|
13 | 14 | import CreateTemplatePage from "./CreateTemplatePage";
|
@@ -150,3 +151,30 @@ test("Create template from duplicating a template", async () => {
|
150 | 151 | );
|
151 | 152 | });
|
152 | 153 | });
|
| 154 | + |
| 155 | +test("The page displays an error if the upload fails", async () => { |
| 156 | + const errMsg = "Unsupported content type header"; |
| 157 | + jest.spyOn(API, "uploadFile").mockRejectedValueOnce( |
| 158 | + mockApiError({ |
| 159 | + message: errMsg, |
| 160 | + }), |
| 161 | + ); |
| 162 | + await renderPage(new URLSearchParams()); |
| 163 | + |
| 164 | + const file = new File([""], "invalidfile.tar"); |
| 165 | + const dropZone = screen.getByTestId("drop-zone"); |
| 166 | + |
| 167 | + fireEvent.drop(dropZone, { |
| 168 | + dataTransfer: { files: [file] }, |
| 169 | + }); |
| 170 | + |
| 171 | + await waitFor(() => expect(API.uploadFile).toHaveBeenCalledTimes(1)); |
| 172 | + |
| 173 | + // Error toast should be displayed |
| 174 | + expect(await screen.findByText(errMsg)).toBeInTheDocument(); |
| 175 | + |
| 176 | + // The upload box should have reset itself |
| 177 | + expect( |
| 178 | + await screen.findByText(/The template has to be a .tar or .zip file/), |
| 179 | + ).toBeInTheDocument(); |
| 180 | +}); |
0 commit comments