jiraCloud/test/jiraRichText.test.js
jmcqueen 98dd33a20e Clean up Jira rich text in Webex approval card details.
Convert wiki markup to readable text and render each detail field in its own card block.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-28 12:26:28 -04:00

79 lines
2.8 KiB
JavaScript

import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { adfToPlainText, formatJiraRichText, formatJiraWikiMarkup } from '../lib/jiraRichText.js';
describe('formatJiraWikiMarkup', () => {
it('converts Jira wiki links to readable text', () => {
const input = '[Repo|https://code.ae.com/projects/SCL/repos/web-apps/browse]';
assert.equal(
formatJiraWikiMarkup(input),
'Repo (https://code.ae.com/projects/SCL/repos/web-apps/browse)'
);
});
it('converts duplicate-url smart links to a single URL', () => {
const input = '[https://aeo.atlassian.net/browse/CHANGE-1|https://aeo.atlassian.net/browse/CHANGE-1|smart-link]';
assert.equal(
formatJiraWikiMarkup(input),
'https://aeo.atlassian.net/browse/CHANGE-1'
);
});
it('normalizes bold markers and bullets', () => {
const input = '* Expected behavior\n** Current behavior';
assert.match(formatJiraWikiMarkup(input), /• Expected behavior/);
assert.match(formatJiraWikiMarkup(input), /Current behavior/);
assert.equal(formatJiraWikiMarkup('**Rollback** plan'), 'Rollback plan');
});
});
describe('adfToPlainText', () => {
it('extracts text from ADF documents', () => {
const adf = {
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [{ type: 'text', text: 'Start approx 4am est' }],
},
{
type: 'bulletList',
content: [
{
type: 'listItem',
content: [
{
type: 'paragraph',
content: [{ type: 'text', text: 'Deploy banner update' }],
},
],
},
],
},
],
};
assert.match(adfToPlainText(adf), /Start approx 4am est/);
assert.match(adfToPlainText(adf), /Deploy banner update/);
});
});
describe('formatJiraRichText', () => {
it('formats wiki strings and ADF objects', () => {
assert.equal(formatJiraRichText('**Rollback** plan'), 'Rollback plan');
assert.equal(
formatJiraRichText({
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [{ type: 'text', text: 'Ready for approval' }],
},
],
}),
'Ready for approval'
);
});
});