diff --git a/packages/developer-portal/src/components/pages/app-detail-preview/__tests__/__snapshots__/app-detail-preview.test.tsx.snap b/packages/developer-portal/src/components/pages/app-detail-preview/__tests__/__snapshots__/app-detail-preview.test.tsx.snap new file mode 100644 index 0000000000..6148fc9977 --- /dev/null +++ b/packages/developer-portal/src/components/pages/app-detail-preview/__tests__/__snapshots__/app-detail-preview.test.tsx.snap @@ -0,0 +1,91 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AppDetailPreview should match a snapshot 1`] = ` + + + + + +
+ +
+ +
+ There is no preview app +
+
+
+
+
+
+
+
+
+
+`; diff --git a/packages/developer-portal/src/components/pages/app-detail-preview/__tests__/app-detail-preview.test.tsx b/packages/developer-portal/src/components/pages/app-detail-preview/__tests__/app-detail-preview.test.tsx new file mode 100644 index 0000000000..dc26a24366 --- /dev/null +++ b/packages/developer-portal/src/components/pages/app-detail-preview/__tests__/app-detail-preview.test.tsx @@ -0,0 +1,50 @@ +import * as React from 'react' +import * as ReactRedux from 'react-redux' +import { MemoryRouter } from 'react-router' +import { mount } from 'enzyme' +import configureStore from 'redux-mock-store' +import AppDetailPreview, { loadAppDetailPreviewDataFromLocalStorage } from '../app-detail-preview' +import Routes from '@/constants/routes' +import appState from '@/reducers/__stubs__/app-state' +import { appDetailDataStub } from '@/sagas/__stubs__/app-detail' + +describe('AppDetailPreview', () => { + let store + let spyDispatch + beforeEach(() => { + /* mocking store */ + const mockStore = configureStore() + store = mockStore({ + ...appState, + client: { + appDetail: { + data: {}, + loading: false, + }, + }, + }) + spyDispatch = jest.spyOn(ReactRedux, 'useDispatch').mockImplementation(() => store.dispatch) + }) + + it('should match a snapshot', () => { + expect( + mount( + + + + + , + ), + ).toMatchSnapshot() + }) + it('should run correctly', () => { + window.localStorage.setItem('developer-preview-app', JSON.stringify(appDetailDataStub.data)) + const mockAppId = '9b6fd5f7-2c15-483d-b925-01b650538e52' + const mockSetAppDetailPreviewData = jest.fn() + const spyLocalStorageGetItem = jest.spyOn(window.localStorage, 'getItem') + const fn = loadAppDetailPreviewDataFromLocalStorage(mockAppId, mockSetAppDetailPreviewData, spyDispatch) + fn() + expect(spyLocalStorageGetItem).toBeCalledWith('developer-preview-app') + expect(mockSetAppDetailPreviewData).toBeCalled() + }) +}) diff --git a/packages/developer-portal/src/components/pages/app-detail-preview/app-detail-preview.tsx b/packages/developer-portal/src/components/pages/app-detail-preview/app-detail-preview.tsx new file mode 100644 index 0000000000..872d0f07e4 --- /dev/null +++ b/packages/developer-portal/src/components/pages/app-detail-preview/app-detail-preview.tsx @@ -0,0 +1,71 @@ +// The UI of this page should be the same as the Standalone App Detail page in Marketplace portal +// Make sure to always update the UI in both places if needed +import * as React from 'react' +import AppContent from './client/app-content' +import { Aside as AppAside } from './client/aside' +import AppHeader from './common/ui-app-header' +import { useParams } from 'react-router' +import { AppDetailData } from '@/reducers/developer' +import { Grid, GridItem, Section, Alert } from '@reapit/elements' +import { Dispatch } from 'redux' +import { showNotificationMessage } from '@/actions/notification-message' +import { useDispatch } from 'react-redux' + +export type AppDetailPreviewProps = {} + +export const loadAppDetailPreviewDataFromLocalStorage = ( + appId: string, + setAppDetailPreviewData: React.Dispatch>, + dispatch: Dispatch, +) => () => { + try { + const appDataString = localStorage.getItem('developer-preview-app') + if (!appDataString) { + throw new Error('No app preview') + } + + const appData = JSON.parse(appDataString) as AppDetailData + if (appData?.id !== appId) { + throw new Error('No app preview') + } + setAppDetailPreviewData(appData) + } catch (err) { + dispatch( + showNotificationMessage({ + message: err.message, + variant: 'danger', + }), + ) + } +} + +const AppDetailPreview: React.FC = () => { + const dispatch = useDispatch() + const [appDetailPreviewData, setAppDetailPreviewData] = React.useState(null) + const { appId } = useParams() + + React.useEffect(loadAppDetailPreviewDataFromLocalStorage(appId, setAppDetailPreviewData, dispatch), [appId, dispatch]) + + return ( + + {!appDetailPreviewData ? ( + + + + ) : ( + <> + + + + +
+ + +
+
+ + )} +
+ ) +} +export default AppDetailPreview diff --git a/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/__snapshots__/app-button-group.test.tsx.snap b/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/__snapshots__/app-button-group.test.tsx.snap new file mode 100644 index 0000000000..42b648a34c --- /dev/null +++ b/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/__snapshots__/app-button-group.test.tsx.snap @@ -0,0 +1,15 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ClientAppDetailButtonGroup should match snapshot when both buttons are hidden 1`] = `""`; + +exports[`ClientAppDetailButtonGroup should match snapshot when both buttons are showing 1`] = ` + + Uninstall App + +`; diff --git a/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/__snapshots__/app-content.test.tsx.snap b/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/__snapshots__/app-content.test.tsx.snap new file mode 100644 index 0000000000..288783aeb1 --- /dev/null +++ b/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/__snapshots__/app-content.test.tsx.snap @@ -0,0 +1,30 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ClientAppContent ClientAppContent - should match snapshot 1`] = ` + + + + + + + +`; diff --git a/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/__snapshots__/aside.test.tsx.snap b/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/__snapshots__/aside.test.tsx.snap new file mode 100644 index 0000000000..d57896ae40 --- /dev/null +++ b/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/__snapshots__/aside.test.tsx.snap @@ -0,0 +1,76 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ClientAside ClientAside - should match snapshot 1`] = ` + + + + + + +`; diff --git a/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/__snapshots__/contact-developer-modal.test.tsx.snap b/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/__snapshots__/contact-developer-modal.test.tsx.snap new file mode 100644 index 0000000000..19d08e90b5 --- /dev/null +++ b/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/__snapshots__/contact-developer-modal.test.tsx.snap @@ -0,0 +1,191 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ContactDeveloperSection should match snapshot with gutter 1`] = ` + + + NEED HELP? + + + Close + + } + onClose={[Function]} + title="Contact Details" + visible={false} + > + + + + + Company name + + + +

