Skip to content

Commit

Permalink
Merge pull request #1032 from geonetwork/ME-record-field-contraints
Browse files Browse the repository at this point in the history
Metadata Editor: constraints fields
  • Loading branch information
jahow authored Nov 17, 2024
2 parents 89e0d3b + d95bd18 commit 1aab0c3
Show file tree
Hide file tree
Showing 59 changed files with 1,901 additions and 245 deletions.
122 changes: 118 additions & 4 deletions apps/metadata-editor-e2e/src/e2e/edit.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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')
Expand All @@ -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)
})
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ Cette section contient des *caractères internationaux* (ainsi que des "caractè
<gmd:MD_ClassificationCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_ClassificationCode" codeListValue="restricted"/>
</gmd:classification>
<gmd:useLimitation>
<gco:CharacterString>Contains sensitive information related to national defense</gco:CharacterString>
<gmx:Anchor xlink:href="https://security.org/document.pdf">Contains sensitive information related to national defense</gmx:Anchor>
<gmd:PT_FreeText>
<gmd:textGroup>
<gmd:LocalisedCharacterString locale="#EN">Contains sensitive information related to national defense</gmd:LocalisedCharacterString>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ Cette section contient des *caractères internationaux* (ainsi que des "caractè
codeListValue="restricted"/>
</mco:classification>
<mco:useLimitation>
<gco:CharacterString>Contains sensitive information related to national defense</gco:CharacterString>
<gcx:Anchor xlink:href="https://security.org/document.pdf">Contains sensitive information related to national defense</gcx:Anchor>
<lan:PT_FreeText>
<mdb:textGroup>
<mdb:LocalisedCharacterString locale="#EN">Contains sensitive information related to national defense</mdb:LocalisedCharacterString>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ Cette section contient des *caractères internationaux* (ainsi que des "caractè
codeListValue="restricted"/>
</mco:classification>
<mco:useLimitation>
<gco:CharacterString>Contains sensitive information related to national defense</gco:CharacterString>
<gcx:Anchor xlink:href="https://security.org/document.pdf">Contains sensitive information related to national defense</gcx:Anchor>
<lan:PT_FreeText>
<mdb:textGroup>
<mdb:LocalisedCharacterString locale="#EN">Contains sensitive information related to national defense</mdb:LocalisedCharacterString>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ Cette section contient des *caractères internationaux* (ainsi que des "caractè
<gmd:MD_ClassificationCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_ClassificationCode" codeListValue="restricted"/>
</gmd:classification>
<gmd:useLimitation>
<gco:CharacterString>Contains sensitive information related to national defense</gco:CharacterString>
<gmx:Anchor xlink:href="https://security.org/document.pdf">Contains sensitive information related to national defense</gmx:Anchor>
<gmd:PT_FreeText>
<gmd:textGroup>
<gmd:LocalisedCharacterString locale="#EN">Contains sensitive information related to national defense</gmd:LocalisedCharacterString>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ As such, **it is not very interesting at all.**`,
securityConstraints: [
{
text: 'Contains sensitive information related to national defense',
url: new URL('https://security.org/document.pdf'),
translations: {
text: {
fr: 'Contient des informations sensibles liées à la défense nationale',
Expand Down
54 changes: 54 additions & 0 deletions libs/api/metadata-converter/src/lib/iso19139/write-parts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import {
writeContacts,
writeContactsForResource,
writeKeywords,
writeLegalConstraints,
writeOnlineResources,
writeOtherConstraints,
writeResourceCreated,
writeResourcePublished,
writeResourceUpdated,
writeSecurityConstraints,
writeSpatialExtents,
writeSpatialRepresentation,
writeTemporalExtents,
Expand Down Expand Up @@ -973,6 +976,57 @@ describe('write parts', () => {
<gmd:identificationInfo>
<gmd:MD_DataIdentification/>
</gmd:identificationInfo>
</root>`)
})
})

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(`<root>
<gmd:identificationInfo>
<gmd:MD_DataIdentification>
<gmd:resourceConstraints>
<gmd:MD_SecurityConstraints>
<gmd:classification>
<gmd:MD_ClassificationCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_ClassificationCode" codeListValue="restricted"/>
</gmd:classification>
<gmd:useLimitation>
<gmx:Anchor xlink:href="https://security.org/document.pdf">Contains sensitive information related to national defense</gmx:Anchor>
<gmd:PT_FreeText>
<gmd:textGroup>
<gmd:LocalisedCharacterString locale="#EN">Contains sensitive information related to national defense</gmd:LocalisedCharacterString>
</gmd:textGroup>
<gmd:textGroup>
<gmd:LocalisedCharacterString locale="#FR">Contient des informations sensibles liées à la défense nationale</gmd:LocalisedCharacterString>
</gmd:textGroup>
</gmd:PT_FreeText>
</gmd:useLimitation>
</gmd:MD_SecurityConstraints>
</gmd:resourceConstraints>
<gmd:resourceConstraints>
<gmd:MD_Constraints>
<gmd:useLimitation>
<gco:CharacterString>new constraint</gco:CharacterString>
</gmd:useLimitation>
</gmd:MD_Constraints>
</gmd:resourceConstraints>
</gmd:MD_DataIdentification>
</gmd:identificationInfo>
</root>`)
})
})
Expand Down
Loading

0 comments on commit 1aab0c3

Please sign in to comment.