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

48 lines
2.1 KiB
TypeScript
Raw Normal View History

2021-02-28 12:36:56 +03:00
import { shallow } from 'enzyme';
import { Mock } from 'ts-mockery';
import { History, Location } from 'history';
import { match } from 'react-router'; // eslint-disable-line @typescript-eslint/no-unused-vars
2021-03-14 14:49:12 +03:00
import { OrphanVisits as createOrphanVisits } from '../../src/visits/OrphanVisits';
2021-02-28 12:36:56 +03:00
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
import { VisitsInfo } from '../../src/visits/types';
import VisitsStats from '../../src/visits/VisitsStats';
import { OrphanVisitsHeader } from '../../src/visits/OrphanVisitsHeader';
import { Settings } from '../../src/settings/reducers/settings';
2021-03-14 14:49:12 +03:00
import { VisitsExporter } from '../../src/visits/services/VisitsExporter';
2021-06-13 12:54:51 +03:00
import { SelectedServer } from '../../src/servers/data';
2021-02-28 12:36:56 +03:00
describe('<OrphanVisits />', () => {
it('wraps visits stats and header', () => {
const goBack = jest.fn();
const getOrphanVisits = jest.fn();
const cancelGetOrphanVisits = jest.fn();
const orphanVisits = Mock.all<VisitsInfo>();
2021-03-14 14:49:12 +03:00
const OrphanVisits = createOrphanVisits(Mock.all<VisitsExporter>());
2021-02-28 12:36:56 +03:00
const wrapper = shallow(
<OrphanVisits
{...Mock.of<MercureBoundProps>({ mercureInfo: {} })}
getOrphanVisits={getOrphanVisits}
orphanVisits={orphanVisits}
cancelGetOrphanVisits={cancelGetOrphanVisits}
history={Mock.of<History>({ goBack })}
location={Mock.all<Location>()}
match={Mock.of<match>({ url: 'the_base_url' })}
settings={Mock.all<Settings>()}
2021-06-13 12:54:51 +03:00
selectedServer={Mock.all<SelectedServer>()}
2021-02-28 12:36:56 +03:00
/>,
).dive();
const stats = wrapper.find(VisitsStats);
const header = wrapper.find(OrphanVisitsHeader);
expect(stats).toHaveLength(1);
expect(header).toHaveLength(1);
expect(stats.prop('getVisits')).toEqual(getOrphanVisits);
expect(stats.prop('cancelGetVisits')).toEqual(cancelGetOrphanVisits);
expect(stats.prop('visitsInfo')).toEqual(orphanVisits);
expect(stats.prop('baseUrl')).toEqual('the_base_url');
expect(header.prop('orphanVisits')).toEqual(orphanVisits);
expect(header.prop('goBack')).toEqual(goBack);
});
});