extending profile test

This commit is contained in:
balzack 2023-01-02 17:49:43 -08:00
parent 66cfd97620
commit 36685f6051
2 changed files with 39 additions and 2 deletions

View File

@ -6,10 +6,15 @@ import { ProfileContextProvider, ProfileContext } from 'context/ProfileContext';
import * as fetchUtil from 'api/fetchUtil';
function ProfileView() {
const [renderCount, setRenderCount] = useState(0);
const profile = useContext(ProfileContext);
useEffect(() => {
setRenderCount(renderCount + 1);
}, [profile.state]);
return (
<View testID="profile" profile={profile}>
<View testID="profile" profile={profile} renderCount={renderCount}>
<Text testID="guid">{ profile.state.identity?.guid }</Text>
<Text testID="handle">{ profile.state.identity?.handle }</Text>
<Text testID="name">{ profile.state.identity?.name }</Text>
@ -155,6 +160,20 @@ test('testing', async () => {
expect(screen.getByTestId('name').props.children).toBe("vesper");
});
const renderCount = screen.getByTestId('profile').props.renderCount;
console.log("RENDER COUNT:", renderCount);
await act(async () => {
identity = { name: 'renderer' };
const profile = screen.getByTestId('profile').props.profile;
await profile.actions.setRevision(2048);
});
console.log(renderCount);
await act(async () => {
expect(screen.getByTestId('profile').props.renderCount).toBe(renderCount + 1);
});
});

View File

@ -5,11 +5,17 @@ import * as fetchUtil from 'api/fetchUtil';
let profileContext = null;
function ProfileView() {
const [renderCount, setRenderCount] = useState(0);
const profile = useContext(ProfileContext);
profileContext = profile;
useEffect(() => {
setRenderCount(renderCount + 1);
}, [profile.state]);
return (
<div>
<span data-testid="count">{ renderCount }</span>
<span data-testid="guid">{ profile.state.identity?.guid }</span>
<span data-testid="handle">{ profile.state.identity?.handle }</span>
<span data-testid="name">{ profile.state.identity?.name }</span>
@ -84,6 +90,19 @@ test('testing', async () => {
expect(screen.getByTestId('name').textContent).toBe("tester");
});
const count = screen.getByTestId('count').textContent;
await act(async () => {
identity = { name: 'renderer' };
await profileContext.actions.setRevision(3);
});
await waitFor(async () => {
const renderCount = parseInt(screen.getByTestId('count').textContent);
const nextCount = parseInt(count) + 1;
expect(nextCount).toBe(renderCount);
});
await act(async () => {
await profileContext.actions.clearToken();
});
@ -92,7 +111,6 @@ test('testing', async () => {
expect(screen.getByTestId('name').textContent).toBe("");
});
});