shlink-web-client/test/visits/VisitsHeader.test.tsx

38 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-09-08 10:31:44 +03:00
import React from 'react';
2020-09-05 09:49:18 +03:00
import { shallow, ShallowWrapper } from 'enzyme';
import { Mock } from 'ts-mockery';
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>() ];
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(() => {
wrapper = shallow(
2020-08-22 09:10:31 +03:00
<VisitsHeader visits={visits} goBack={goBack} title={title} />,
);
2018-09-08 10:31:44 +03:00
});
2018-09-08 10:31:44 +03:00
afterEach(() => wrapper.unmount());
afterEach(jest.resetAllMocks);
2018-09-08 10:31:44 +03:00
it('shows the amount of visits', () => {
const visitsBadge = wrapper.find('.badge');
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>`,
);
2018-09-08 10:31:44 +03:00
});
it('shows the title in two places', () => {
const titles = wrapper.find('.text-center');
2018-09-08 10:31:44 +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
});
});