import * as React from 'react';
import { shallow } from 'enzyme';
import Badge from '@atlaskit/badge';
import Lozenge from '@atlaskit/lozenge';
import { ImageIcon } from '../../../../../BlockCard/ImageIcon';
import Widgets from '../..';
import { WidgetDetails, Title, Text } from '../../styled';
describe('Widgets', () => {
it('should render zero details as null', () => {
const element = shallow();
expect(element.getElement()).toBeNull();
});
it('should render a title and some text', () => {
const element = shallow(
,
);
expect(
element
.find(WidgetDetails)
.render()
.text(),
).toEqual('Modified:03/10/1990');
});
it('should render an icon', () => {
const element = shallow(
,
);
const icon = element.find(ImageIcon);
expect(icon).toHaveLength(1);
expect(icon.props()).toEqual(
expect.objectContaining({
src: 'https://www.example.com/foobar.jpg',
}),
);
});
it('should render a badge', () => {
const element = shallow(
,
);
const badge = element.find(Badge);
expect(badge).toHaveLength(1);
expect(badge.props()).toEqual(
expect.objectContaining({
appearance: 'default',
max: 99,
value: 12,
}),
);
});
it('should render a lozenge', () => {
const element = shallow(
,
);
const lozenge = element.find(Lozenge);
expect(lozenge).toHaveLength(1);
expect(lozenge.props()).toEqual(
expect.objectContaining({
appearance: 'success',
children: 'Closed',
isBold: false,
}),
);
});
it('should render widget details in order', () => {
const element = shallow(
,
);
const details = element.find(WidgetDetails).children();
expect(details.at(0).type()).toEqual(Title);
expect(details.at(1).type()).toEqual(ImageIcon);
expect(details.at(2).type()).toEqual(Badge);
expect(details.at(3).type()).toEqual(Lozenge);
expect(details.at(4).type()).toEqual(Text);
});
it('should render a number of widgets', () => {
const element = shallow(
,
);
const widgets = element.find(WidgetDetails);
expect(
widgets.at(0).contains(
Modified:),
).toBeTruthy();
expect(
widgets.at(0).contains(03/10/1990),
).toBeTruthy();
expect(
widgets
.at(1)
.contains(
,
),
).toBeTruthy();
expect(
widgets.at(2).contains(Closed),
).toBeTruthy();
expect(
widgets
.at(3)
.contains(),
).toBeTruthy();
});
});