making profile test more functional

This commit is contained in:
balzack 2022-12-31 11:40:25 -08:00
parent a0ccc11775
commit a6b13a77c8

View File

@ -3,11 +3,13 @@ import {render, act, screen, waitFor, fireEvent} from '@testing-library/react'
import { ProfileContextProvider, ProfileContext } from 'context/ProfileContext';
import * as fetchUtil from 'api/fetchUtil';
let profileContext = null;
function ProfileView() {
const profile = useContext(ProfileContext);
profileContext = profile;
return (
<div data-testid="profile" profile={profile}>
<div>
<span data-testid="guid">{ profile.state.profile?.guid }</span>
<span data-testid="handle">{ profile.state.profile?.handle }</span>
<span data-testid="name">{ profile.state.profile?.name }</span>
@ -55,10 +57,24 @@ afterEach(() => {
test('testing', async () => {
render(<ProfileTestApp />);
await waitFor(async () => {
expect(profileContext).not.toBe(null);
});
await waitFor(async () => {
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");
});
});