digitransit-ui/test/unit/component/Availability.test.js
2020-08-04 17:47:26 +03:00

47 lines
1.5 KiB
JavaScript

import React from 'react';
import Availability from '../../../app/component/Availability';
import { shallowWithIntl } from '../helpers/mock-intl-enzyme';
describe('<Availability />', () => {
it('should render text', () => {
const props = {
available: 1,
total: 3,
fewAvailableCount: 3,
fewerAvailableCount: 2,
text: <p className="test-text">foo</p>,
showStatusBar: true,
};
const wrapper = shallowWithIntl(<Availability {...props} />);
expect(wrapper.find('.test-text').text()).to.equal('foo');
});
it('should render status bar when showStatusBar is true', () => {
const props = {
available: 2,
total: 3,
fewAvailableCount: 2,
fewerAvailableCount: 1,
text: <p className="test-text">foo</p>,
showStatusBar: true,
};
const wrapper = shallowWithIntl(<Availability {...props} />);
expect(wrapper.find('.available-few')).to.have.lengthOf(1);
expect(wrapper.find('.available-none')).to.have.lengthOf(1);
});
it('should not render status bar when showStatusBar is false', () => {
const props = {
available: 2,
total: 3,
fewAvailableCount: 3,
fewerAvailableCount: 3,
text: <p className="test-text">foo</p>,
showStatusBar: false,
};
const wrapper = shallowWithIntl(<Availability {...props} />);
expect(wrapper.find('.available-few')).to.have.lengthOf(0);
expect(wrapper.find('.available-none')).to.have.lengthOf(0);
});
});