2020-09-05 09:49:18 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
|
|
|
import { Mock } from 'ts-mockery';
|
2019-03-04 20:14:45 +03:00
|
|
|
import VisitsHeader from '../../src/visits/VisitsHeader';
|
2020-09-05 09:49:18 +03:00
|
|
|
import { Visit } from '../../src/visits/types';
|
2018-09-08 10:31:44 +03:00
|
|
|
|
|
|
|
describe('<VisitsHeader />', () => {
|
2020-09-05 09:49:18 +03:00
|
|
|
let wrapper: ShallowWrapper;
|
|
|
|
const visits = [ Mock.all<Visit>(), Mock.all<Visit>(), Mock.all<Visit>() ];
|
2020-05-10 20:37:00 +03:00
|
|
|
const title = 'My header title';
|
2020-04-26 11:43:00 +03:00
|
|
|
const goBack = jest.fn();
|
2018-09-08 10:31:44 +03:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-05-10 20:37:00 +03:00
|
|
|
wrapper = shallow(
|
2020-08-22 09:10:31 +03:00
|
|
|
<VisitsHeader visits={visits} goBack={goBack} title={title} />,
|
2020-05-10 20:37:00 +03:00
|
|
|
);
|
2018-09-08 10:31:44 +03:00
|
|
|
});
|
2020-05-10 20:37:00 +03:00
|
|
|
|
2018-09-08 10:31:44 +03:00
|
|
|
afterEach(() => wrapper.unmount());
|
2020-05-10 20:37:00 +03:00
|
|
|
afterEach(jest.resetAllMocks);
|
2018-09-08 10:31:44 +03:00
|
|
|
|
|
|
|
it('shows the amount of visits', () => {
|
|
|
|
const visitsBadge = wrapper.find('.badge');
|
|
|
|
|
2020-04-18 11:50:01 +03:00
|
|
|
expect(visitsBadge.html()).toContain(
|
2020-08-22 09:10:31 +03:00
|
|
|
`Visits: <span><strong class="short-url-visits-count__amount">${visits.length}</strong></span>`,
|
2020-04-18 11:50:01 +03:00
|
|
|
);
|
2018-09-08 10:31:44 +03:00
|
|
|
});
|
|
|
|
|
2020-05-10 20:37:00 +03:00
|
|
|
it('shows the title in two places', () => {
|
|
|
|
const titles = wrapper.find('.text-center');
|
2018-09-08 10:31:44 +03:00
|
|
|
|
2020-05-10 20:37:00 +03:00
|
|
|
expect(titles).toHaveLength(2);
|
|
|
|
expect(titles.at(0).html()).toContain(title);
|
|
|
|
expect(titles.at(1).html()).toContain(title);
|
2018-09-08 10:31:44 +03:00
|
|
|
});
|
|
|
|
});
|