mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 20:49:16 +00:00
extending profile test
This commit is contained in:
parent
66cfd97620
commit
36685f6051
@ -6,10 +6,15 @@ import { ProfileContextProvider, ProfileContext } from 'context/ProfileContext';
|
|||||||
import * as fetchUtil from 'api/fetchUtil';
|
import * as fetchUtil from 'api/fetchUtil';
|
||||||
|
|
||||||
function ProfileView() {
|
function ProfileView() {
|
||||||
|
const [renderCount, setRenderCount] = useState(0);
|
||||||
const profile = useContext(ProfileContext);
|
const profile = useContext(ProfileContext);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setRenderCount(renderCount + 1);
|
||||||
|
}, [profile.state]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View testID="profile" profile={profile}>
|
<View testID="profile" profile={profile} renderCount={renderCount}>
|
||||||
<Text testID="guid">{ profile.state.identity?.guid }</Text>
|
<Text testID="guid">{ profile.state.identity?.guid }</Text>
|
||||||
<Text testID="handle">{ profile.state.identity?.handle }</Text>
|
<Text testID="handle">{ profile.state.identity?.handle }</Text>
|
||||||
<Text testID="name">{ profile.state.identity?.name }</Text>
|
<Text testID="name">{ profile.state.identity?.name }</Text>
|
||||||
@ -155,6 +160,20 @@ test('testing', async () => {
|
|||||||
expect(screen.getByTestId('name').props.children).toBe("vesper");
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,11 +5,17 @@ import * as fetchUtil from 'api/fetchUtil';
|
|||||||
|
|
||||||
let profileContext = null;
|
let profileContext = null;
|
||||||
function ProfileView() {
|
function ProfileView() {
|
||||||
|
const [renderCount, setRenderCount] = useState(0);
|
||||||
const profile = useContext(ProfileContext);
|
const profile = useContext(ProfileContext);
|
||||||
profileContext = profile;
|
profileContext = profile;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setRenderCount(renderCount + 1);
|
||||||
|
}, [profile.state]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
<span data-testid="count">{ renderCount }</span>
|
||||||
<span data-testid="guid">{ profile.state.identity?.guid }</span>
|
<span data-testid="guid">{ profile.state.identity?.guid }</span>
|
||||||
<span data-testid="handle">{ profile.state.identity?.handle }</span>
|
<span data-testid="handle">{ profile.state.identity?.handle }</span>
|
||||||
<span data-testid="name">{ profile.state.identity?.name }</span>
|
<span data-testid="name">{ profile.state.identity?.name }</span>
|
||||||
@ -84,6 +90,19 @@ test('testing', async () => {
|
|||||||
expect(screen.getByTestId('name').textContent).toBe("tester");
|
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 act(async () => {
|
||||||
await profileContext.actions.clearToken();
|
await profileContext.actions.clearToken();
|
||||||
});
|
});
|
||||||
@ -92,7 +111,6 @@ test('testing', async () => {
|
|||||||
expect(screen.getByTestId('name').textContent).toBe("");
|
expect(screen.getByTestId('name').textContent).toBe("");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user