Skip to content

Commit

Permalink
feat(imageuploader): write test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidicus committed Nov 13, 2020
1 parent 68927b8 commit 70809c5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/ImageCard/ImageUploader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const { iotPrefix } = settings;
const i18nDefaults = {
dropContainerLabelText: 'Drag and drop file here or click to select file',
dropContainerDescText:
'Max file size is 1MB. Supported file types are: JPEG, PNG, GIF, WEBP, TIFF, JPEG2000',
'Max file size is 1MB. Supported file types are: APNG, AVIF, GIF, JPEG, PNG, WebP',
uploadByURLCancel: 'Cancel',
uploadByURLButton: 'OK',
browseImages: 'Browse images',
Expand All @@ -44,7 +44,7 @@ const propTypes = {
};

const defaultProps = {
accept: ['JPEG', 'PNG', 'GIF', 'WEBP', 'TIFF', 'JPEG2000'],
accept: ['APNG', 'AVIF', 'GIF', 'JPEG', 'PNG', 'WebP'],
onBrowseClick: () => {},
onUpload: () => {},
i18n: i18nDefaults,
Expand Down
28 changes: 28 additions & 0 deletions src/components/ImageCard/ImageUploader.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import ImageUploader from './ImageUploader';

describe('ImageUploader', () => {
it('will switch to URL upload screen', () => {
render(<ImageUploader />);

const insertFromURLBtn = screen.getByText(/Insert from URL/);
userEvent.click(insertFromURLBtn);
expect(screen.getAllByText(/OK/)).toHaveLength(1);
});

it('will upload and use an image from URL', async () => {
render(<ImageUploader />);

const insertFromURLBtn = screen.getByText(/Insert from URL/);
userEvent.click(insertFromURLBtn);
await userEvent.type(
screen.getAllByTitle('Type or insert URL'),
'http://placekitten.com/200/300'
);
userEvent.click(insertFromURLBtn);
expect(screen.querySelectorAll('.iot--image-card-img')).toHaveLength(1);
});
});

0 comments on commit 70809c5

Please sign in to comment.