Skip to content

Commit

Permalink
fixup! Fix(web-react): FileUploaderInput className #DS-1508
Browse files Browse the repository at this point in the history
  • Loading branch information
literat committed Oct 21, 2024
1 parent 2b7b57a commit 40a6ee2
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
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');

restPropsTest(FileUploaderInput, 'div');

validationTextPropsTest(FileUploaderInput, '.FileUploaderInput__validationText');

it('should have drag-and-drop listeners in CSR when draggable is supported', () => {
render(<FileUploaderInput id="test-uploader" name="test-uploader" />);

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 = <FileUploaderInput id="test-uploader" name="test-uploader" />;
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');
});
});

0 comments on commit 40a6ee2

Please sign in to comment.