Skip to content

Commit

Permalink
fix: remove usage of backgroundBox as string
Browse files Browse the repository at this point in the history
  • Loading branch information
umbobabo committed Mar 14, 2023
1 parent 6d963a3 commit 1449a93
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 35 deletions.
12 changes: 3 additions & 9 deletions src/lib/get-topper-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,10 @@ const useEditoriallySelectedTopper = (content) => {
if (content.topper.layout === 'full-bleed-offset') {
backgroundColour = 'wheat';
} else if (content.topper.layout === 'deep-landscape') {
// If the backgroundBox is present, use its color to determine a background colour
// The background color won't be visible due to the overlapping image, however, it's needed to
// determine the text color
if (content.topper.backgroundBox) {
backgroundColour =
content.topper.backgroundBox === 'light' ? 'white' : 'black';
} else if (!hasDarkBackground(content.topper.backgroundColour)) {
backgroundColour = 'white';
} else {
if (hasDarkBackground(content.topper.backgroundColour)) {
backgroundColour = 'black';
} else {
backgroundColour = 'white';
}
} else if (
content.topper.backgroundColour === 'pink' ||
Expand Down
30 changes: 4 additions & 26 deletions test/lib/get-topper-settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,51 +114,29 @@ describe('Get topper settings', () => {
expect(topper.backgroundColour).to.equal('wheat');
});

it('sets the `backgroundColour` to `white` if layout is deep landscape and background is light', () => {
it('sets the `backgroundColour` to `white` if layout is deep landscape and the background is auto', () => {
const topper = getTopperSettings({
topper: { layout: 'deep-landscape', backgroundColour: 'paper' }
topper: { layout: 'deep-landscape', backgroundColour: 'auto' }
});

expect(topper.backgroundColour).to.equal('white');
});

it('sets the `backgroundColour` to `black` if layout is deep landscape and background is dark', () => {
it('sets the `backgroundColour` to `black` if layout is deep landscape and background is slate', () => {
const topper = getTopperSettings({
topper: { layout: 'deep-landscape', backgroundColour: 'slate' }
});

expect(topper.backgroundColour).to.equal('black');
});

it('sets the `backgroundColour` to `white` if layout is deep landscape and background is undefined', () => {
const topper = getTopperSettings({
topper: { layout: 'deep-landscape' }
});

expect(topper.backgroundColour).to.equal('white');
});

describe('When a background Box is present', () => {
it('sets the `backgroundColour` to `white` if layout is deep landscape and background Box is light', () => {
const topper = getTopperSettings({
topper: {
layout: 'deep-landscape',
backgroundBox: 'light'
}
});

expect(topper.backgroundColour).to.equal('white');
});
it('sets the `backgroundColour` to `black` if layout is deep landscape and background Box is dark', () => {
const topper = getTopperSettings({
topper: {
layout: 'deep-landscape',
backgroundBox: 'dark'
}
});

expect(topper.backgroundColour).to.equal('black');
});
});
});

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

0 comments on commit 1449a93

Please sign in to comment.