Skip to content

Commit

Permalink
feat: added toggle for notification support (#10872)
Browse files Browse the repository at this point in the history
* feat: added toggle for notification support

* feat: updated snaps

* feat: added test for toggle support notification component

* feat: added generated badges

* fix: corrected snapshot

* chore: updates badges
  • Loading branch information
bashleigh authored Mar 12, 2024
1 parent 9c0af90 commit a3949ca
Show file tree
Hide file tree
Showing 22 changed files with 191 additions and 4 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .yarn/cache/fsevents-patch-19706e7e35-10.zip
Binary file not shown.
Binary file added .yarn/cache/fsevents-patch-6b67494872-10.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ exports[`AppsTable should render component with apps 1`] = `
<mock-styled.div />
Toggle Subscription
</mock-styled.button>
<mock-styled.button
classname="el-intent-primary"
disabled="true"
>
<mock-styled.div />
Toggle Support Notification
</mock-styled.button>
<mock-styled.button
classname="el-intent-primary"
disabled="true"
Expand Down Expand Up @@ -599,6 +606,13 @@ exports[`AppsTable should render component with apps 1`] = `
<mock-styled.div />
Toggle Subscription
</mock-styled.button>
<mock-styled.button
classname="el-intent-primary"
disabled="true"
>
<mock-styled.div />
Toggle Support Notification
</mock-styled.button>
<mock-styled.button
classname="el-intent-primary"
disabled="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,12 @@ exports[`AppsPage should render a component when has data 1`] = `
<mock-styled.div />
Toggle Subscription
</mock-styled.button>
<mock-styled.button
classname="el-intent-primary"
>
<mock-styled.div />
Toggle Support Notification
</mock-styled.button>
<mock-styled.button
classname="el-intent-primary"
>
Expand Down Expand Up @@ -1340,6 +1346,12 @@ exports[`AppsPage should render a component when has data 1`] = `
<mock-styled.div />
Toggle Subscription
</mock-styled.button>
<mock-styled.button
classname="el-intent-primary"
>
<mock-styled.div />
Toggle Support Notification
</mock-styled.button>
<mock-styled.button
classname="el-intent-primary"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ToggleSupportNotification should match a snapshot 1`] = `
{
"asFragment": [Function],
"baseElement": <body>
<div>
<mock-styled.div />
<mock-styled.button
classname="el-intent-primary"
disabled="true"
>
<mock-styled.div />
Toggle Support Notification
</mock-styled.button>
</div>
</body>,
"container": <div>
<mock-styled.div />
<mock-styled.button
classname="el-intent-primary"
disabled="true"
>
<mock-styled.div />
Toggle Support Notification
</mock-styled.button>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'
import { render } from '../../../tests/react-testing'
import { ToggleSupportNotification, handleSetSupportNotification } from '../toggle-support-notification'

jest.mock('@reapit/use-reapit-data', () => ({
...jest.requireActual('@reapit/use-reapit-data'),
useReapitUpdate: jest.fn(() => [undefined, undefined, jest.fn(), false]),
}))

describe('ToggleSupportNotification', () => {
it('should match a snapshot', () => {
expect(render(<ToggleSupportNotification appId="MOCK_ID" hasReadAccess={true} />)).toMatchSnapshot()
})

it('handleSetSupportNotification', () => {
const setNotificationFunction = jest.fn()

const curried = handleSetSupportNotification(setNotificationFunction)

curried()

expect(setNotificationFunction).toHaveBeenCalledTimes(1)
})
})
2 changes: 2 additions & 0 deletions packages/admin-portal/src/components/apps/apps-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { CreateSubscriptions } from '../subscriptions/create-subscriptions'
import { usePermissionsState } from '../../core/use-permissions-state'
import { ToggleFeatured } from './toggle-featured'
import { ToggleConsumption } from './toggle-consumption'
import { ToggleSupportNotification } from './toggle-support-notification'

export interface AppsTableProps {
apps: AppSummaryModelPagedResult | null
Expand Down Expand Up @@ -249,6 +250,7 @@ export const AppsTable: FC<AppsTableProps> = ({ apps, appsRefresh }) => {
>
Toggle Subscription
</Button>
<ToggleSupportNotification appId={id as string} hasReadAccess={hasReadAccess} />
<Button
intent="primary"
disabled={hasReadAccess}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { BodyText, Button, ButtonGroup, useModal } from '@reapit/elements'
import { UpdateActionNames, updateActions, useReapitUpdate } from '@reapit/use-reapit-data'
import React, { FC, useEffect } from 'react'
import { reapitConnectBrowserSession } from '../../core/connect-session'

export const handleSetSupportNotification = (setSupportNotification: (data: any) => void) => () => {
setSupportNotification({
sendInternalInstallNotification: true,
})
}

export const ToggleSupportNotification: FC<{ appId: string; hasReadAccess: boolean }> = ({ appId, hasReadAccess }) => {
const { Modal, openModal, closeModal } = useModal()

const [loading, , setSupportNotification, done] = useReapitUpdate({
reapitConnectBrowserSession,
action: updateActions[UpdateActionNames.updateApp],
method: 'PUT',
uriParams: {
appId,
},
headers: {
['Api-Version']: 'latest',
},
})

useEffect(() => {
if (done) closeModal()
}, [done])

return (
<>
<Button onClick={openModal} intent="primary" disabled={hasReadAccess}>
Toggle Support Notification
</Button>

<Modal title={'Toggle Support Notifications'}>
<BodyText>This will enable the support notifications</BodyText>
<ButtonGroup alignment="center">
<Button intent="secondary" onClick={closeModal}>
Cancel
</Button>
<Button
intent="primary"
disabled={loading}
loading={loading}
onClick={handleSetSupportNotification(setSupportNotification)}
>
Confirm
</Button>
</ButtonGroup>
</Modal>
</>
)
}
2 changes: 1 addition & 1 deletion packages/admin-portal/src/tests/badges/badge-branches.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/admin-portal/src/tests/badges/badge-functions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/admin-portal/src/tests/badges/badge-lines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a3949ca

Please sign in to comment.