2022-05-13 08:08:49 -04:00
|
|
|
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2020-12-03 13:10:10 -05:00
|
|
|
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
|
2021-04-12 17:11:12 -04:00
|
|
|
import { setNotification, getVersionDigest } from '~/whats_new/utils/notification';
|
2020-12-03 13:10:10 -05:00
|
|
|
|
|
|
|
describe('~/whats_new/utils/notification', () => {
|
|
|
|
useLocalStorageSpy();
|
|
|
|
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const findNotificationEl = () => wrapper.querySelector('.header-help');
|
|
|
|
const findNotificationCountEl = () => wrapper.querySelector('.js-whats-new-notification-count');
|
|
|
|
const getAppEl = () => wrapper.querySelector('.app');
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-05-13 08:08:49 -04:00
|
|
|
loadHTMLFixture('static/whats_new_notification.html');
|
2020-12-03 13:10:10 -05:00
|
|
|
wrapper = document.querySelector('.whats-new-notification-fixture-root');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.remove();
|
2022-05-13 08:08:49 -04:00
|
|
|
resetHTMLFixture();
|
2020-12-03 13:10:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('setNotification', () => {
|
|
|
|
const subject = () => setNotification(getAppEl());
|
|
|
|
|
|
|
|
it("when storage key doesn't exist it adds notifications class", () => {
|
|
|
|
const notificationEl = findNotificationEl();
|
|
|
|
|
|
|
|
expect(notificationEl.classList).not.toContain('with-notifications');
|
|
|
|
|
|
|
|
subject();
|
|
|
|
|
2021-11-10 01:10:31 -05:00
|
|
|
expect(findNotificationCountEl()).not.toBe(null);
|
2020-12-03 13:10:10 -05:00
|
|
|
expect(notificationEl.classList).toContain('with-notifications');
|
|
|
|
});
|
|
|
|
|
2021-04-12 17:11:12 -04:00
|
|
|
it('removes class and count element when storage key has current digest', () => {
|
|
|
|
const notificationEl = findNotificationEl();
|
|
|
|
notificationEl.classList.add('with-notifications');
|
|
|
|
localStorage.setItem('display-whats-new-notification', 'version-digest');
|
2020-12-03 13:10:10 -05:00
|
|
|
|
2021-11-10 01:10:31 -05:00
|
|
|
expect(findNotificationCountEl()).not.toBe(null);
|
2020-12-03 13:10:10 -05:00
|
|
|
|
|
|
|
subject();
|
|
|
|
|
2021-11-10 01:10:31 -05:00
|
|
|
expect(findNotificationCountEl()).toBe(null);
|
2020-12-03 13:10:10 -05:00
|
|
|
expect(notificationEl.classList).not.toContain('with-notifications');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-12 17:11:12 -04:00
|
|
|
describe('getVersionDigest', () => {
|
2020-12-03 13:10:10 -05:00
|
|
|
it('retrieves the storage key data attribute from the el', () => {
|
2021-04-12 17:11:12 -04:00
|
|
|
expect(getVersionDigest(getAppEl())).toBe('version-digest');
|
2020-12-03 13:10:10 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|