Skip to content

Commit

Permalink
Merge pull request #1034 from geonetwork/ME-about-section-fixes
Browse files Browse the repository at this point in the history
[Editor]: About section various fixes
  • Loading branch information
cmoinier authored Nov 12, 2024
2 parents e8eb1e1 + 217cf39 commit 9ee3821
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 102 deletions.
7 changes: 2 additions & 5 deletions apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,8 @@ describe('dashboard (authenticated)', () => {
.as('abstractField')
.focus()
cy.get('@abstractField').type('draft abstract')
cy.editor_readFormUniqueIdentifier().then((recordUuid) => {
cy.window()
.its('localStorage')
.invoke('getItem', `geonetwork-ui-draft-${recordUuid}`)
.should('contain', 'draft abstract')
cy.editor_findDraftInLocalStorage().then((value) => {
expect(value).to.contain('draft abstract')
})
cy.visit('/my-space/my-draft')
cy.get('gn-ui-results-table').find('[data-cy="table-row"]').as('draft')
Expand Down
22 changes: 3 additions & 19 deletions apps/metadata-editor-e2e/src/e2e/edit.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,16 @@ describe('editor form', () => {
.click()
cy.get('[data-test="record-menu-duplicate-button"]').click()
cy.url().should('include', '/duplicate/')
cy.editor_readFormUniqueIdentifier().then((recordUuid) => {
cy.window()
.its('localStorage')
.invoke('getItem', `geonetwork-ui-draft-${recordUuid}`)
.should('exist')
cy.editor_findDraftInLocalStorage().then((value) => {
expect(value).to.not.equal(null)
})
cy.get('md-editor-publish-button').click()

// Open the copy
cy.visit('/catalog/search')
cy.get('gn-ui-fuzzy-search input').type('station épuration copy{enter}')
cy.get('[data-cy="table-row"]').first().children('div').eq(2).click()

cy.url().should('include', '/edit/')
cy.editor_readFormUniqueIdentifier().then((uuid) => {
recordUuid = uuid
})
Expand Down Expand Up @@ -221,19 +218,6 @@ describe('editor form', () => {
.eq(1)
.as('aboutSection')
})
describe('unique identifier', () => {
it('shows the unique identifier', () => {
cy.get('@aboutSection')
.find('gn-ui-form-field')
.eq(0)
.find('gn-ui-form-field-simple')
.find('input')
.invoke('val')
.then((val) => {
cy.get('@recordUuid').should('eq', val)
})
})
})
describe('resource updated', () => {
beforeEach(() => {
cy.get('@aboutSection')
Expand Down
33 changes: 10 additions & 23 deletions apps/metadata-editor-e2e/src/e2e/record-actions.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@ describe('record-actions', () => {
}).as('insertRecord')
cy.get('md-editor-publish-button').click()
cy.wait('@insertRecord')
cy.get('@abstractField').focus()
cy.get('@abstractField').type('draft abstract')
// Assert that the draft exists in the local storage
cy.editor_readFormUniqueIdentifier().then((uniqueIdentifier) =>
cy
.window()
.its('localStorage')
.invoke('getItem', `geonetwork-ui-draft-${uniqueIdentifier}`)
.should('exist')
cy.editor_findDraftInLocalStorage().then((value) =>
expect(value).to.not.equal('null')
)
cy.get('@abstractField').focus()
cy.get('@abstractField').type('draft abstract')
cy.visit('/my-space/my-records')
cy.get('[data-cy="table-row"]')
.contains(recordId)
Expand Down Expand Up @@ -64,11 +60,8 @@ describe('record-actions', () => {
.as('abstractField')
.focus()
cy.get('@abstractField').type('draft abstract')
cy.editor_readFormUniqueIdentifier().then((recordUuid) => {
cy.window()
.its('localStorage')
.invoke('getItem', `geonetwork-ui-draft-${recordUuid}`)
.should('contain', 'draft abstract')
cy.editor_findDraftInLocalStorage().then((value) => {
expect(value).to.contain('draft abstract')
})
cy.visit('/my-space/my-draft')
cy.get('[data-cy="table-row"]')
Expand Down Expand Up @@ -152,11 +145,8 @@ describe('record-actions', () => {
.as('abstractField')
.focus()
cy.get('@abstractField').type('record abstract')
cy.editor_readFormUniqueIdentifier().then((recordUuid) => {
cy.window()
.its('localStorage')
.invoke('getItem', `geonetwork-ui-draft-${recordUuid}`)
.should('exist')
cy.editor_findDraftInLocalStorage().then((value) => {
expect(value).to.not.equal('null')
})

cy.intercept({
Expand All @@ -170,11 +160,8 @@ describe('record-actions', () => {
cy.get('@abstractField').clear()
cy.get('@abstractField').focus()
cy.get('@abstractField').type('draft abstract')
cy.editor_readFormUniqueIdentifier().then((recordUuid) => {
cy.window()
.its('localStorage')
.invoke('getItem', `geonetwork-ui-draft-${recordUuid}`)
.should('contain', 'draft abstract')
cy.editor_findDraftInLocalStorage().then((value) => {
expect(value).to.contain('draft abstract')
})

cy.get('[data-cy="undo-button"]').click()
Expand Down
3 changes: 0 additions & 3 deletions libs/common/fixtures/src/lib/editor/editor.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export const editorFieldRecordUpdatedFixture = () => ({
hidden: false,
formFieldConfig: {
labelKey: 'editor.record.form.field.recordUpdated',
locked: true,
},
value: '2024-07-16T05:18:53.000Z',
onSaveProcess: '${dateNow()}',
Expand Down Expand Up @@ -129,7 +128,6 @@ export const editorFieldUniqueIdentifierFixture = () => ({
hidden: false,
formFieldConfig: {
labelKey: 'editor.record.form.field.uniqueIdentifier',
locked: true,
},
value: 'accroche_velos',
})
Expand All @@ -139,7 +137,6 @@ export const editorFieldLicenseFixture = () => ({
hidden: false,
formFieldConfig: {
labelKey: 'editor.record.form.field.license',
locked: true,
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,12 @@
(valueChange)="valueChange.emit($event)"
></gn-ui-form-field-overviews>
</ng-container>
<ng-container *ngSwitchCase="'uniqueIdentifier'">
<gn-ui-form-field-simple
type="text"
[readonly]="true"
[value]="valueAsString"
(valueChange)="valueChange.emit($event)"
></gn-ui-form-field-simple>
</ng-container>
<ng-container *ngSwitchCase="'resourceUpdated'">
<gn-ui-form-field-date-updated
[value]="valueAsDate"
(valueChange)="valueChange.emit($event)"
></gn-ui-form-field-date-updated>
</ng-container>
<ng-container *ngSwitchCase="'recordUpdated'">
<gn-ui-form-field-date-updated
[value]="valueAsDate"
(valueChange)="valueChange.emit($event)"
></gn-ui-form-field-date-updated>
</ng-container>
<ng-container *ngSwitchCase="'updateFrequency'">
<gn-ui-form-field-update-frequency
[value]="valueAsUpdateFrequency"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { By } from '@angular/platform-browser'
import { FormFieldWrapperComponent } from '@geonetwork-ui/ui/layout'
import { TranslateModule } from '@ngx-translate/core'
import { MockBuilder } from 'ng-mocks'
import { FormFieldLicenseComponent } from './form-field-license/form-field-license.component'
import { FormFieldOverviewsComponent } from './form-field-overviews/form-field-overviews.component'
import { FormFieldDateUpdatedComponent } from './form-field-date-updated/form-field-date-updated.component'
import { FormFieldRichComponent } from './form-field-rich/form-field-rich.component'
import { FormFieldSimpleComponent } from './form-field-simple/form-field-simple.component'
import { FormFieldSpatialExtentComponent } from './form-field-spatial-extent/form-field-spatial-extent.component'
import { FormFieldTemporalExtentsComponent } from './form-field-temporal-extents/form-field-temporal-extents.component'
import { FormFieldUpdateFrequencyComponent } from './form-field-update-frequency/form-field-update-frequency.component'
Expand Down Expand Up @@ -104,29 +102,6 @@ describe('FormFieldComponent', () => {
expect(formField).toBeTruthy()
})
})
describe('simple field', () => {
let fieldWrapper
let formField
beforeEach(async () => {
component.model = 'uniqueIdentifier'
fixture.detectChanges()
await fixture.whenStable()
fieldWrapper = fixture.debugElement.query(
By.directive(FormFieldWrapperComponent)
).componentInstance
formField = fixture.debugElement.query(
By.directive(FormFieldSimpleComponent)
).componentInstance
})
it('creates a simple field field (unique identifier)', () => {
expect(formField).toBeTruthy()
expect(formField.type).toEqual('text')
expect(formField.readonly).toEqual(true)
})
it('creates a form field wrapper', () => {
expect(fieldWrapper).toBeTruthy()
})
})
describe('spatial extent field', () => {
let formField
beforeEach(() => {
Expand Down
18 changes: 9 additions & 9 deletions libs/feature/editor/src/lib/fields.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ import { Keyword } from '@geonetwork-ui/common/domain/model/record'
************************************************************
*/

export const RECORD_UNIQUE_IDENTIFIER_FIELD: EditorField = {
model: 'uniqueIdentifier',
formFieldConfig: {
labelKey: marker('editor.record.form.field.uniqueIdentifier'),
},
hidden: true,
}

export const RECORD_LICENSE_FIELD: EditorField = {
model: 'licenses',
formFieldConfig: {
Expand All @@ -32,14 +40,6 @@ export const RECORD_KEYWORDS_FIELD: EditorField = {
},
}

export const RECORD_UNIQUE_IDENTIFIER_FIELD: EditorField = {
model: 'uniqueIdentifier',
formFieldConfig: {
labelKey: marker('editor.record.form.field.uniqueIdentifier'),
locked: true,
},
}

export const RECORD_RESOURCE_UPDATED_FIELD: EditorField = {
model: 'resourceUpdated',
formFieldConfig: {
Expand All @@ -52,10 +52,10 @@ export const RECORD_UPDATED_FIELD: EditorField = {
model: 'recordUpdated',
formFieldConfig: {
labelKey: marker('editor.record.form.field.recordUpdated'),
locked: true,
},
onSaveProcess: '${dateNow()}',
gridColumnSpan: 1,
hidden: true,
}

export const RECORD_UPDATE_FREQUENCY_FIELD: EditorField = {
Expand Down
1 change: 0 additions & 1 deletion libs/feature/editor/src/lib/models/editor-config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export interface FormFieldConfig {
hintKey?: string
tooltipKey?: string
required?: boolean
locked?: boolean
invalid?: boolean
invalidHintKey?: string
}
Expand Down
30 changes: 27 additions & 3 deletions tools/e2e/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ declare namespace Cypress {
editor_readFormUniqueIdentifier(): Chainable<string | number | string[]>
editor_wrapPreviousDraft(): void
editor_publishAndReload(): void
editor_findDraftInLocalStorage(): Chainable<string | number | string[]>

// interaction with gn-ui-dropdown-selector
openDropdown(): Chainable<JQuery<HTMLElement>>
Expand Down Expand Up @@ -156,9 +157,32 @@ Cypress.Commands.add('clearRecordDrafts', () => {
})

Cypress.Commands.add('editor_readFormUniqueIdentifier', () => {
return cy
.get('gn-ui-form-field[ng-reflect-model=uniqueIdentifier] input')
.invoke('val')
cy.url().then((url) => {
if (url.includes('/edit/')) {
return url.split('edit/').pop()
}
})
})

Cypress.Commands.add('editor_findDraftInLocalStorage', () => {
cy.window().then((win) => {
cy.get('body', { timeout: 10000 })
.should(() => {
const keys = Object.keys(win.localStorage)
const matchingKey = keys.find((key) =>
key.startsWith('geonetwork-ui-draft-')
)

expect(matchingKey).to.not.be.undefined
})
.then(() => {
const keys = Object.keys(win.localStorage)
const matchingKey = keys.find((key) =>
key.startsWith('geonetwork-ui-draft-')
)
return win.localStorage.getItem(matchingKey)
})
})
})

// this needs a recordUuid to have been wrapped
Expand Down

0 comments on commit 9ee3821

Please sign in to comment.