From 66cfd97620c6bd4be04cc5c38da8b87d0f559c2f Mon Sep 17 00:00:00 2001 From: balzack Date: Mon, 2 Jan 2023 15:46:08 -0800 Subject: [PATCH] fixing mobile test --- .../src/context/useProfileContext.hook.js | 8 ++--- app/mobile/test/Profile.test.js | 34 +++++++++++++------ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/app/mobile/src/context/useProfileContext.hook.js b/app/mobile/src/context/useProfileContext.hook.js index 65a1f2ba..20126ea2 100644 --- a/app/mobile/src/context/useProfileContext.hook.js +++ b/app/mobile/src/context/useProfileContext.hook.js @@ -30,10 +30,10 @@ export function useProfileContext() { const revision = curRevision.current; const { server, appToken, guid } = session.current; 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.setProfileRevision(guid, revision); - updateState({ identity, imageUrl: getProfileImageUrl(server, appToken, revision) }); + updateState({ identity, imageUrl }); setRevision.current = revision; } catch(err) { @@ -52,7 +52,7 @@ export function useProfileContext() { const { guid, server, appToken } = access; const identity = await store.actions.getProfile(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 }); setRevision.current = revision; curRevision.current = revision; @@ -60,7 +60,7 @@ export function useProfileContext() { }, clearSession: () => { session.current = {}; - updateState({ profile: {} }); + updateState({ identity: {}, imageUrl: null }); }, setRevision: (rev) => { curRevision.current = rev; diff --git a/app/mobile/test/Profile.test.js b/app/mobile/test/Profile.test.js index 00ca2ff3..70cc2eac 100644 --- a/app/mobile/test/Profile.test.js +++ b/app/mobile/test/Profile.test.js @@ -10,16 +10,16 @@ function ProfileView() { return ( - { profile.state.profile?.guid } - { profile.state.profile?.handle } - { profile.state.profile?.name } - { profile.state.profile?.description } - { profile.state.profile?.location } - { profile.state.profile?.image } - { profile.state.profile?.revision } - { profile.state.profile?.seal } - { profile.state.profile?.version } - { profile.state.profile?.node } + { profile.state.identity?.guid } + { profile.state.identity?.handle } + { profile.state.identity?.name } + { profile.state.identity?.description } + { profile.state.identity?.location } + { profile.state.identity?.image } + { profile.state.identity?.revision } + { profile.state.identity?.seal } + { profile.state.identity?.version } + { profile.state.identity?.node } { profile.state.imageUrl } ); @@ -82,13 +82,14 @@ test('testing', async () => { }); await act(async () => { - identity = { name: 'tester' }; + identity = { name: 'tester', image: 'abc123' }; const profile = screen.getByTestId('profile').props.profile; await profile.actions.setRevision(2); }); await waitFor(async () => { 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 () => { @@ -99,6 +100,7 @@ test('testing', async () => { await waitFor(async () => { 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 () => { @@ -121,6 +123,16 @@ test('testing', async () => { 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 () => { const profile = screen.getByTestId('profile').props.profile; for (let i = 0; i < 1024; i++) {