fixing mobile test

This commit is contained in:
balzack 2023-01-02 15:46:08 -08:00
parent c0cd0660b1
commit 66cfd97620
2 changed files with 27 additions and 15 deletions

View File

@ -30,10 +30,10 @@ export function useProfileContext() {
const revision = curRevision.current; const revision = curRevision.current;
const { server, appToken, guid } = session.current; const { server, appToken, guid } = session.current;
const identity = await getProfile(server, appToken); const identity = await getProfile(server, appToken);
const imageUrl = identity.image ? getProfileImageUrl(server, appToken, revision) : null; const imageUrl = identity?.image ? getProfileImageUrl(server, appToken, revision) : null;
await store.actions.setProfile(guid, identity); await store.actions.setProfile(guid, identity);
await store.actions.setProfileRevision(guid, revision); await store.actions.setProfileRevision(guid, revision);
updateState({ identity, imageUrl: getProfileImageUrl(server, appToken, revision) }); updateState({ identity, imageUrl });
setRevision.current = revision; setRevision.current = revision;
} }
catch(err) { catch(err) {
@ -52,7 +52,7 @@ export function useProfileContext() {
const { guid, server, appToken } = access; const { guid, server, appToken } = access;
const identity = await store.actions.getProfile(guid); const identity = await store.actions.getProfile(guid);
const revision = await store.actions.getProfileRevision(guid); const revision = await store.actions.getProfileRevision(guid);
const imageUrl = identity.image ? getProfileImageUrl(server, appToken, revision) : null; const imageUrl = identity?.image ? getProfileImageUrl(server, appToken, revision) : null;
updateState({ identity, imageUrl }); updateState({ identity, imageUrl });
setRevision.current = revision; setRevision.current = revision;
curRevision.current = revision; curRevision.current = revision;
@ -60,7 +60,7 @@ export function useProfileContext() {
}, },
clearSession: () => { clearSession: () => {
session.current = {}; session.current = {};
updateState({ profile: {} }); updateState({ identity: {}, imageUrl: null });
}, },
setRevision: (rev) => { setRevision: (rev) => {
curRevision.current = rev; curRevision.current = rev;

View File

@ -10,16 +10,16 @@ function ProfileView() {
return ( return (
<View testID="profile" profile={profile}> <View testID="profile" profile={profile}>
<Text testID="guid">{ profile.state.profile?.guid }</Text> <Text testID="guid">{ profile.state.identity?.guid }</Text>
<Text testID="handle">{ profile.state.profile?.handle }</Text> <Text testID="handle">{ profile.state.identity?.handle }</Text>
<Text testID="name">{ profile.state.profile?.name }</Text> <Text testID="name">{ profile.state.identity?.name }</Text>
<Text testID="description">{ profile.state.profile?.description }</Text> <Text testID="description">{ profile.state.identity?.description }</Text>
<Text testID="location">{ profile.state.profile?.location }</Text> <Text testID="location">{ profile.state.identity?.location }</Text>
<Text testID="image">{ profile.state.profile?.image }</Text> <Text testID="image">{ profile.state.identity?.image }</Text>
<Text testID="revision">{ profile.state.profile?.revision }</Text> <Text testID="revision">{ profile.state.identity?.revision }</Text>
<Text testID="seal">{ profile.state.profile?.seal }</Text> <Text testID="seal">{ profile.state.identity?.seal }</Text>
<Text testID="version">{ profile.state.profile?.version }</Text> <Text testID="version">{ profile.state.identity?.version }</Text>
<Text testID="node">{ profile.state.profile?.node }</Text> <Text testID="node">{ profile.state.identity?.node }</Text>
<Text testID="imageUrl">{ profile.state.imageUrl }</Text> <Text testID="imageUrl">{ profile.state.imageUrl }</Text>
</View> </View>
); );
@ -82,13 +82,14 @@ test('testing', async () => {
}); });
await act(async () => { await act(async () => {
identity = { name: 'tester' }; identity = { name: 'tester', image: 'abc123' };
const profile = screen.getByTestId('profile').props.profile; const profile = screen.getByTestId('profile').props.profile;
await profile.actions.setRevision(2); await profile.actions.setRevision(2);
}); });
await waitFor(async () => { await waitFor(async () => {
expect(screen.getByTestId('name').props.children).toBe("tester"); expect(screen.getByTestId('name').props.children).toBe("tester");
expect(screen.getByTestId('imageUrl').props.children).toBe("https://test.org/profile/image?agent=123&revision=2");
}); });
await act(async () => { await act(async () => {
@ -99,6 +100,7 @@ test('testing', async () => {
await waitFor(async () => { await waitFor(async () => {
expect(screen.getByTestId('name').props.children).toBe("tester"); expect(screen.getByTestId('name').props.children).toBe("tester");
expect(screen.getByTestId('imageUrl').props.children).toBe("https://test.org/profile/image?agent=123&revision=2");
}); });
await act(async () => { await act(async () => {
@ -121,6 +123,16 @@ test('testing', async () => {
expect(screen.getByTestId('imageUrl').props.children).toBe("https://test.org/profile/image?agent=123&revision=2"); expect(screen.getByTestId('imageUrl').props.children).toBe("https://test.org/profile/image?agent=123&revision=2");
}); });
await act(async () => {
const profile = screen.getByTestId('profile').props.profile;
await profile.actions.setRevision(3);
});
await waitFor(async () => {
expect(screen.getByTestId('name').props.children).toBe("jester");
expect(screen.getByTestId('imageUrl').props.children).toBe(null);
});
await act(async () => { await act(async () => {
const profile = screen.getByTestId('profile').props.profile; const profile = screen.getByTestId('profile').props.profile;
for (let i = 0; i < 1024; i++) { for (let i = 0; i < 1024; i++) {