diff options
Diffstat (limited to 'spec/frontend/releases/release_notification_service_spec.js')
-rw-r--r-- | spec/frontend/releases/release_notification_service_spec.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/frontend/releases/release_notification_service_spec.js b/spec/frontend/releases/release_notification_service_spec.js new file mode 100644 index 00000000000..2344d4b929a --- /dev/null +++ b/spec/frontend/releases/release_notification_service_spec.js @@ -0,0 +1,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); + }); + }); + }); +}); |