import React from 'react';
import { Page, RouteList, Router, RouterContext, useFirstPageCheck, useLocation } from '..';
import { act, cleanup, render } from '@testing-library/react';
describe('hook', () => {
afterEach(() => {
cleanup();
window.history.replaceState({}, '', '/#');
});
function Main() {
const router = useLocation();
const first = useFirstPageCheck(true);
return {`Hello world: ${router.getPanelId()} ${first ? 'first_page' : ''}`};
}
test('use router with hook', () => {
const list: RouteList = {
'/': new Page('panel_main'),
'/user': new Page('panel_user'),
};
const router = new Router(list);
router.start();
const component = render(
,
);
expect(component.queryByText(/panel_main/i)).toBeTruthy();
expect(component.queryByText(/first_page/i)).toBeTruthy();
act(() => {
router.pushPage('/user');
});
expect(component.queryByText(/panel_user/i)).toBeTruthy();
expect(component.queryByText(/first_page/i)).toBeFalsy();
});
});