diff --git a/packages/marketplace/src/components/pages/client-app-detail/__test__/client-app-detail.test.tsx b/packages/marketplace/src/components/pages/client-app-detail/__test__/client-app-detail.test.tsx index 5aa9cbeb12..58bbe98fae 100644 --- a/packages/marketplace/src/components/pages/client-app-detail/__test__/client-app-detail.test.tsx +++ b/packages/marketplace/src/components/pages/client-app-detail/__test__/client-app-detail.test.tsx @@ -8,10 +8,13 @@ import ClientAppDetail, { handleCloseInstallConfirmationModal, handleInstallAppButtonClick, renderAppHeaderButtonGroup, + handleApplyAppDetailsFromLocalStorage, } from '../client-app-detail' import { Button } from '@reapit/elements' import Routes from '@/constants/routes' import appState from '@/reducers/__stubs__/app-state' +import { developerApplyAppDetails } from '@/actions/developer' +import { AppDetailData } from '@/reducers/client/app-detail' describe('ClientAppDetail', () => { let store @@ -169,4 +172,18 @@ describe('ClientAppDetail', () => { expect(mockFunction).toBeCalledWith(true) }) }) + + describe('handleApplyAppDetailsFromLocalStorage', () => { + it('should run correctly', () => { + const dispatch = jest.fn() + const appId = 'appId' + const value = { id: 'appId' } as AppDetailData + const stringValue = JSON.stringify(value) + const spyLocalStorageGetItem = jest.spyOn(window.localStorage, 'getItem').mockImplementation(() => stringValue) + const fn = handleApplyAppDetailsFromLocalStorage(dispatch, appId) + fn() + expect(spyLocalStorageGetItem).toBeCalledWith('developer-preview-app') + expect(dispatch).toBeCalledWith(developerApplyAppDetails(value)) + }) + }) }) diff --git a/packages/marketplace/src/components/pages/client-app-detail/client-app-detail.tsx b/packages/marketplace/src/components/pages/client-app-detail/client-app-detail.tsx index 5bbc5ce8bd..1a0540ab6e 100644 --- a/packages/marketplace/src/components/pages/client-app-detail/client-app-detail.tsx +++ b/packages/marketplace/src/components/pages/client-app-detail/client-app-detail.tsx @@ -36,7 +36,7 @@ export const handleInstallAppButtonClick = (setIsVisibleInstallConfirmation: (is } } -export const handleApplyAppDetailsFromLocalStorage = (dispatch: Dispatch, appid?: string) => () => { +export const handleApplyAppDetailsFromLocalStorage = (dispatch: Dispatch, appId?: string) => () => { try { const appDataString = localStorage.getItem('developer-preview-app') if (!appDataString) { @@ -44,7 +44,7 @@ export const handleApplyAppDetailsFromLocalStorage = (dispatch: Dispatch, appid? } const appData = JSON.parse(appDataString) - if (appData.id !== appid) { + if (appData.id !== appId) { throw 'No app preview' } @@ -94,7 +94,7 @@ export const renderAppHeaderButtonGroup = ( const ClientAppDetail: React.FC = () => { const dispatch = useDispatch() - const { id: appid } = useParams() + const { appId } = useParams() const [isVisibleInstallConfirmation, setIsVisibleInstallConfirmation] = React.useState(false) const [isVisibleUninstallConfirmation, setIsVisibleUninstallConfirmation] = React.useState(false) @@ -129,7 +129,7 @@ const ClientAppDetail: React.FC = () => { const unfetched = Object.keys(appDetailData).length === 0 const { id = '', installedOn = '' } = appDetailData - React.useEffect(handleApplyAppDetailsFromLocalStorage(dispatch, appid), [dispatch]) + React.useEffect(handleApplyAppDetailsFromLocalStorage(dispatch, appId), [dispatch]) if (error) return if (isLoadingAppDetail || unfetched) { diff --git a/packages/marketplace/src/components/pages/developer-submit-app/__test__/developer-submit-app.test.tsx b/packages/marketplace/src/components/pages/developer-submit-app/__test__/developer-submit-app.test.tsx index 651814373d..71abca9a76 100644 --- a/packages/marketplace/src/components/pages/developer-submit-app/__test__/developer-submit-app.test.tsx +++ b/packages/marketplace/src/components/pages/developer-submit-app/__test__/developer-submit-app.test.tsx @@ -20,6 +20,7 @@ import DeveloperSubmitApp, { handleGoBackToApps, handleOnSubmitAnotherApp, generateInitialValues, + handleOpenAppPreview, } from '../developer-submit-app' import { getMockRouterProps } from '@/utils/mock-helper' import { FIELD_ERROR_DESCRIPTION } from '@/constants/form' @@ -292,4 +293,18 @@ describe('DeveloperSubmitApp', () => { }) }) }) + + describe('handleOpenAppPreview', () => { + it('should run correctly', () => { + const params = { appDetails: {}, values: {}, scopes: [], appId: 'appId' } + const spyLocalStorageSetItem = jest.spyOn(window.localStorage, 'setItem') + const spyOpenUrl = jest.spyOn(window, 'open') + const expected = JSON.stringify({ scopes: [] }) + + const fn = handleOpenAppPreview(params) + fn() + expect(spyLocalStorageSetItem).toBeCalledWith('developer-preview-app', expected) + expect(spyOpenUrl).toBeCalledWith('developer/apps/appId/preview', '_blank') + }) + }) }) diff --git a/packages/marketplace/src/components/pages/developer-submit-app/developer-submit-app.tsx b/packages/marketplace/src/components/pages/developer-submit-app/developer-submit-app.tsx index 652c124c44..1f034eba65 100644 --- a/packages/marketplace/src/components/pages/developer-submit-app/developer-submit-app.tsx +++ b/packages/marketplace/src/components/pages/developer-submit-app/developer-submit-app.tsx @@ -279,18 +279,18 @@ export const handleOnSubmitAnotherApp = (dispatch: Dispatch) => { export type HandleOpenAppPreview = { scopes: ScopeModel[] values: FormikValues - appid?: string + appId?: string appDetails?: AppDetailModel & { apiKey?: string } } -export const handleOpenAppPreview = ({ appDetails, values, scopes, appid }: HandleOpenAppPreview) => () => { +export const handleOpenAppPreview = ({ appDetails, values, scopes, appId }: HandleOpenAppPreview) => () => { const appDetailState = { ...appDetails, ...values, scopes: scopes.filter(scope => values.scopes.includes(scope.name)), } - const url = `developer/apps/${appid}/preview` + const url = `developer/apps/${appId}/preview` localStorage.setItem('developer-preview-app', JSON.stringify(appDetailState)) window.open(url, '_blank') } @@ -403,7 +403,7 @@ export const DeveloperSubmitApp: React.FC = () => { appDetails: appDetailState?.appDetailData?.data, values, scopes, - appid, + appId: appid, })} variant="primary" type="button" diff --git a/packages/marketplace/src/constants/routes.ts b/packages/marketplace/src/constants/routes.ts index 82382ea2b6..a7545b9c3d 100644 --- a/packages/marketplace/src/constants/routes.ts +++ b/packages/marketplace/src/constants/routes.ts @@ -25,7 +25,7 @@ const Routes = { SETTINGS: '/developer/settings', SUBMIT_APP: '/developer/submit-app', DEVELOPER_HELP: '/developer/help', - DEVELOPER_APP_PREVIEW: '/developer/apps/:id/preview', + DEVELOPER_APP_PREVIEW: '/developer/apps/:appId/preview', CLIENT_HELP: '/client/help', REGISTER: '/register', REGISTER_CONFIRM: '/register/confirm', diff --git a/packages/marketplace/src/core/__tests__/__snapshots__/router.tsx.snap b/packages/marketplace/src/core/__tests__/__snapshots__/router.tsx.snap index 40a3a6962b..e655d4c366 100644 --- a/packages/marketplace/src/core/__tests__/__snapshots__/router.tsx.snap +++ b/packages/marketplace/src/core/__tests__/__snapshots__/router.tsx.snap @@ -389,7 +389,7 @@ exports[`Router should match a snapshot 1`] = ` } } exact={true} - path="/developer/apps/:id/preview" + path="/developer/apps/:appId/preview" /> { } export const selectAppDetailError = (state: ReduxState): string | null => { - return state.client.appDetail.error || null + return state?.client?.appDetail?.error || null } diff --git a/packages/marketplace/src/tests/badges/badge-branches.svg b/packages/marketplace/src/tests/badges/badge-branches.svg index 7b0822daf2..e7ac5f6d41 100644 --- a/packages/marketplace/src/tests/badges/badge-branches.svg +++ b/packages/marketplace/src/tests/badges/badge-branches.svg @@ -1 +1 @@ -Coverage:branchesCoverage:branches70.79%70.79% \ No newline at end of file +Coverage:branchesCoverage:branches70.86%70.86% \ No newline at end of file diff --git a/packages/marketplace/src/tests/badges/badge-functions.svg b/packages/marketplace/src/tests/badges/badge-functions.svg index c445c4ddea..c2c0a69339 100644 --- a/packages/marketplace/src/tests/badges/badge-functions.svg +++ b/packages/marketplace/src/tests/badges/badge-functions.svg @@ -1 +1 @@ -Coverage:functionsCoverage:functions79.43%79.43% \ No newline at end of file +Coverage:functionsCoverage:functions79.51%79.51% \ No newline at end of file diff --git a/packages/marketplace/src/tests/badges/badge-lines.svg b/packages/marketplace/src/tests/badges/badge-lines.svg index c676371ebd..8ef1721576 100644 --- a/packages/marketplace/src/tests/badges/badge-lines.svg +++ b/packages/marketplace/src/tests/badges/badge-lines.svg @@ -1 +1 @@ -Coverage:linesCoverage:lines90.76%90.76% \ No newline at end of file +Coverage:linesCoverage:lines90.88%90.88% \ No newline at end of file diff --git a/packages/marketplace/src/tests/badges/badge-statements.svg b/packages/marketplace/src/tests/badges/badge-statements.svg index 5b09f408d0..126ee22a7a 100644 --- a/packages/marketplace/src/tests/badges/badge-statements.svg +++ b/packages/marketplace/src/tests/badges/badge-statements.svg @@ -1 +1 @@ -Coverage:statementsCoverage:statements89.79%89.79% \ No newline at end of file +Coverage:statementsCoverage:statements89.9%89.9% \ No newline at end of file