Skip to content

Commit

Permalink
MMT-3915: Fixed when a user tries to publish a draft and is unsuccess…
Browse files Browse the repository at this point in the history
…ful, there is no error message displayed
  • Loading branch information
Christopher D. Gokey committed Oct 2, 2024
1 parent 86b5bf0 commit d134cfc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
16 changes: 15 additions & 1 deletion static/src/js/pages/DraftPage/DraftPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ const DraftPageHeader = () => {

const {
publishMutation,
publishDraft
publishDraft,
error: publishErrors
} = usePublishMutation(pluralize(derivedConceptType).toLowerCase())

const toggleShowDeleteModal = (nextState) => {
Expand Down Expand Up @@ -121,6 +122,19 @@ const DraftPageHeader = () => {
}
}, [publishDraft])

useEffect(() => {
if (publishErrors) {
console.log('publishErrors', publishErrors)
const { message } = publishErrors
addNotification({
message,
variant: 'danger'
})

errorLogger(message, 'PublishMutation: publishMutation')
}
}, [publishErrors])

const handleTemplate = async () => {
const response = await createTemplate(providerId, mmtJwt, {
TemplateName: '',
Expand Down
30 changes: 30 additions & 0 deletions static/src/js/pages/DraftPage/__tests__/DraftPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import createTemplate from '@/js/utils/createTemplate'
import Providers from '@/js/providers/Providers/Providers'

import DraftPage from '../DraftPage'
import { GraphQLError } from 'graphql'

Check failure on line 27 in static/src/js/pages/DraftPage/__tests__/DraftPage.test.jsx

View workflow job for this annotation

GitHub Actions / eslint (lts/hydrogen)

`graphql` import should occur before import of `../DraftPage`

vi.mock('@/js/components/MetadataPreview/MetadataPreview')
vi.mock('@/js/utils/createTemplate')
Expand Down Expand Up @@ -341,6 +342,35 @@ describe('DraftPage', () => {
expect(button).toHaveAttribute('disabled')
})

test('calls the publish mutation and if unsuccesfull shows error', async () => {
const navigateSpy = vi.fn()
vi.spyOn(router, 'useNavigate').mockImplementation(() => navigateSpy)

const { user } = setup({
additionalMocks: [{
request: {
query: PUBLISH_DRAFT,
variables: {
draftConceptId: 'TD1000000-MMT',
nativeId: 'MMT_2331e312-cbbc-4e56-9d6f-fe217464be2c',
ummVersion: '1.2.0'
}
},
result: {
errors: [new GraphQLError('An error occurred')]
}
}]
})

const button = await screen.findByRole('button', { name: /Publish/ })
await user.click(button)

expect(navigateSpy).toHaveBeenCalledTimes(0)

expect(errorLogger).toHaveBeenCalledTimes(1)
expect(errorLogger).toHaveBeenCalledWith('An error occurred', 'PublishMutation: publishMutation')
})

test('calls the publish mutation and navigates to the concept page', async () => {
const navigateSpy = vi.fn()
vi.spyOn(router, 'useNavigate').mockImplementation(() => navigateSpy)
Expand Down

0 comments on commit d134cfc

Please sign in to comment.