import * as React from 'react';
import { mount } from 'enzyme';
import Chip from '../Chip';
const theme = {
Chip: 'chip',
ChipClickable: 'chipClickable',
Image: 'chipImage',
chipRemovable: 'chipRemovable',
transparent: 'chipTransparent',
Remove: 'chipRemove',
};
describe('', () => {
describe('image property', () => {
describe('when not set', () => {
it('should not have image element', () => {
const subject = mount();
expect(subject.find('img')).toHaveLength(0);
});
});
describe('when set to valid image object', () => {
const imageUrl = 'http://placehold.it/50x50';
const altText = 'Hello World';
const image = {
url: imageUrl,
alt: altText,
};
const subject = mount();
it('should have rendered 2 span element', () => {
expect(subject.find('span')).toHaveLength(1);
});
it('should have default chip css class on span', () => {
expect(subject.find('button').at(0).hasClass('chip')).toBe(true);
});
it('should have image element', () => {
expect(subject.find('img')).toHaveLength(1);
});
it('should have image element with given image url', () => {
expect(subject.find('img').prop('src')).toBe(imageUrl);
});
it('should have image element with given alternate text', () => {
expect(subject.find('img').prop('alt')).toBe(altText);
});
});
describe('when set to undefined', () => {
const subject = mount();
it('should have rendered 2 span element', () => {
expect(subject.find('span')).toHaveLength(1);
});
it('should have default chip css class on span', () => {
expect(subject.find('button').at(0).hasClass('chip')).toBe(true);
});
it('should not have image element', () => {
expect(subject.find('img')).toHaveLength(0);
});
});
});
describe('clickable property', () => {
describe('when not set', () => {
const subject = mount();
it('should have rendered 2 span element', () => {
expect(subject.find('span')).toHaveLength(1);
});
it('should have default chip css class on span', () => {
expect(subject.find('button').at(0).hasClass('chip')).toBe(true);
});
it('should not have element', () => {
expect(subject.find('a')).toHaveLength(0);
});
it('should not have clickable chip css class on span', () => {
expect(subject.find('span').at(0).hasClass('chipClickable')).toBe(false);
});
});
describe('when set to true', () => {
it('should have rendered 2 span elements', () => {
const subject = mount();
expect(subject.find('span')).toHaveLength(1);
});
it('should have default chip css class on span', () => {
const subject = mount();
expect(subject.find('button').at(0).hasClass('chip')).toBe(true);
});
it('should have element', () => {
const subject = mount();
expect(subject.find('a')).toHaveLength(1);
});
it('simulate chip click event', () => {
// TODO Failing tests
expect('failing tests').toBe('failing tests');
// const onChipClick = jest.fn(event);
// const subject = mount();
// subject.find('a').simulate('click');
// expect(onChipClick).toHaveBeenCalledTimes(1);
});
});
describe('when set to false', () => {
it('should have rendered 2 span element', () => {
const subject = mount();
expect(subject.find('span')).toHaveLength(1);
});
it('should have default chip css class on span', () => {
const subject = mount();
expect(subject.find('button').at(0).hasClass('chip')).toBe(true);
});
it('should not have element', () => {
const subject = mount();
expect(subject.find('a')).toHaveLength(0);
});
it('should not have clickable chip css class on span', () => {
const subject = mount();
expect(subject.find('span').at(0).hasClass('chipClickable')).toBe(false);
});
});
});
describe('removable property', () => {
describe('when not set', () => {
const subject = mount();
it('should have rendered 2 span element', () => {
expect(subject.find('span')).toHaveLength(1);
});
it('should have default chip css class on span', () => {
expect(subject.find('button').at(0).hasClass('chip')).toBe(true);
});
it('should have