diff --git a/apps/metadata-editor-e2e/src/e2e/edit.cy.ts b/apps/metadata-editor-e2e/src/e2e/edit.cy.ts index 4360ee6bd..1ad6d7cac 100644 --- a/apps/metadata-editor-e2e/src/e2e/edit.cy.ts +++ b/apps/metadata-editor-e2e/src/e2e/edit.cy.ts @@ -18,7 +18,7 @@ describe('editor form', () => { return } // there is a copy: delete it - cy.get('[data-test="record-menu-button"]').eq(1).click() + cy.get('[data-test="record-menu-button"]').eq(0).click() cy.get('[data-test="record-menu-delete-button"]').click() cy.get('[data-cy="confirm-button"]').click() cy.log('An existing copy of the test record was found and deleted.') @@ -675,6 +675,9 @@ describe('editor form', () => { }) }) describe('Access and constraints', () => { + beforeEach(() => { + cy.get('@accessContactPageBtn').click() + }) // TEMPORARY - to be removed when the open data switch is back // describe('Open data switch', () => { // beforeEach(() => { @@ -699,9 +702,6 @@ describe('editor form', () => { // }) // }) describe('licenses', () => { - beforeEach(() => { - cy.get('@accessContactPageBtn').click() - }) it('should select a new license and show it on reload', () => { cy.get('gn-ui-form-field-license') .find('button') @@ -727,6 +727,120 @@ describe('editor form', () => { .should('eq', ' Creative Commons CC-0 ') }) }) + describe('constraints', () => { + it('should add a few constraints and show it on reload', () => { + cy.editor_wrapPreviousDraft() + cy.get('[data-cy=legalConstraints]') + .find('gn-ui-button[data-cy=add-constraint-btn] button') + .click() + cy.get('[data-cy=legalConstraints]') + .find('textarea') + .last() + .type('new legal constraint') + + // add from shortcuts + cy.get('[data-cy=constraints-shortcut-btns]') + .find('gn-ui-button') + .eq(1) + .click() + cy.get('[data-cy=securityConstraints]') + .find('textarea') + .last() + .type('new security constraint') + + // add from shortcuts + cy.get('[data-cy=constraints-shortcut-btns]') + .find('gn-ui-button') + .eq(2) + .click() + cy.get('[data-cy=otherConstraints]') + .find('textarea') + .last() + .type('new other constraint') + cy.get('[data-cy=otherConstraints]') + .find('gn-ui-button[data-cy=add-url-btn] button') + .click() + cy.get('[data-cy=otherConstraints]') + .find('gn-ui-url-input') + .last() + .find('input') + .type('http://www.example.com/abcd/1234') + + cy.screenshot({ capture: 'fullPage' }) + cy.editor_publishAndReload() + cy.get('@saveStatus').should('eq', 'record_up_to_date') + cy.get('@accessContactPageBtn').click() + + cy.get('[data-cy=legalConstraints]') + .find('gn-ui-constraint-card') + .should('have.length', 5) + cy.get('[data-cy=legalConstraints]') + .find('textarea') + .last() + .invoke('val') + .should('eq', 'new legal constraint') + + cy.get('[data-cy=securityConstraints]') + .find('gn-ui-constraint-card') + .should('have.length', 1) + cy.get('[data-cy=securityConstraints]') + .find('textarea') + .last() + .invoke('val') + .should('eq', 'new security constraint') + + cy.get('[data-cy=otherConstraints]') + .find('gn-ui-constraint-card') + .should('have.length', 1) + cy.get('[data-cy=otherConstraints]') + .find('textarea') + .last() + .invoke('val') + .should('eq', 'new other constraint') + cy.get('[data-cy=otherConstraints]') + .find('gn-ui-url-input input') + .invoke('val') + .should('eq', 'http://www.example.com/abcd/1234/') + }) + + it('should enable "no applicable constraints" and stay enabled', () => { + cy.editor_wrapPreviousDraft() + cy.get('[data-cy=constraints-shortcut-toggles]') + .find('gn-ui-check-toggle label') + .eq(0) + .click() + + cy.editor_publishAndReload() + cy.get('@saveStatus').should('eq', 'record_up_to_date') + cy.get('@accessContactPageBtn').click() + + cy.get('[data-cy=constraints-shortcut-toggles]') + .find('gn-ui-check-toggle input[type=checkbox]') + .eq(0) + .invoke('val') + .should('eq', 'on') + + // constraints are hidden + cy.get('[data-cy=legalConstraints]').should('not.exist') + cy.get('[data-cy=securityConstraints]').should('not.exist') + cy.get('[data-cy=otherConstraints]').should('not.exist') + + // uncheck toggle + cy.get('[data-cy=constraints-shortcut-toggles]') + .find('gn-ui-check-toggle label') + .eq(0) + .click() + + // remaining constraints are shown + cy.get('[data-cy=legalConstraints]').should('not.exist') + cy.get('[data-cy=securityConstraints]') + .find('gn-ui-constraint-card') + .should('have.length', 1) + cy.get('[data-cy=otherConstraints]') + .find('gn-ui-constraint-card') + .should('have.length', 1) + }) + }) }) }) }) diff --git a/libs/api/metadata-converter/src/lib/iso19139/write-parts.spec.ts b/libs/api/metadata-converter/src/lib/iso19139/write-parts.spec.ts index 2e27b4bb6..db356b32a 100644 --- a/libs/api/metadata-converter/src/lib/iso19139/write-parts.spec.ts +++ b/libs/api/metadata-converter/src/lib/iso19139/write-parts.spec.ts @@ -12,10 +12,13 @@ import { writeContacts, writeContactsForResource, writeKeywords, + writeLegalConstraints, writeOnlineResources, + writeOtherConstraints, writeResourceCreated, writeResourcePublished, writeResourceUpdated, + writeSecurityConstraints, writeSpatialExtents, writeSpatialRepresentation, writeTemporalExtents, @@ -973,6 +976,57 @@ describe('write parts', () => { +`) + }) + }) + + describe('write constraints', () => { + it('writes elements without deleting others, remove empty constraints', () => { + writeSecurityConstraints(datasetRecord, rootEl) + writeLegalConstraints(datasetRecord, rootEl) + writeOtherConstraints(datasetRecord, rootEl) + writeLegalConstraints({ ...datasetRecord, legalConstraints: [] }, rootEl) + writeOtherConstraints( + { + ...datasetRecord, + otherConstraints: [ + { + text: 'new constraint', + }, + ], + }, + rootEl + ) + expect(rootAsString()).toEqual(` + + + + + + + + + Contains sensitive information related to national defense + + + Contains sensitive information related to national defense + + + Contient des informations sensibles liées à la défense nationale + + + + + + + + + new constraint + + + + + `) }) }) diff --git a/libs/api/metadata-converter/src/lib/iso19139/write-parts.ts b/libs/api/metadata-converter/src/lib/iso19139/write-parts.ts index b8d531526..bf87b7ba1 100644 --- a/libs/api/metadata-converter/src/lib/iso19139/write-parts.ts +++ b/libs/api/metadata-converter/src/lib/iso19139/write-parts.ts @@ -30,6 +30,7 @@ import { tap, } from '../function-utils' import { + allChildrenElement, appendChildren, createChild, createElement, @@ -542,7 +543,7 @@ export function createConstraint( ) ) } - + // other return pipe( createNestedElement( 'gmd:resourceConstraints', @@ -565,13 +566,20 @@ export function createConstraint( } export function removeOtherConstraints() { - return removeChildren( + return tap( pipe( findChildrenElement('gmd:resourceConstraints'), - filterArray( - pipe( - findNestedElements('gmd:MD_Constraints', 'gmd:useLimitation'), - (array) => array.length > 0 + mapArray( + removeChildren( + pipe( + findChildrenElement('gmd:MD_Constraints'), + filterArray( + pipe( + findNestedElements('gmd:useLimitation'), + (array) => array.length > 0 + ) + ) + ) ) ) ) @@ -579,13 +587,20 @@ export function removeOtherConstraints() { } export function removeSecurityConstraints() { - return removeChildren( + return tap( pipe( findChildrenElement('gmd:resourceConstraints'), - filterArray( - pipe( - findNestedElements('gmd:MD_SecurityConstraints', 'gmd:useLimitation'), - (array) => array.length > 0 + mapArray( + removeChildren( + pipe( + findChildrenElement('gmd:MD_SecurityConstraints'), + filterArray( + pipe( + findNestedElements('gmd:useLimitation'), + (array) => array.length > 0 + ) + ) + ) ) ) ) @@ -593,25 +608,40 @@ export function removeSecurityConstraints() { } export function removeLegalConstraints() { - return removeChildren( + return tap( pipe( findChildrenElement('gmd:resourceConstraints'), - filterArray( - pipe( - findNestedElements( - 'gmd:MD_LegalConstraints', - 'gmd:accessConstraints', - 'gmd:MD_RestrictionCode' - ), - mapArray(readAttribute('codeListValue')), - (restrictionCodes) => - restrictionCodes.every((code) => code !== 'license') + mapArray( + removeChildren( + pipe( + findChildrenElement('gmd:MD_LegalConstraints'), + filterArray( + pipe( + findNestedElements( + 'gmd:accessConstraints', + 'gmd:MD_RestrictionCode' + ), + mapArray(readAttribute('codeListValue')), + (restrictionCodes) => + restrictionCodes.every((code) => code !== 'license') + ) + ) + ) ) ) ) ) } +export function removeEmptyResourceConstraints() { + return removeChildren( + pipe( + findChildrenElement('gmd:resourceConstraints'), + filterArray(pipe(allChildrenElement, (array) => array.length === 0)) + ) + ) +} + export function removeLicenses() { return removeChildren( pipe( @@ -933,6 +963,7 @@ export function writeLegalConstraints( pipe( findOrCreateIdentification(), removeLegalConstraints(), + removeEmptyResourceConstraints(), appendChildren( ...record.legalConstraints.map((c) => createConstraint(c, 'legal', record.defaultLanguage) @@ -948,6 +979,7 @@ export function writeSecurityConstraints( pipe( findOrCreateIdentification(), removeSecurityConstraints(), + removeEmptyResourceConstraints(), appendChildren( ...record.securityConstraints.map((c) => createConstraint(c, 'security', record.defaultLanguage) @@ -963,6 +995,7 @@ export function writeOtherConstraints( pipe( findOrCreateIdentification(), removeOtherConstraints(), + removeEmptyResourceConstraints(), appendChildren( ...record.otherConstraints.map((c) => createConstraint(c, 'other', record.defaultLanguage) diff --git a/libs/feature/editor/src/lib/components/constraint-card/constraint-card.component.html b/libs/feature/editor/src/lib/components/constraint-card/constraint-card.component.html index 42fdfd369..46734ec3a 100644 --- a/libs/feature/editor/src/lib/components/constraint-card/constraint-card.component.html +++ b/libs/feature/editor/src/lib/components/constraint-card/constraint-card.component.html @@ -8,7 +8,11 @@ >
- +   input.image.displayUrlInput diff --git a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-constraints-shortcuts/form-field-constraints-shortcuts.component.html b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-constraints-shortcuts/form-field-constraints-shortcuts.component.html index 5ebc9ca11..4f4ff0aa2 100644 --- a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-constraints-shortcuts/form-field-constraints-shortcuts.component.html +++ b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-constraints-shortcuts/form-field-constraints-shortcuts.component.html @@ -1,4 +1,4 @@ -
+
+
{{ constraintsHeader | translate }} - +  {{ additionalConstraintsButtonLabel | translate }}