diff --git a/static/src/js/components/DraftPreview/DraftPreview.jsx b/static/src/js/components/DraftPreview/DraftPreview.jsx index c6840ab34..86de4bc46 100644 --- a/static/src/js/components/DraftPreview/DraftPreview.jsx +++ b/static/src/js/components/DraftPreview/DraftPreview.jsx @@ -58,37 +58,50 @@ const DraftPreview = () => { // Validate ummMetadata const { errors: validationErrors } = validator.validateFormData(ummMetadata, schema) + const { errors } = ummMetadata + // Pull the formSections out of the formConfigurations const formSections = formConfigurations[derivedConceptType] return ( - - + { + errors ? ( - -

Metadata Fields

- + + This record does not exist in CMR, please contact support@earthdata.nasa.gov + if you believe this is an error.
- - - -

Preview

- - - - -
-
+ ) : ( + + + + +

Metadata Fields

+ + +
+ + + +

Preview

+ + + + +
+
+ ) + }
) } diff --git a/static/src/js/components/DraftPreview/__tests__/DraftPreview.test.jsx b/static/src/js/components/DraftPreview/__tests__/DraftPreview.test.jsx index 40cee737f..371c5c110 100644 --- a/static/src/js/components/DraftPreview/__tests__/DraftPreview.test.jsx +++ b/static/src/js/components/DraftPreview/__tests__/DraftPreview.test.jsx @@ -1,5 +1,9 @@ import React, { Suspense } from 'react' -import { render, waitFor } from '@testing-library/react' +import { + render, + screen, + waitFor +} from '@testing-library/react' import userEvent from '@testing-library/user-event' import { MockedProvider } from '@apollo/client/testing' import { @@ -92,6 +96,59 @@ const mockDraft = { __typename: 'Draft' } +const mockErrorDraft = { + conceptId: 'TD1000000-MMT', + conceptType: 'tool-draft', + deleted: false, + name: null, + nativeId: 'MMT_2331e312-cbbc-4e56-9d6f-fe217464be2c', + providerId: 'MMT_2', + revisionDate: '2023-12-08T16:14:28.177Z', + revisionId: '2', + ummMetadata: { + errors: 'concept not found in DB' + }, + previewMetadata: { + accessConstraints: null, + ancillaryKeywords: null, + associationDetails: null, + conceptId: 'TD1000000-MMT', + contactGroups: null, + contactPersons: null, + description: null, + doi: null, + nativeId: 'MMT_2331e312-cbbc-4e56-9d6f-fe217464be2c', + lastUpdatedDate: null, + longName: 'Long Name', + metadataSpecification: { + url: 'https://cdn.earthdata.nasa.gov/umm/tool/v1.1', + name: 'UMM-T', + version: '1.1' + }, + name: null, + organizations: null, + pageTitle: null, + potentialAction: null, + quality: null, + relatedUrls: null, + revisionId: '2', + searchAction: null, + supportedBrowsers: null, + supportedInputFormats: null, + supportedOperatingSystems: null, + supportedOutputFormats: null, + supportedSoftwareLanguages: null, + toolKeywords: null, + type: null, + url: null, + useConstraints: null, + version: null, + versionDescription: null, + __typename: 'Tool' + }, + __typename: 'Draft' +} + const setup = ({ additionalMocks = [], overrideMocks = false, @@ -244,4 +301,29 @@ describe('DraftPreview', () => { }, {}) }) }) + + describe('when cmr takes longer than react to populate', () => { + test('renders a refresh page banner', async () => { + setup({ + overrideMocks: [{ + request: { + query: conceptTypeDraftQueries.Tool, + variables: { + params: { + conceptId: 'TD1000000-MMT', + conceptType: 'Tool' + } + } + }, + result: { + data: { + draft: mockErrorDraft + } + } + }] + }) + + expect(await screen.findByText('This record does not exist in CMR, please contact support@earthdata.nasa.gov if you believe this is an error.')).toBeVisible() + }) + }) }) diff --git a/static/src/js/pages/DraftPage/DraftPage.jsx b/static/src/js/pages/DraftPage/DraftPage.jsx index 1820c50e2..d295257cf 100644 --- a/static/src/js/pages/DraftPage/DraftPage.jsx +++ b/static/src/js/pages/DraftPage/DraftPage.jsx @@ -105,6 +105,9 @@ const DraftPageHeader = () => { // Validate ummMetadata const { errors: validationErrors } = validator.validateFormData(ummMetadata, schema) + // Check to see if special CMR lag use case is true + const { errors } = ummMetadata + const handlePublish = () => { publishMutation(derivedConceptType, nativeId) } @@ -219,6 +222,7 @@ const DraftPageHeader = () => { variant: 'success' }, { + disabled: !!errors, icon: FaTrash, iconTitle: 'A trash icon', onClick: () => toggleShowDeleteModal(true), @@ -228,6 +232,7 @@ const DraftPageHeader = () => { ...[( derivedConceptType === conceptTypes.Collection ? { + disabled: !!errors, icon: FaCopy, iconTitle: 'A copy icon', onClick: handleTemplate, diff --git a/static/src/js/pages/DraftPage/__tests__/DraftPage.test.jsx b/static/src/js/pages/DraftPage/__tests__/DraftPage.test.jsx index fdc9200fa..0234334a6 100644 --- a/static/src/js/pages/DraftPage/__tests__/DraftPage.test.jsx +++ b/static/src/js/pages/DraftPage/__tests__/DraftPage.test.jsx @@ -63,7 +63,7 @@ const ummMetadata = { const mockDraft = { __typename: 'Draft', conceptId: 'TD1000000-MMT', - conceptType: 'topol-draft', + conceptType: 'tool-draft', deleted: false, name: 'mock name', nativeId: 'MMT_2331e312-cbbc-4e56-9d6f-fe217464be2c', @@ -111,11 +111,64 @@ const mockDraft = { ummMetadata } +const mockCollectionDraft = { + __typename: 'Draft', + conceptId: 'CD1000000-MMT', + conceptType: 'collection-draft', + deleted: false, + name: 'mock name', + nativeId: 'MMT_2331e312-cbbc-4e56-9d6f-fe217464be2c', + previewMetadata: { + __typename: 'Collection', + accessConstraints: null, + ancillaryKeywords: null, + associationDetails: null, + conceptId: 'CD1000000-MMT', + contactGroups: null, + contactPersons: null, + description: null, + doi: null, + lastUpdatedDate: null, + longName: 'Long Name', + metadataSpecification: { + name: 'UMM-C', + url: 'https://cdn.earthdata.nasa.gov/umm/collection/v1.1', + version: '1.1' + }, + name: null, + nativeId: 'MMT_2331e312-cbbc-4e56-9d6f-fe217464be2c', + organizations: null, + pageTitle: null, + potentialAction: null, + quality: null, + relatedUrls: null, + revisionId: '2', + searchAction: null, + supportedBrowsers: null, + supportedInputFormats: null, + supportedOperatingSystems: null, + supportedOutputFormats: null, + supportedSoftwareLanguages: null, + toolKeywords: null, + type: null, + url: null, + useConstraints: null, + version: null, + versionDescription: null + }, + providerId: 'MMT_2', + revisionDate: '2023-12-08T16:14:28.177Z', + revisionId: '2', + ummMetadata +} + const setup = ({ additionalMocks = [], overrideMocks = false, pageUrl = '/drafts/tools/TD1000000-MMT', - path = '/drafts/tools' + overridePageUrl = false, + path = '/drafts/tools', + overridePath = false }) => { const mocks = [{ request: { @@ -141,10 +194,10 @@ const setup = ({ - + { expect(button).toHaveAttribute('disabled') }) + test('buttons are disabled if draft does not exist', async () => { + const navigateSpy = vi.fn() + vi.spyOn(router, 'useNavigate').mockImplementation(() => navigateSpy) + + // Overriding ummMetadata and setting it to have errors + const invalidMockDraft = { + ...mockCollectionDraft, + ummMetadata: { + errors: 'concept not found in DB' + } + } + + setup({ + overrideMocks: [{ + request: { + query: conceptTypeDraftQueries.Collection, + variables: { + params: { + conceptId: 'CD1000000-MMT', + conceptType: 'Collection' + } + } + }, + result: { + data: { + draft: invalidMockDraft + } + } + }], + overridePageUrl: '/drafts/collections/CD1000000-MMT', + overridePath: '/drafts/collections' + }) + + const publishButton = await screen.findByRole('button', { name: /Publish/ }) + expect(publishButton).toHaveAttribute('disabled') + + const deleteButton = await screen.findByRole('button', { name: /Delete/ }) + expect(deleteButton).toHaveAttribute('disabled') + + const templateButton = await screen.findByRole('button', { name: /Save as Template/ }) + expect(templateButton).toHaveAttribute('disabled') + }) + test('calls the publish mutation and if unsuccesfull shows error', async () => { const navigateSpy = vi.fn() vi.spyOn(router, 'useNavigate').mockImplementation(() => navigateSpy)