Skip to content

Commit

Permalink
chore(): clean up and fix tests v1
Browse files Browse the repository at this point in the history
  • Loading branch information
didd committed Jun 6, 2024
1 parent d6cc59d commit 1fd4c7b
Show file tree
Hide file tree
Showing 98 changed files with 939 additions and 1,691 deletions.
26 changes: 4 additions & 22 deletions extensions/apps/antenna/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import './jest.setup';
import '../../jest.setup';

import { genLoggedInState } from '@akashaorg/af-testing';
import * as loginHooks from '@akashaorg/ui-awf-hooks/lib/use-login.new';
import * as mediaHooks from '@akashaorg/ui-awf-hooks/lib/utils/media-utils';

jest.mock('@akashaorg/typings/lib/ui', () => ({
EntityTypes: {
POST: 0,
BEAM: 0,
PROFILE: 1,
REPLY: 2,
REFLECT: 2,
TAG: 3,
ARTICLE: 4,
},
EventTypes: {
Instantiated: 'instantiated',
Expand Down Expand Up @@ -37,20 +36,3 @@ jest.mock('@akashaorg/typings/lib/ui', () => ({
jest
.spyOn(mediaHooks, 'getMediaUrl')
.mockReturnValue({ originLink: '', fallbackLink: '', pathLink: '' });

jest.spyOn(loginHooks, 'useGetLogin').mockReturnValue({
data: { ...genLoggedInState(true) },
status: 'success',
isSuccess: true,
reported: true,
});

const mockIntersectionObserver = jest.fn();

mockIntersectionObserver.mockReturnValue({
observe: () => null,
unobserve: () => null,
disconnect: () => null,
});

global.IntersectionObserver = mockIntersectionObserver;
188 changes: 128 additions & 60 deletions extensions/apps/antenna/src/components/__tests__/beam-page.spec.tsx
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();
});
});
});

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 1fd4c7b

Please sign in to comment.