diff --git a/src/middleware/issueDetails.middleware.js b/src/middleware/issueDetails.middleware.js index 4bbd24b0..1bd64291 100644 --- a/src/middleware/issueDetails.middleware.js +++ b/src/middleware/issueDetails.middleware.js @@ -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 ?? '' } } diff --git a/test/unit/middleware/issueDetails.middleware.test.js b/test/unit/middleware/issueDetails.middleware.test.js index abf43ca4..1ddb4b9f 100644 --- a/test/unit/middleware/issueDetails.middleware.test.js +++ b/test/unit/middleware/issueDetails.middleware.test.js @@ -58,6 +58,72 @@ describe('issueDetails.middleware.js', () => { classes: '' }) }) + + it('should return an object with default values if text is null', () => { + const html = '
Mock html
' + 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 = 'Mock html
' + 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 = 'Mock html
' + 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 = 'Mock html
' + const result = getIssueField(text, html, undefined) + expect(result).toEqual({ + key: { text }, + value: { html }, + classes: '' + }) + }) }) describe('prepareIssueDetailsTemplateParams', () => {