From 40a6ee2bd1d8312446195fb142bb07dcbbb38163 Mon Sep 17 00:00:00 2001 From: literat Date: Mon, 21 Oct 2024 14:23:18 +0200 Subject: [PATCH] fixup! Fix(web-react): FileUploaderInput className #DS-1508 --- .../__tests__/FileUploaderInput.test.tsx | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/web-react/src/components/FileUploader/__tests__/FileUploaderInput.test.tsx b/packages/web-react/src/components/FileUploader/__tests__/FileUploaderInput.test.tsx index 3b6478f34b..8f2eba53b3 100644 --- a/packages/web-react/src/components/FileUploader/__tests__/FileUploaderInput.test.tsx +++ b/packages/web-react/src/components/FileUploader/__tests__/FileUploaderInput.test.tsx @@ -1,7 +1,11 @@ +import { render, screen, act } from '@testing-library/react'; +import React from 'react'; +import ReactDOMServer from 'react-dom/server'; import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest'; import { restPropsTest } from '../../../../tests/providerTests/restPropsTest'; import { validationTextPropsTest } from '../../../../tests/providerTests/validationTextPropsTest'; import FileUploaderInput from '../FileUploaderInput'; +import '@testing-library/jest-dom'; describe('FileUploaderInput', () => { classNamePrefixProviderTest(FileUploaderInput, 'FileUploaderInput'); @@ -9,4 +13,33 @@ describe('FileUploaderInput', () => { restPropsTest(FileUploaderInput, 'div'); validationTextPropsTest(FileUploaderInput, '.FileUploaderInput__validationText'); + + it('should have drag-and-drop listeners in CSR when draggable is supported', () => { + render(); + + const dropZone = screen.getByLabelText(/upload/i).parentElement; + + expect(dropZone).toHaveAttribute('ondragover'); + expect(dropZone).toHaveAttribute('ondragenter'); + expect(dropZone).toHaveAttribute('ondragleave'); + expect(dropZone).toHaveAttribute('ondrop'); + }); + + it('should not have drag-and-drop listeners in SSR', () => { + const ui = ; + const container = document.createElement('div'); + document.body.appendChild(container); + container.innerHTML = ReactDOMServer.renderToString(ui); + + act(() => { + render(ui, { hydrate: true, container }); + }); + + const dropZone = screen.getByLabelText(/upload/i).parentElement; + + expect(dropZone).not.toHaveAttribute('ondragover'); + expect(dropZone).not.toHaveAttribute('ondragenter'); + expect(dropZone).not.toHaveAttribute('ondragleave'); + expect(dropZone).not.toHaveAttribute('ondrop'); + }); });