Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RickyRoller committed Mar 7, 2025
1 parent eb991c8 commit c7372ad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
28 changes: 17 additions & 11 deletions src/apps/external-app/index.vitest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ vi.mock('../iframe', () => ({
}));

const DEFAULT_PROPS: PublicProperties = {
route: '/foo',
title: 'Bar',
url: 'https://foo.bar',
manifest: {
title: 'Foo',
route: '/foo',
url: 'https://foo.bar',
features: [],
},
};

const history = createMemoryHistory();
Expand All @@ -38,28 +41,28 @@ describe(ExternalApp, () => {
});

it('should pass title to iFrame', () => {
renderComponent({ title: 'Foo' });
renderComponent(DEFAULT_PROPS);
expect(mockIFrame).toHaveBeenCalledWith(expect.objectContaining({ title: 'Foo' }));
});

describe('when browser route is default app route', () => {
it('should pass url to iFrame', () => {
renderComponent({ url: 'https://foo.baz' }, '/foo');
renderComponent({ manifest: { ...DEFAULT_PROPS.manifest, url: 'https://foo.baz' } });
expect(mockIFrame).toHaveBeenCalledWith(expect.objectContaining({ src: 'https://foo.baz/' }));
});
});

describe('when browser route is sub-route of app route', () => {
it('should pass url to iFrame', () => {
renderComponent({ url: 'https://foo.baz' }, '/foo/bar/baz');
renderComponent({ manifest: { ...DEFAULT_PROPS.manifest, url: 'https://foo.baz' } }, '/foo/bar/baz');
expect(mockIFrame).toHaveBeenCalledWith(expect.objectContaining({ src: 'https://foo.baz/bar/baz' }));
});
});

describe('when window receives a message event', () => {
describe('when type is zapp-route-changed', () => {
it('should change route accordingly', async () => {
renderComponent({ route: '/foo', url: 'https://foo.bar' }, '/foo');
renderComponent({ manifest: { ...DEFAULT_PROPS.manifest, url: 'https://foo.bar' } }, '/foo');

const navigationEvent = new MessageEvent('message', {
data: {
Expand All @@ -77,7 +80,7 @@ describe(ExternalApp, () => {
});

it('should ignore origin outside of app', async () => {
renderComponent({ route: '/foo', url: 'https://foo.bar' }, '/foo');
renderComponent({ manifest: { ...DEFAULT_PROPS.manifest, url: 'https://foo.bar' } }, '/foo');

const navigationEvent = new MessageEvent('message', {
data: {
Expand All @@ -94,7 +97,7 @@ describe(ExternalApp, () => {
});

it('should handle root navigation', async () => {
renderComponent({ route: '/foo', url: 'https://foo.bar' }, '/foo');
renderComponent({ manifest: { ...DEFAULT_PROPS.manifest, url: 'https://foo.bar' } }, '/foo');

const navigationEvent = new MessageEvent('message', {
data: {
Expand All @@ -112,7 +115,10 @@ describe(ExternalApp, () => {
});

it('should not react if unmounted', () => {
const { unmount } = renderComponent({ route: '/foo', url: 'https://foo.bar' }, '/foo');
const { unmount } = renderComponent(
{ manifest: { ...DEFAULT_PROPS.manifest, url: 'https://foo.bar' } },
'/foo'
);

unmount();

Expand All @@ -133,7 +139,7 @@ describe(ExternalApp, () => {
});

it('should not react to other message types (only accept zapp-route-changed)', async () => {
renderComponent({ route: '/foo', url: 'https://foo.bar' }, '/foo');
renderComponent({ manifest: { ...DEFAULT_PROPS.manifest, url: 'https://foo.bar' } }, '/foo');

const navigationEvent = new MessageEvent('message', {
data: {
Expand Down
7 changes: 5 additions & 2 deletions src/store/active-zapp/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import { expectSaga } from 'redux-saga-test-plan';

import { setActiveZAppManifest, clearActiveZAppManifest } from './saga';
import { setActiveZAppManifestAction, clearActiveZAppManifestAction } from './index';
import { ZAppManifest } from '../../apps/external-app/types/manifest';

describe('external-app saga', () => {
const mockManifest = {
name: 'ZApp',
const mockManifest: ZAppManifest = {
title: 'ZApp',
route: '/',
url: 'https://zapp.zero.tech/',
features: [],
};

Expand Down

0 comments on commit c7372ad

Please sign in to comment.