2022-07-16 23:28:13 +05:30
|
|
|
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2021-02-22 17:27:13 +05:30
|
|
|
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
|
2021-04-29 21:17:54 +05:30
|
|
|
import { setNotification, getVersionDigest } from '~/whats_new/utils/notification';
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
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-07-16 23:28:13 +05:30
|
|
|
loadHTMLFixture('static/whats_new_notification.html');
|
2021-02-22 17:27:13 +05:30
|
|
|
wrapper = document.querySelector('.whats-new-notification-fixture-root');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.remove();
|
2022-07-16 23:28:13 +05:30
|
|
|
resetHTMLFixture();
|
2021-02-22 17:27:13 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
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-12-11 22:18:48 +05:30
|
|
|
expect(findNotificationCountEl()).not.toBe(null);
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(notificationEl.classList).toContain('with-notifications');
|
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it('removes class and count element when storage key has current digest', () => {
|
2021-02-22 17:27:13 +05:30
|
|
|
const notificationEl = findNotificationEl();
|
|
|
|
notificationEl.classList.add('with-notifications');
|
2021-04-29 21:17:54 +05:30
|
|
|
localStorage.setItem('display-whats-new-notification', 'version-digest');
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(findNotificationCountEl()).not.toBe(null);
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
subject();
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(findNotificationCountEl()).toBe(null);
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(notificationEl.classList).not.toContain('with-notifications');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe('getVersionDigest', () => {
|
2021-02-22 17:27:13 +05:30
|
|
|
it('retrieves the storage key data attribute from the el', () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(getVersionDigest(getAppEl())).toBe('version-digest');
|
2021-02-22 17:27:13 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|