|
7 | 7 | } from "../../utils/instanceHandlers"; |
8 | 8 | import { ISchemaFieldMap } from "../../utils/types/index.types"; |
9 | 9 | import FieldToolbarComponent from "../FieldToolbar"; |
10 | | -import { mockMultipleLinkFieldSchema, singleLineFieldSchema } from "../../../__test__/data/fields"; |
| 10 | +import { mockMultipleLinkFieldSchema, mockMultipleFileFieldSchema } from "../../../__test__/data/fields"; |
11 | 11 | import { asyncRender } from "../../../__test__/utils"; |
12 | 12 | import { VisualBuilderCslpEventDetails } from "../../types/visualBuilder.types"; |
13 | 13 |
|
@@ -180,4 +180,60 @@ describe("MultipleFieldToolbarComponent", () => { |
180 | 180 | ); |
181 | 181 | expect(variantIcon).toBeInTheDocument(); |
182 | 182 | }); |
| 183 | + |
| 184 | + describe("'Replace button' visibility for multiple file fields", () => { |
| 185 | + beforeEach(() => { |
| 186 | + vi.spyOn(FieldSchemaMap, "getFieldSchema").mockResolvedValue( |
| 187 | + mockMultipleFileFieldSchema |
| 188 | + ); |
| 189 | + }); |
| 190 | + |
| 191 | + test("'replace button' is hidden for parent wrapper of multiple file field", async () => { |
| 192 | + const parentWrapperMetadata: CslpData = { |
| 193 | + ...mockMultipleFieldMetadata, |
| 194 | + fieldPathWithIndex: "files", |
| 195 | + instance: { |
| 196 | + fieldPathWithIndex: "files" |
| 197 | + }, |
| 198 | + }; |
| 199 | + |
| 200 | + const parentWrapperEventDetails = { |
| 201 | + ...mockEventDetails, |
| 202 | + fieldMetadata: parentWrapperMetadata |
| 203 | + }; |
| 204 | + |
| 205 | + const { container } = await asyncRender( |
| 206 | + <FieldToolbarComponent |
| 207 | + eventDetails={parentWrapperEventDetails} |
| 208 | + /> |
| 209 | + ); |
| 210 | + |
| 211 | + const replaceButton = container.querySelector('[data-testid="visual-builder-replace-file"]'); |
| 212 | + expect(replaceButton).not.toBeInTheDocument(); |
| 213 | + }); |
| 214 | + |
| 215 | + test("'replace button' is visible for individual field in multiple file field", async () => { |
| 216 | + const individualFieldMetadata: CslpData = { |
| 217 | + ...mockMultipleFieldMetadata, |
| 218 | + fieldPathWithIndex: "files", |
| 219 | + instance: { |
| 220 | + fieldPathWithIndex: "files.0" |
| 221 | + }, |
| 222 | + }; |
| 223 | + |
| 224 | + const individualFieldEventDetails = { |
| 225 | + ...mockEventDetails, |
| 226 | + fieldMetadata: individualFieldMetadata |
| 227 | + }; |
| 228 | + |
| 229 | + const { container } = await asyncRender( |
| 230 | + <FieldToolbarComponent |
| 231 | + eventDetails={individualFieldEventDetails} |
| 232 | + /> |
| 233 | + ); |
| 234 | + |
| 235 | + const replaceButton = container.querySelector('[data-testid="visual-builder-replace-file"]'); |
| 236 | + expect(replaceButton).toBeInTheDocument(); |
| 237 | + }); |
| 238 | + }); |
183 | 239 | }); |
0 commit comments