The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/packages/grafana-ui/src/components/FileUpload/FileUpload.test.tsx

33 lines
1.2 KiB

import React from 'react';
import { shallow } from 'enzyme';
import { FileUpload } from './FileUpload';
describe('FileUpload', () => {
it('should render upload button with default text and no file name', () => {
const wrapper = shallow(<FileUpload onFileUpload={() => {}} />);
expect(wrapper.findWhere((comp) => comp.text() === 'Upload file').exists()).toBeTruthy();
expect(wrapper.find({ 'aria-label': 'File name' }).exists()).toBeFalsy();
});
it("should trim uploaded file's name", () => {
const wrapper = shallow(<FileUpload onFileUpload={() => {}} />);
wrapper.find('input').simulate('change', {
currentTarget: {
files: [{ name: 'longFileName.something.png' }],
},
});
expect(wrapper.find({ 'aria-label': 'File name' }).exists()).toBeTruthy();
// Trim file name longer than 16 chars
expect(wrapper.find({ 'aria-label': 'File name' }).text()).toEqual('longFileName.som....png');
// Keep the name below the length limit intact
wrapper.find('input').simulate('change', {
currentTarget: {
files: [{ name: 'longFileName.png' }],
},
});
expect(wrapper.find({ 'aria-label': 'File name' }).text()).toEqual('longFileName.png');
});
});