-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
98 changed files
with
939 additions
and
1,691 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 128 additions & 60 deletions
188
extensions/apps/antenna/src/components/__tests__/beam-page.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,158 @@ | ||
import React from 'react'; | ||
import BeamPage from '../pages/entry-page/beam-page'; | ||
import * as apolloHooks from '@akashaorg/ui-awf-hooks/lib/generated/apollo'; | ||
import * as useBeamsHook from '@akashaorg/ui-awf-hooks/lib/use-beams'; | ||
import * as useReflectionsHook from '@akashaorg/ui-awf-hooks/lib/use-reflections'; | ||
|
||
import { | ||
screen, | ||
renderWithAllProviders, | ||
act, | ||
genAppProps, | ||
genBeamData, | ||
genUser, | ||
waitFor, | ||
genContentBlock, | ||
genReflectionStream, | ||
genProfileByDID, | ||
} from '@akashaorg/af-testing'; | ||
import { AnalyticsProvider } from '@akashaorg/ui-awf-hooks/lib/use-analytics'; | ||
import { AkashaBeamStreamModerationStatus } from '@akashaorg/typings/lib/sdk/graphql-types-new'; | ||
import { mapBeamEntryData } from '@akashaorg/ui-awf-hooks'; | ||
import { | ||
GetProfileByDidDocument, | ||
GetContentBlockByIdDocument, | ||
GetReflectionStreamDocument, | ||
GetBeamByIdDocument, | ||
} from '@akashaorg/ui-awf-hooks/lib/generated/apollo'; | ||
import { formatRelativeTime, truncateDid } from '@akashaorg/design-system-core/lib/utils'; | ||
import { getReflectionFeedMocks } from '@akashaorg/ui-lib-feed/lib/__tests__/__mocks__/get-reflection-feed-mocks'; | ||
|
||
class ResizeObserver { | ||
observe() { | ||
return; | ||
} | ||
unobserve() { | ||
return; | ||
} | ||
disconnect() { | ||
return; | ||
} | ||
} | ||
const BEAM_SECTION = { | ||
profileDID: 'did:pkh:eip155:11155111:0x1d3ac7a3d118f60a726f2dc52a614b2a6ae8dd00', | ||
beamId: 'kjzl6kcym7w8y5coci0at0tquy8zmferlog88ys14oj2qgyjy8soxzpbflmlzey', | ||
reflectionId: 'kjzl6kcym7w8y4wm6o3ikwiwttnsr6f7g0tkpqojlwsmp2r9wehvfapuvkfqqjn', | ||
content: 'Beam', | ||
}; | ||
|
||
const REFLECT_FEED = { | ||
authorProfileDID: 'did:pkh:eip155:11155111:0x404ea3f8e4a5fcc8bdcdb7a74f25357113fdf989', | ||
beamId: BEAM_SECTION.beamId, | ||
reflectionId: 'kjzl6kcym7w8yaknlainhkpejftbsmffx9799hf1nrmkptk2gvqi7t27d3rp1ve', | ||
content: 'Reflection', | ||
preview: { | ||
reflectionId: 'kjzl6kcym7w8y70ra8llsn1l6qi4iy9d5g1acypb2uh9bl1bw479h92gygkmze3', | ||
content: 'Reflection Preview', | ||
}, | ||
}; | ||
|
||
describe('< BeamPage /> component', () => { | ||
global.ResizeObserver = ResizeObserver; | ||
const beamData = genBeamData({ | ||
beamId: BEAM_SECTION.beamId, | ||
authorProfileDID: BEAM_SECTION.profileDID, | ||
}); | ||
const profileData = genProfileByDID(BEAM_SECTION.profileDID); | ||
const BaseComponent = ( | ||
<AnalyticsProvider {...genAppProps()}> | ||
<BeamPage | ||
beamStream={{}} | ||
beam={{ node: genBeamData() }} | ||
beamId={'kjzl6kcym7w8y5coci0at0tquy8zmferlog99ys94oj2qgyjy8soxzpbflmlzey'} | ||
beamStatus={AkashaBeamStreamModerationStatus.Ok} | ||
entryData={mapBeamEntryData(beamData)} | ||
beamId={BEAM_SECTION.beamId} | ||
/> | ||
</AnalyticsProvider> | ||
); | ||
|
||
beforeEach(async () => { | ||
await act(async () => { | ||
renderWithAllProviders(BaseComponent, {}); | ||
renderWithAllProviders( | ||
BaseComponent, | ||
{}, | ||
{ | ||
mocks: [ | ||
{ | ||
request: { | ||
query: GetProfileByDidDocument, | ||
}, | ||
variableMatcher: () => true, | ||
result: { | ||
data: { | ||
node: profileData, | ||
}, | ||
}, | ||
}, | ||
{ | ||
request: { | ||
query: GetBeamByIdDocument, | ||
}, | ||
variableMatcher: () => true, | ||
result: { | ||
data: { | ||
node: genBeamData({ | ||
beamId: BEAM_SECTION.beamId, | ||
authorProfileDID: BEAM_SECTION.profileDID, | ||
reflectionsCount: BEAM_SECTION.reflectionCount, | ||
}), | ||
}, | ||
}, | ||
}, | ||
...beamData.content.map(block => ({ | ||
request: { | ||
query: GetContentBlockByIdDocument, | ||
}, | ||
variableMatcher: () => true, | ||
result: { | ||
data: { | ||
node: genContentBlock({ | ||
blockId: block.blockID, | ||
authorProfileDID: BEAM_SECTION.profileDID, | ||
content: BEAM_SECTION.content, | ||
}), | ||
}, | ||
}, | ||
})), | ||
{ | ||
request: { | ||
query: GetReflectionStreamDocument, | ||
}, | ||
variableMatcher: () => true, | ||
result: { | ||
data: { | ||
node: genReflectionStream({ | ||
beamId: BEAM_SECTION.beamId, | ||
reflectionId: BEAM_SECTION.reflectionId, | ||
}), | ||
}, | ||
}, | ||
}, | ||
...getReflectionFeedMocks({ | ||
beamId: REFLECT_FEED.beamId, | ||
reflectionId: REFLECT_FEED.preview.reflectionId, | ||
authorProfileDID: REFLECT_FEED.authorProfileDID, | ||
reflectionContent: REFLECT_FEED.content, | ||
reflectionPreviewContent: REFLECT_FEED.preview.content, | ||
}), | ||
], | ||
}, | ||
); | ||
}); | ||
}); | ||
|
||
beforeAll(() => { | ||
( | ||
jest.spyOn(apolloHooks, 'useGetReflectReflectionsLazyQuery') as unknown as jest.SpyInstance< | ||
[ | ||
typeof jest.fn, | ||
{ | ||
data: unknown; | ||
isLoading: boolean; | ||
}, | ||
] | ||
> | ||
).mockReturnValue([ | ||
jest.fn().mockReturnValue({ data: undefined }), | ||
{ data: {}, isLoading: false }, | ||
]); | ||
( | ||
jest.spyOn(apolloHooks, 'useGetMyProfileQuery') as unknown as jest.SpyInstance<{ | ||
data: { viewer: { akashaProfile: ReturnType<typeof genUser> } }; | ||
}> | ||
).mockReturnValue({ | ||
data: { | ||
viewer: { | ||
akashaProfile: genUser('did:pkh:eip155:5:0xc47a483494db8fe455ba29a53a7f75349dfc02ff'), | ||
}, | ||
}, | ||
//TODO add test case for publishing reflection | ||
it('should render beam section', async () => { | ||
await waitFor(() => { | ||
expect(screen.getAllByTestId('info-box')[0]).toHaveTextContent( | ||
profileData.akashaProfile.name, | ||
); | ||
expect(screen.getAllByTestId('info-box')[0]).toHaveTextContent( | ||
truncateDid(profileData.akashaProfile.did.id), | ||
); | ||
expect(screen.getAllByTestId('info-box')[0]).toHaveTextContent( | ||
formatRelativeTime(beamData.createdAt, 'en'), | ||
); | ||
expect(screen.getByText(/Share your thoughts/i)).toBeInTheDocument(); | ||
expect(screen.getByRole('button', { name: 'Reflect' })).toBeInTheDocument(); | ||
}); | ||
( | ||
jest.spyOn(useBeamsHook, 'useBeams') as unknown as jest.SpyInstance<{ | ||
data: unknown; | ||
}> | ||
).mockReturnValue({ data: {} }); | ||
( | ||
jest.spyOn(useReflectionsHook, 'useReflections') as unknown as jest.SpyInstance<{ | ||
reflections: unknown[]; | ||
fetchInitialData: typeof jest.fn; | ||
}> | ||
).mockReturnValue({ reflections: [], fetchInitialData: jest.fn }); | ||
}); | ||
|
||
it.skip('should render beam page', async () => { | ||
expect(screen.getByText(/Share your thoughts/i)).toBeInTheDocument(); | ||
expect(screen.getByRole('button', { name: /Reflect/i })).toBeInTheDocument(); | ||
it('should render reflect feed', async () => { | ||
await waitFor(() => { | ||
expect(screen.getByText(REFLECT_FEED.content)).toBeInTheDocument(); | ||
expect(screen.getByText(REFLECT_FEED.preview.content)).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
47 changes: 0 additions & 47 deletions
47
extensions/apps/antenna/src/components/__tests__/global-antenna-page.spec.tsx
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
extensions/apps/antenna/src/components/__tests__/pending-reflect.spec.tsx
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
extensions/apps/antenna/src/components/__tests__/reflection-page.spec.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.