2022-02-05 18:37:01 +03:00
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import { Mock } from 'ts-mockery';
|
|
|
|
import { NonOrphanVisits as createNonOrphanVisits } from '../../src/visits/NonOrphanVisits';
|
|
|
|
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
|
|
|
|
import { VisitsInfo } from '../../src/visits/types';
|
|
|
|
import VisitsStats from '../../src/visits/VisitsStats';
|
|
|
|
import { Settings } from '../../src/settings/reducers/settings';
|
2022-03-13 20:56:42 +03:00
|
|
|
import { ReportExporter } from '../../src/common/services/ReportExporter';
|
2022-02-05 18:37:01 +03:00
|
|
|
import { SelectedServer } from '../../src/servers/data';
|
2022-04-30 12:00:12 +03:00
|
|
|
import VisitsHeader from '../../src/visits/VisitsHeader';
|
2022-02-05 18:37:01 +03:00
|
|
|
|
2022-02-08 00:17:57 +03:00
|
|
|
jest.mock('react-router-dom', () => ({
|
|
|
|
...jest.requireActual('react-router-dom'),
|
|
|
|
useNavigate: jest.fn().mockReturnValue(jest.fn()),
|
|
|
|
useParams: jest.fn().mockReturnValue({}),
|
|
|
|
}));
|
|
|
|
|
2022-02-05 18:37:01 +03:00
|
|
|
describe('<NonOrphanVisits />', () => {
|
|
|
|
it('wraps visits stats and header', () => {
|
|
|
|
const getNonOrphanVisits = jest.fn();
|
|
|
|
const cancelGetNonOrphanVisits = jest.fn();
|
|
|
|
const nonOrphanVisits = Mock.all<VisitsInfo>();
|
2022-03-13 20:56:42 +03:00
|
|
|
const NonOrphanVisits = createNonOrphanVisits(Mock.all<ReportExporter>());
|
2022-02-05 18:37:01 +03:00
|
|
|
|
|
|
|
const wrapper = shallow(
|
|
|
|
<NonOrphanVisits
|
|
|
|
{...Mock.of<MercureBoundProps>({ mercureInfo: {} })}
|
|
|
|
getNonOrphanVisits={getNonOrphanVisits}
|
|
|
|
nonOrphanVisits={nonOrphanVisits}
|
|
|
|
cancelGetNonOrphanVisits={cancelGetNonOrphanVisits}
|
|
|
|
settings={Mock.all<Settings>()}
|
|
|
|
selectedServer={Mock.all<SelectedServer>()}
|
|
|
|
/>,
|
|
|
|
).dive();
|
|
|
|
const stats = wrapper.find(VisitsStats);
|
2022-04-30 12:00:12 +03:00
|
|
|
const header = wrapper.find(VisitsHeader);
|
2022-02-05 18:37:01 +03:00
|
|
|
|
|
|
|
expect(stats).toHaveLength(1);
|
|
|
|
expect(header).toHaveLength(1);
|
|
|
|
expect(stats.prop('cancelGetVisits')).toEqual(cancelGetNonOrphanVisits);
|
|
|
|
expect(stats.prop('visitsInfo')).toEqual(nonOrphanVisits);
|
|
|
|
expect(stats.prop('isOrphanVisits')).not.toBeDefined();
|
2022-04-30 12:00:12 +03:00
|
|
|
expect(header.prop('visits')).toEqual(nonOrphanVisits.visits);
|
2022-02-08 00:17:57 +03:00
|
|
|
expect(header.prop('goBack')).toEqual(expect.any(Function));
|
2022-02-05 18:37:01 +03:00
|
|
|
});
|
|
|
|
});
|