Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata Editor: constraints fields #1032

Merged
merged 11 commits into from
Nov 17, 2024
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
Loading