Refactored announcement bar settings tests

refs https://github.com/TryGhost/Team/issues/3051

- Made unit tests in the announcement bar settings package more concise
This commit is contained in:
Naz 2023-04-21 15:14:09 +02:00
parent d3a60c760b
commit 6928235c48
No known key found for this signature in database

View File

@ -15,91 +15,81 @@ describe('AnnouncementBarSettings', function () {
});
describe('getAnnouncementSettings', function () {
it('returns undefined if there is no announcement content', function () {
const testVisibility = (announcementSettings, member, expected) => {
const announcementBarSettings = new AnnouncementBarSettings({
getAnnouncementSettings: () => ({
announcement: null,
announcement_visibility: [],
announcement_background: 'dark'
})
getAnnouncementSettings: () => (announcementSettings)
});
const settings = announcementBarSettings.getAnnouncementSettings();
const settings = announcementBarSettings.getAnnouncementSettings(member);
assert.equal(settings, undefined);
assert.deepEqual(settings, expected);
};
it('returns undefined settings if there is no announcement content', function () {
testVisibility({
announcement: null,
announcement_visibility: []
}, undefined, undefined);
});
it('returns undefined announcement settings if there is no announcement visibility', function () {
const announcementBarSettings = new AnnouncementBarSettings({
getAnnouncementSettings: () => ({
testVisibility({
announcement: {
announcement: 'Hello world',
announcement_visibility: [],
announcement_background: 'dark'
})
});
const settings = announcementBarSettings.getAnnouncementSettings();
assert.equal(settings, undefined);
announcement_visibility: []
},
announcement_visibility: []
}, undefined, undefined);
});
it('returns announcement if visibility is set to visitors and there is no logged in member', function () {
const announcementBarSettings = new AnnouncementBarSettings({
getAnnouncementSettings: () => ({
announcement: 'Hello world',
announcement_visibility: ['visitors'],
announcement_background: 'dark'
})
testVisibility({
announcement: 'Hello world',
announcement_visibility: ['visitors'],
announcement_background: 'dark'
}, undefined, {
announcement: 'Hello world',
announcement_background: 'dark'
});
const settings = announcementBarSettings.getAnnouncementSettings();
assert.equal(settings.announcement, 'Hello world');
});
it('returns announcement if visibility is set to free members and member is free', function () {
const announcementBarSettings = new AnnouncementBarSettings({
getAnnouncementSettings: () => ({
announcement: 'Hello world',
announcement_visibility: ['free_members'],
announcement_background: 'dark'
})
});
const settings = announcementBarSettings.getAnnouncementSettings({
testVisibility({
announcement: 'Hello world',
announcement_visibility: ['free_members'],
announcement_background: 'dark'
}, {
status: 'free'
}, {
announcement: 'Hello world',
announcement_background: 'dark'
});
assert.equal(settings.announcement, 'Hello world');
});
it('returns announcement if visibility is set to paid members and member is paid', function () {
const announcementBarSettings = new AnnouncementBarSettings({
getAnnouncementSettings: () => ({
announcement: 'Hello world',
announcement_visibility: ['paid_members'],
announcement_background: 'dark'
})
});
const settings = announcementBarSettings.getAnnouncementSettings({
testVisibility({
announcement: 'Hello world',
announcement_visibility: ['paid_members'],
announcement_background: 'dark'
}, {
status: 'paid'
}, {
announcement: 'Hello world',
announcement_background: 'dark'
});
assert.equal(settings.announcement, 'Hello world');
});
it('returns announcement if visibility is set to paid and paid members and member is comped', function () {
const announcementBarSettings = new AnnouncementBarSettings({
getAnnouncementSettings: () => ({
announcement: 'Hello world',
announcement_visibility: ['paid_members'],
announcement_background: 'dark'
})
});
const settings = announcementBarSettings.getAnnouncementSettings({
testVisibility({
announcement: 'Hello world',
announcement_visibility: ['paid_members'],
announcement_background: 'dark'
}, {
status: 'comped'
}, {
announcement: 'Hello world',
announcement_background: 'dark'
});
assert.equal(settings.announcement, 'Hello world');
});
});
});