summaryrefslogtreecommitdiff
path: root/spec/frontend/releases/release_notification_service_spec.js
blob: 2344d4b929ac1c686e1c816c7e46702a9daf3a97 (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
import {
  popCreateReleaseNotification,
  putCreateReleaseNotification,
} from '~/releases/release_notification_service';
import { createAlert, VARIANT_SUCCESS } from '~/flash';

jest.mock('~/flash');

describe('~/releases/release_notification_service', () => {
  const projectPath = 'test-project-path';
  const releaseName = 'test-release-name';

  const storageKey = `createRelease:${projectPath}`;

  describe('prepareCreateReleaseFlash', () => {
    it('should set the session storage with project path key and release name value', () => {
      putCreateReleaseNotification(projectPath, releaseName);

      const item = window.sessionStorage.getItem(storageKey);

      expect(item).toBe(releaseName);
    });
  });

  describe('showNotificationsIfPresent', () => {
    describe('if notification is prepared', () => {
      beforeEach(() => {
        window.sessionStorage.setItem(storageKey, releaseName);
        popCreateReleaseNotification(projectPath);
      });

      it('should remove storage key', () => {
        const item = window.sessionStorage.getItem(storageKey);

        expect(item).toBe(null);
      });

      it('should create a flash message', () => {
        expect(createAlert).toHaveBeenCalledTimes(1);
        expect(createAlert).toHaveBeenCalledWith({
          message: `Release ${releaseName} has been successfully created.`,
          variant: VARIANT_SUCCESS,
        });
      });
    });

    describe('if notification is not prepared', () => {
      beforeEach(() => {
        popCreateReleaseNotification(projectPath);
      });

      it('should not create a flash message', () => {
        expect(createAlert).toHaveBeenCalledTimes(0);
      });
    });
  });
});