Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/steps/render-body.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { maybeHTML } from './utils.js';
export function formatPrice(price) {
if (!price) return '';
const { regular, final } = price;
if (!final || final === '') {
return h('p', `$${regular}`);
}
if (parseFloat(final) < parseFloat(regular)) {
return h('p', [`$${final} `, '(', h('del', `$${regular}`), ')']);
}
Expand Down
28 changes: 21 additions & 7 deletions test/steps/render-body.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,6 @@ describe('formatPrice', () => {
assert.strictEqual(result.children[0].value, '$N/A');
});

it('displays final price when final is empty string', () => {
const result = formatPrice({ final: '', regular: '99.99' });
assert.strictEqual(result.tagName, 'p');
assert.strictEqual(result.children.length, 1);
assert.strictEqual(result.children[0].value, '$');
});

it('displays final price when regular is undefined', () => {
const result = formatPrice({ final: '79.99', regular: undefined });
assert.strictEqual(result.tagName, 'p');
Expand All @@ -172,6 +165,27 @@ describe('formatPrice', () => {
assert.strictEqual(result.children.length, 4);
assert.strictEqual(result.children[0].value, '$79.99abc ');
});

it('displays regular price when final is empty string', () => {
const result = formatPrice({ final: '', regular: '99.99' });
assert.strictEqual(result.tagName, 'p');
assert.strictEqual(result.children.length, 1);
assert.strictEqual(result.children[0].value, '$99.99');
});

it('displays regular price when final is undefined', () => {
const result = formatPrice({ final: undefined, regular: '99.99' });
assert.strictEqual(result.tagName, 'p');
assert.strictEqual(result.children.length, 1);
assert.strictEqual(result.children[0].value, '$99.99');
});

it('displays regular price when final is undefined', () => {
const result = formatPrice({ final: null, regular: '99.99' });
assert.strictEqual(result.tagName, 'p');
assert.strictEqual(result.children.length, 1);
assert.strictEqual(result.children[0].value, '$99.99');
});
});

describe('edge cases with zero', () => {
Expand Down
Loading