Welcome to mirror list, hosted at ThFree Co, Russian Federation.

notification_spec.js « utils « whats_new « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e1de65df30fed9a2d415c140617b096ee9e8530e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
import { setNotification, getVersionDigest } from '~/whats_new/utils/notification';

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(() => {
    loadFixtures('static/whats_new_notification.html');
    wrapper = document.querySelector('.whats-new-notification-fixture-root');
  });

  afterEach(() => {
    wrapper.remove();
  });

  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();

      expect(findNotificationCountEl()).toExist();
      expect(notificationEl.classList).toContain('with-notifications');
    });

    it('removes class and count element when legacy storage key is false', () => {
      const notificationEl = findNotificationEl();
      notificationEl.classList.add('with-notifications');
      localStorage.setItem('display-whats-new-notification-13.10', 'false');

      expect(findNotificationCountEl()).toExist();

      subject();

      expect(findNotificationCountEl()).not.toExist();
      expect(notificationEl.classList).not.toContain('with-notifications');
    });

    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');

      expect(findNotificationCountEl()).toExist();

      subject();

      expect(findNotificationCountEl()).not.toExist();
      expect(notificationEl.classList).not.toContain('with-notifications');
    });
  });

  describe('getVersionDigest', () => {
    it('retrieves the storage key data attribute from the el', () => {
      expect(getVersionDigest(getAppEl())).toBe('version-digest');
    });
  });
});