Skip to content

Commit

Permalink
Merge pull request #965 from geonetwork/ME-fix-new-record-crash
Browse files Browse the repository at this point in the history
fix(ME): do not return null on text fields for new records
  • Loading branch information
jahow authored Aug 22, 2024
2 parents 38f835a + 621b04f commit 825a487
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
34 changes: 34 additions & 0 deletions apps/metadata-editor-e2e/src/e2e/create.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
describe('create', () => {
beforeEach(() => {
cy.login('admin', 'admin', false)
cy.visit('/catalog/search')
})

describe('create new record', () => {
it('should create the record without error', () => {
// First create a record and its draft
cy.get('[data-cy="create-record"]').click()

// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(1200) // waiting for draft saving to kick in

// Check that the record is correctly displayed
cy.get('gn-ui-record-form').should('be.visible')

cy.get('gn-ui-record-form')
.children()
.eq(0)
.children()
.should('have.length', 3)

cy.get('[data-test="previousNextPageButtons"]')
.children()
.eq(0)
.should('contain.text', 'Come back later')
cy.get('[data-test="previousNextPageButtons"]')
.children()
.eq(1)
.should('contain.text', 'Next')
})
})
})
2 changes: 1 addition & 1 deletion apps/metadata-editor-e2e/src/e2e/edit.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('editor form', () => {
cy.get('@abstractField').clear()
cy.get('@abstractField').type('modified abstract')
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(1000) // waiting for draft saving to kick in
cy.wait(1200) // waiting for draft saving to kick in
cy.reload()
cy.get('@abstractField').invoke('val').should('eq', 'modified abstract')
cy.get('@saveStatus').should('eq', 'draft_changes_pending')
Expand Down
5 changes: 4 additions & 1 deletion apps/metadata-editor/src/app/edit/edit-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
</div>
<gn-ui-record-form></gn-ui-record-form>
</div>
<div class="p-8 mt-auto flex flex-row justify-between">
<div
data-test="previousNextPageButtons"
class="p-8 mt-auto flex flex-row justify-between"
>
<gn-ui-button
type="secondary"
(buttonClick)="previousPageButtonHandler()"
Expand Down
18 changes: 18 additions & 0 deletions libs/api/metadata-converter/src/lib/xml-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { XmlElement } from '@rgrove/parse-xml'
import {
getRootElement,
parseXmlString,
readText,
renameElements,
xmlToString,
} from './xml-utils'
Expand Down Expand Up @@ -144,4 +145,21 @@ end.
`)
})
})

describe('readText', () => {
it('returns the text node in an element', () => {
const input = parseXmlString(`
<root>hello
world</root>
`).root
expect(readText()(input)).toEqual('hello\nworld')
})
it('returns an empty string if no text node', () => {
const input = parseXmlString(`<root/>`).root
expect(readText()(input)).toEqual('')
})
it('returns null if applied to a falsy element', () => {
expect(readText()(null)).toEqual(null)
})
})
})
10 changes: 5 additions & 5 deletions libs/api/metadata-converter/src/lib/xml-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ export function findParent(

export function readText(): ChainableFunction<XmlElement, string> {
return (el) => {
const textNode =
el && Array.isArray(el.children)
? (el.children.find((node) => node.type === 'text') as XmlText)
: null
return textNode ? textNode.text : null
if (!el) return null
const textNode = Array.isArray(el.children)
? (el.children.find((node) => node.type === 'text') as XmlText)
: null
return textNode ? textNode.text : ''
}
}

Expand Down

0 comments on commit 825a487

Please sign in to comment.