adding additional create account nav test

This commit is contained in:
balzack 2023-02-16 16:31:03 -08:00
parent d88dc97c9e
commit 4ac6a4a76e
2 changed files with 47 additions and 16 deletions

View File

@ -9,6 +9,7 @@ import { CardContextProvider } from 'context/CardContext';
import { StoreContext } from 'context/StoreContext'; import { StoreContext } from 'context/StoreContext';
import { useTestStoreContext } from 'context/useTestStoreContext.hook'; import { useTestStoreContext } from 'context/useTestStoreContext.hook';
import { useLogin } from 'src/access/login/useLogin.hook'; import { useLogin } from 'src/access/login/useLogin.hook';
import { useCreate } from 'src/access/create/useCreate.hook';
import * as fetchUtil from 'api/fetchUtil'; import * as fetchUtil from 'api/fetchUtil';
let navPath; let navPath;
@ -18,8 +19,8 @@ jest.mock('react-router-dom', () => ({
useLocation: () => { return 'path' }, useLocation: () => { return 'path' },
})); }));
function AccessView() { function AccessView({ mode }) {
const { state, actions } = useLogin(); const { state, actions } = (mode === 'login') ? useLogin() : useCreate();
const app = useContext(AppContext); const app = useContext(AppContext);
const [session, setSession] = useState(); const [session, setSession] = useState();
@ -34,18 +35,18 @@ function AccessView() {
); );
} }
function AccessTestApp() { function AccessTestApp({ mode }) {
return ( return (
<AccountContextProvider> <AccountContextProvider>
<ProfileContextProvider> <ProfileContextProvider>
<ChannelContextProvider> <ChannelContextProvider>
<CardContextProvider> <CardContextProvider>
<AppContextProvider> <AppContextProvider>
<AccessView /> <AccessView mode={mode} />
</AppContextProvider> </AppContextProvider>
</CardContextProvider> </CardContextProvider>
</ChannelContextProvider> </ChannelContextProvider>
</ProfileContextProvider> </ProfileContextProvider>
</AccountContextProvider> </AccountContextProvider>
); );
} }
@ -55,9 +56,13 @@ function MockWebsocket(url) {
this.url = url; this.url = url;
this.sent = false; this.sent = false;
this.send = (msg) => { this.sent = true }; this.send = (msg) => { this.sent = true };
this.close = () => {};
}; };
jest.mock('@react-native-firebase/messaging', () => () => ({ getToken: async () => '##' })); jest.mock('@react-native-firebase/messaging', () => () => ({
deleteToken: async () => {},
getToken: async () => '##'
}));
jest.mock('react-native-device-info', () => ({ jest.mock('react-native-device-info', () => ({
getVersion: () => '##', getVersion: () => '##',
@ -84,6 +89,8 @@ beforeEach(() => {
React.useContext = mockUseContext; React.useContext = mockUseContext;
const mockFetch = jest.fn().mockImplementation((url, options) => { const mockFetch = jest.fn().mockImplementation((url, options) => {
console.log(url);
return Promise.resolve({ return Promise.resolve({
json: () => Promise.resolve({ json: () => Promise.resolve({
guid: '123', guid: '123',
@ -105,8 +112,30 @@ afterEach(() => {
fetchUtil.fetchWithCustomTimeout = realFetchWithCustomTimeout; fetchUtil.fetchWithCustomTimeout = realFetchWithCustomTimeout;
}); });
test('nav to session after create', async () => {
render(<AccessTestApp mode="create" />);
await waitFor(async () => {
expect(screen.getByTestId('session').props.children).toBe(false);
});
await act(async () => {
const app = screen.getByTestId('access').props.app;
await app.actions.create('test.org', 'testusername', 'testpassword', 'secret');
});
await waitFor(async () => {
expect(navPath).toBe('/session');
});
await waitFor(async () => {
expect(screen.getByTestId('session').props.children).toBe(true);
});
});
test('nav to session after login', async () => { test('nav to session after login', async () => {
render(<AccessTestApp />); render(<AccessTestApp mode="login" />);
await waitFor(async () => { await waitFor(async () => {
expect(screen.getByTestId('session').props.children).toBe(false); expect(screen.getByTestId('session').props.children).toBe(false);
@ -124,7 +153,6 @@ test('nav to session after login', async () => {
await waitFor(async () => { await waitFor(async () => {
expect(screen.getByTestId('session').props.children).toBe(true); expect(screen.getByTestId('session').props.children).toBe(true);
}); });
}); });

View File

@ -61,6 +61,9 @@ export function useCreate() {
}, [state]); }, [state]);
useEffect(() => { useEffect(() => {
if (!count) {
return;
}
if (checking.current) { if (checking.current) {
backoff.current = true; backoff.current = true;
} }