+ Reapit Ltd +

+
+
+ + + + Telephone Number + + + +

+ 0777 777 777 +

+
+
+ + + + Support Email + + + +

+ + reapit@reapit.com + +

+
+
+ + + + Home Page + + + +

+ + https://reapit.com + +

+
+
+
+
+
+`; + +exports[`ContactDeveloperSection should match snapshot without gutter 1`] = ` + + + NEED HELP? + + + Close + + } + onClose={[Function]} + title="Contact Details" + visible={false} + > + + + + + Company name + + + +

+ Reapit Ltd +

+
+
+ + + + Telephone Number + + + +

+ 0777 777 777 +

+
+
+ + + + Support Email + + + +

+ + reapit@reapit.com + +

+
+
+ + + + Home Page + + + +

+ + https://reapit.com + +

+
+
+
+
+
+`; diff --git a/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/app-button-group.test.tsx b/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/app-button-group.test.tsx new file mode 100644 index 0000000000..4d6ab6e782 --- /dev/null +++ b/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/app-button-group.test.tsx @@ -0,0 +1,29 @@ +import React from 'react' +import { AppDetailButtonGroup } from '../app-detail-button-group' +import { shallow } from 'enzyme' + +describe('ClientAppDetailButtonGroup', () => { + it('should match snapshot when both buttons are showing', () => { + const wrapper = shallow( + , + ) + expect(wrapper).toMatchSnapshot() + }) + + it('should match snapshot when both buttons are hidden', () => { + const wrapper = shallow( + , + ) + expect(wrapper).toMatchSnapshot() + }) +}) diff --git a/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/app-content.test.tsx b/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/app-content.test.tsx new file mode 100644 index 0000000000..4f80c16f99 --- /dev/null +++ b/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/app-content.test.tsx @@ -0,0 +1,12 @@ +import React from 'react' +import AppContent from '../app-content' +import { appDetailDataStub } from '@/sagas/__stubs__/app-detail' +import { shallow } from 'enzyme' +import { AppDetailModel } from '@reapit/foundations-ts-definitions' + +describe('ClientAppContent', () => { + it('ClientAppContent - should match snapshot', () => { + const wrapper = shallow() + expect(wrapper).toMatchSnapshot() + }) +}) diff --git a/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/aside.test.tsx b/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/aside.test.tsx new file mode 100644 index 0000000000..21d4cc0e7c --- /dev/null +++ b/packages/developer-portal/src/components/pages/app-detail-preview/client/__tests__/aside.test.tsx @@ -0,0 +1,20 @@ +import React from 'react' +import { Aside } from '../aside' +import { shallow } from 'enzyme' +import { integrationTypesStub } from '@/sagas/__stubs__/integration-types' +import { appDetailDataStub } from '@/sagas/__stubs__/app-detail' +import { DesktopIntegrationTypeModel } from '@/actions/app-integration-types' +import { AppDetailModel } from '@reapit/foundations-ts-definitions' + +describe('ClientAside', () => { + test('ClientAside - should match snapshot', () => { + expect( + shallow( +