mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 20:49:16 +00:00
making profile test more functional
This commit is contained in:
parent
a0ccc11775
commit
a6b13a77c8
@ -3,11 +3,13 @@ import {render, act, screen, waitFor, fireEvent} from '@testing-library/react'
|
|||||||
import { ProfileContextProvider, ProfileContext } from 'context/ProfileContext';
|
import { ProfileContextProvider, ProfileContext } from 'context/ProfileContext';
|
||||||
import * as fetchUtil from 'api/fetchUtil';
|
import * as fetchUtil from 'api/fetchUtil';
|
||||||
|
|
||||||
|
let profileContext = null;
|
||||||
function ProfileView() {
|
function ProfileView() {
|
||||||
const profile = useContext(ProfileContext);
|
const profile = useContext(ProfileContext);
|
||||||
|
profileContext = profile;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div data-testid="profile" profile={profile}>
|
<div>
|
||||||
<span data-testid="guid">{ profile.state.profile?.guid }</span>
|
<span data-testid="guid">{ profile.state.profile?.guid }</span>
|
||||||
<span data-testid="handle">{ profile.state.profile?.handle }</span>
|
<span data-testid="handle">{ profile.state.profile?.handle }</span>
|
||||||
<span data-testid="name">{ profile.state.profile?.name }</span>
|
<span data-testid="name">{ profile.state.profile?.name }</span>
|
||||||
@ -55,10 +57,24 @@ afterEach(() => {
|
|||||||
test('testing', async () => {
|
test('testing', async () => {
|
||||||
render(<ProfileTestApp />);
|
render(<ProfileTestApp />);
|
||||||
|
|
||||||
|
await waitFor(async () => {
|
||||||
|
expect(profileContext).not.toBe(null);
|
||||||
|
});
|
||||||
|
|
||||||
await waitFor(async () => {
|
await waitFor(async () => {
|
||||||
expect(screen.getByTestId('name').textContent).toBe("");
|
expect(screen.getByTestId('name').textContent).toBe("");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
identity = { name: 'jester' };
|
||||||
|
await profileContext.actions.setToken({ guid: 'abc', server: 'test.org', appToken: '123' });
|
||||||
|
await profileContext.actions.setRevision(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(async () => {
|
||||||
|
expect(screen.getByTestId('name').textContent).toBe("jester");
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user