Skip to content

Commit

Permalink
make sure getIssueField returns some default values
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeGoodall committed Oct 21, 2024
1 parent c690786 commit aac6641
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/middleware/issueDetails.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ export const issueErrorMessageHtml = (errorMessage, issue) => {
* @param {*} classes
* @returns {{key: {text: string}, value: { html: string}, classes: string}}
*/
export const getIssueField = (text, html, classes = '') => {
export const getIssueField = (text = '', html = '', classes = '') => {
return {
key: {
text
text: text ?? ''
},
value: {
html
html: html ?? ''
},
classes
classes: classes ?? ''
}
}

Expand Down
66 changes: 66 additions & 0 deletions test/unit/middleware/issueDetails.middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,72 @@ describe('issueDetails.middleware.js', () => {
classes: ''
})
})

it('should return an object with default values if text is null', () => {
const html = '<p>Mock html</p>'
const classes = 'mock-classes'
const result = getIssueField(null, html, classes)
expect(result).toEqual({
key: { text: '' },
value: { html },
classes
})
})

it('should return an object with default values if text is undefined', () => {
const html = '<p>Mock html</p>'
const classes = 'mock-classes'
const result = getIssueField(undefined, html, classes)
expect(result).toEqual({
key: { text: '' },
value: { html },
classes
})
})

it('should return an object with default values if html is null', () => {
const text = 'Mock text'
const classes = 'mock-classes'
const result = getIssueField(text, null, classes)
expect(result).toEqual({
key: { text },
value: { html: '' },
classes
})
})

it('should return an object with default values if html is undefined', () => {
const text = 'Mock text'
const classes = 'mock-classes'
const result = getIssueField(text, undefined, classes)
expect(result).toEqual({
key: { text },
value: { html: '' },
classes
})
})

it('should return an object with default values if classes is null', () => {
const text = 'Mock text'
const html = '<p>Mock html</p>'
const result = getIssueField(text, html, null)
expect(result).toEqual({
key: { text },
value: { html },
classes: ''
})
})

it('should return an object with default values if classes is undefined', () => {
const text = 'Mock text'
const html = '<p>Mock html</p>'
const result = getIssueField(text, html, undefined)
expect(result).toEqual({
key: { text },
value: { html },
classes: ''
})
})
})

describe('prepareIssueDetailsTemplateParams', () => {
Expand Down

0 comments on commit aac6641

Please sign in to comment.