debian-mirror-gitlab/spec/frontend/releases/release_notification_service_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

109 lines
3.3 KiB
JavaScript
Raw Normal View History

2023-04-23 21:23:45 +05:30
import {
popCreateReleaseNotification,
putCreateReleaseNotification,
2023-07-09 08:55:56 +05:30
popDeleteReleaseNotification,
putDeleteReleaseNotification,
2023-04-23 21:23:45 +05:30
} from '~/releases/release_notification_service';
2023-05-27 22:25:52 +05:30
import { createAlert, VARIANT_SUCCESS } from '~/alert';
2023-04-23 21:23:45 +05:30
2023-05-27 22:25:52 +05:30
jest.mock('~/alert');
2023-04-23 21:23:45 +05:30
describe('~/releases/release_notification_service', () => {
const projectPath = 'test-project-path';
const releaseName = 'test-release-name';
2023-07-09 08:55:56 +05:30
describe('create release', () => {
const storageKey = `createRelease:${projectPath}`;
2023-04-23 21:23:45 +05:30
2023-07-09 08:55:56 +05:30
describe('prepareFlash', () => {
it('should set the session storage with project path key and release name value', () => {
putCreateReleaseNotification(projectPath, releaseName);
2023-04-23 21:23:45 +05:30
2023-07-09 08:55:56 +05:30
const item = window.sessionStorage.getItem(storageKey);
2023-04-23 21:23:45 +05:30
2023-07-09 08:55:56 +05:30
expect(item).toBe(releaseName);
});
2023-04-23 21:23:45 +05:30
});
2023-07-09 08:55:56 +05:30
describe('showNotificationsIfPresent', () => {
describe('if notification is prepared', () => {
beforeEach(() => {
window.sessionStorage.setItem(storageKey, releaseName);
popCreateReleaseNotification(projectPath);
});
2023-04-23 21:23:45 +05:30
2023-07-09 08:55:56 +05:30
it('should remove storage key', () => {
const item = window.sessionStorage.getItem(storageKey);
expect(item).toBe(null);
});
2023-04-23 21:23:45 +05:30
2023-07-09 08:55:56 +05:30
it('should create an alert message', () => {
expect(createAlert).toHaveBeenCalledTimes(1);
expect(createAlert).toHaveBeenCalledWith({
message: `Release ${releaseName} has been successfully created.`,
variant: VARIANT_SUCCESS,
});
});
2023-04-23 21:23:45 +05:30
});
2023-07-09 08:55:56 +05:30
describe('if notification is not prepared', () => {
beforeEach(() => {
popCreateReleaseNotification(projectPath);
});
it('should not create an alert message', () => {
expect(createAlert).toHaveBeenCalledTimes(0);
2023-04-23 21:23:45 +05:30
});
});
});
2023-07-09 08:55:56 +05:30
});
describe('delete release', () => {
const storageKey = `deleteRelease:${projectPath}`;
describe('prepareFlash', () => {
it('should set the session storage with project path key and release name value', () => {
putDeleteReleaseNotification(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);
popDeleteReleaseNotification(projectPath);
});
2023-04-23 21:23:45 +05:30
2023-07-09 08:55:56 +05:30
it('should remove storage key', () => {
const item = window.sessionStorage.getItem(storageKey);
expect(item).toBe(null);
});
it('should create an alert message', () => {
expect(createAlert).toHaveBeenCalledTimes(1);
expect(createAlert).toHaveBeenCalledWith({
message: `Release ${releaseName} has been successfully deleted.`,
variant: VARIANT_SUCCESS,
});
});
2023-04-23 21:23:45 +05:30
});
2023-07-09 08:55:56 +05:30
describe('if notification is not prepared', () => {
beforeEach(() => {
popDeleteReleaseNotification(projectPath);
});
it('should not create an alert message', () => {
expect(createAlert).toHaveBeenCalledTimes(0);
});
2023-04-23 21:23:45 +05:30
});
});
});
});