Commit f9de7156 authored by Alexander Turinske's avatar Alexander Turinske

Refactor onboarding component tests to jest

- move ee/spec/javascript/frontend/onboarding tests
  to ee/spec/frontend/onboarding
- migrate tests from karma to jest
parent d10ee385
...@@ -66,7 +66,7 @@ describe('User onboarding new project utils', () => { ...@@ -66,7 +66,7 @@ describe('User onboarding new project utils', () => {
form = document.getElementById('new_project'); form = document.getElementById('new_project');
submitBtn = document.getElementById('submitBtn'); submitBtn = document.getElementById('submitBtn');
form.addEventListener('submit', submitSpy); form.addEventListener('submit', submitSpy);
jest.spyOn(form, 'submit').mockImplementation(() => {}); jest.spyOn(form, 'submit');
}); });
describe('when onboarding is not dismissed and there is an onboarding state on the local storage', () => { describe('when onboarding is not dismissed and there is an onboarding state on the local storage', () => {
...@@ -82,7 +82,7 @@ describe('User onboarding new project utils', () => { ...@@ -82,7 +82,7 @@ describe('User onboarding new project utils', () => {
bindOnboardingEvents(form); bindOnboardingEvents(form);
expect(form.addEventListener).toHaveBeenCalledWith('submit', jasmine.any(Function)); expect(form.addEventListener).toHaveBeenCalledWith('submit', expect.any(Function));
}); });
it('calls updateLocalStorage with the correct project path when the form is submitted', () => { it('calls updateLocalStorage with the correct project path when the form is submitted', () => {
......
...@@ -32,23 +32,23 @@ describe('User onboarding action popover', () => { ...@@ -32,23 +32,23 @@ describe('User onboarding action popover', () => {
describe('when mounted', () => { describe('when mounted', () => {
it("binds 'onboardingHelper.showActionPopover', 'onboardingHelper.hideActionPopover' and 'onboardingHelper.destroyActionPopover' event listener on eventHub", () => { it("binds 'onboardingHelper.showActionPopover', 'onboardingHelper.hideActionPopover' and 'onboardingHelper.destroyActionPopover' event listener on eventHub", () => {
spyOn(eventHub, '$on'); jest.spyOn(eventHub, '$on');
createComponent(); createComponent();
expect(eventHub.$on).toHaveBeenCalledWith( expect(eventHub.$on).toHaveBeenCalledWith(
'onboardingHelper.showActionPopover', 'onboardingHelper.showActionPopover',
jasmine.any(Function), expect.any(Function),
); );
expect(eventHub.$on).toHaveBeenCalledWith( expect(eventHub.$on).toHaveBeenCalledWith(
'onboardingHelper.hideActionPopover', 'onboardingHelper.hideActionPopover',
jasmine.any(Function), expect.any(Function),
); );
expect(eventHub.$on).toHaveBeenCalledWith( expect(eventHub.$on).toHaveBeenCalledWith(
'onboardingHelper.destroyActionPopover', 'onboardingHelper.destroyActionPopover',
jasmine.any(Function), expect.any(Function),
); );
}); });
}); });
...@@ -60,7 +60,7 @@ describe('User onboarding action popover', () => { ...@@ -60,7 +60,7 @@ describe('User onboarding action popover', () => {
describe('beforeDestroy', () => { describe('beforeDestroy', () => {
it("unbinds 'showActionPopover', 'hideActionPopover' and 'destroyActionPopover' event handler", () => { it("unbinds 'showActionPopover', 'hideActionPopover' and 'destroyActionPopover' event handler", () => {
spyOn(eventHub, '$off'); jest.spyOn(eventHub, '$off');
wrapper.destroy(); wrapper.destroy();
......
import Vue from 'vue'; import Vue from 'vue';
import OnboardingHelperApp from 'ee/onboarding/onboarding_helper/components/app.vue'; import OnboardingHelperApp from 'ee/onboarding/onboarding_helper/components/app.vue';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
import eventHub from 'ee/onboarding/onboarding_helper/event_hub'; import eventHub from 'ee/onboarding/onboarding_helper/event_hub';
import createStore from 'ee/onboarding/onboarding_helper/store'; import createStore from 'ee/onboarding/onboarding_helper/store';
import actionPopoverUtils from 'ee/onboarding/onboarding_helper/action_popover_utils'; import actionPopoverUtils from 'ee/onboarding/onboarding_helper/action_popover_utils';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import { mockTourData } from '../mock_data'; import { mockTourData } from '../mock_data';
import { redirectTo } from '~/lib/utils/url_utility';
jest.mock('~/lib/utils/url_utility', () => ({
redirectTo: jest.fn(),
}));
describe('User onboarding helper app', () => { describe('User onboarding helper app', () => {
let vm; let vm;
...@@ -55,7 +60,7 @@ describe('User onboarding helper app', () => { ...@@ -55,7 +60,7 @@ describe('User onboarding helper app', () => {
beforeEach(() => { beforeEach(() => {
vm = createComponent(); vm = createComponent();
spyOn(vm, 'init'); jest.spyOn(vm, 'init');
vm.$mount(); vm.$mount();
}); });
...@@ -122,7 +127,7 @@ describe('User onboarding helper app', () => { ...@@ -122,7 +127,7 @@ describe('User onboarding helper app', () => {
describe('methods', () => { describe('methods', () => {
describe('initActionPopover', () => { describe('initActionPopover', () => {
it('calls renderPopover with the correct data', () => { it('calls renderPopover with the correct data', () => {
spyOn(actionPopoverUtils, 'renderPopover'); jest.spyOn(actionPopoverUtils, 'renderPopover');
const expected = { const expected = {
selector: '.popup-trigger', selector: '.popup-trigger',
...@@ -144,7 +149,7 @@ describe('User onboarding helper app', () => { ...@@ -144,7 +149,7 @@ describe('User onboarding helper app', () => {
}); });
it('calls renderPopover with showPopover=true if there is no helpContent data and no popover selector for the current url', () => { it('calls renderPopover with showPopover=true if there is no helpContent data and no popover selector for the current url', () => {
spyOn(actionPopoverUtils, 'renderPopover'); jest.spyOn(actionPopoverUtils, 'renderPopover');
vm.$store.state.url = 'http://gitlab-org/gitlab-test/xyz'; vm.$store.state.url = 'http://gitlab-org/gitlab-test/xyz';
...@@ -170,7 +175,7 @@ describe('User onboarding helper app', () => { ...@@ -170,7 +175,7 @@ describe('User onboarding helper app', () => {
describe('showActionPopover', () => { describe('showActionPopover', () => {
it('emits the "onboardingHelper.showActionPopover" event', () => { it('emits the "onboardingHelper.showActionPopover" event', () => {
spyOn(eventHub, '$emit'); jest.spyOn(eventHub, '$emit');
vm.showActionPopover(); vm.showActionPopover();
...@@ -180,7 +185,7 @@ describe('User onboarding helper app', () => { ...@@ -180,7 +185,7 @@ describe('User onboarding helper app', () => {
describe('hideActionPopover', () => { describe('hideActionPopover', () => {
it('emits the "onboardingHelper.hideActionPopover" event', () => { it('emits the "onboardingHelper.hideActionPopover" event', () => {
spyOn(eventHub, '$emit'); jest.spyOn(eventHub, '$emit');
vm.hideActionPopover(); vm.hideActionPopover();
...@@ -190,8 +195,8 @@ describe('User onboarding helper app', () => { ...@@ -190,8 +195,8 @@ describe('User onboarding helper app', () => {
describe('handleRestartStep', () => { describe('handleRestartStep', () => {
it('calls the "showExitTourContent" and "handleFeedbackTourContent" methods', () => { it('calls the "showExitTourContent" and "handleFeedbackTourContent" methods', () => {
spyOn(vm, 'showExitTourContent'); jest.spyOn(vm, 'showExitTourContent');
spyOn(vm, 'handleFeedbackTourContent'); jest.spyOn(vm, 'handleFeedbackTourContent');
vm.handleRestartStep(); vm.handleRestartStep();
...@@ -200,7 +205,7 @@ describe('User onboarding helper app', () => { ...@@ -200,7 +205,7 @@ describe('User onboarding helper app', () => {
}); });
it('emits the "onboardingHelper.hideActionPopover" event', () => { it('emits the "onboardingHelper.hideActionPopover" event', () => {
spyOn(eventHub, '$emit'); jest.spyOn(eventHub, '$emit');
vm.handleRestartStep(); vm.handleRestartStep();
...@@ -218,8 +223,8 @@ describe('User onboarding helper app', () => { ...@@ -218,8 +223,8 @@ describe('User onboarding helper app', () => {
click: () => {}, click: () => {},
}; };
spyOn(document, 'querySelector').and.returnValue(fakeLink); jest.spyOn(document, 'querySelector').mockReturnValue(fakeLink);
spyOn(fakeLink, 'click'); jest.spyOn(fakeLink, 'click');
vm.handleSkipStep(); vm.handleSkipStep();
...@@ -230,7 +235,7 @@ describe('User onboarding helper app', () => { ...@@ -230,7 +235,7 @@ describe('User onboarding helper app', () => {
describe('handleStepContentButton', () => { describe('handleStepContentButton', () => {
it('shows the exitTour content', () => { it('shows the exitTour content', () => {
spyOn(vm, 'showExitTourContent'); jest.spyOn(vm, 'showExitTourContent');
const button = { const button = {
showExitTourContent: true, showExitTourContent: true,
...@@ -268,19 +273,18 @@ describe('User onboarding helper app', () => { ...@@ -268,19 +273,18 @@ describe('User onboarding helper app', () => {
}); });
it('redirects to the redirectPath', () => { it('redirects to the redirectPath', () => {
const redirectSpy = spyOnDependency(OnboardingHelperApp, 'redirectTo');
const button = { const button = {
redirectPath: 'my-redirect/path', redirectPath: 'my-redirect/path',
}; };
vm.handleStepContentButton(button); vm.handleStepContentButton(button);
expect(redirectSpy).toHaveBeenCalledWith(button.redirectPath); expect(redirectTo).toHaveBeenCalledWith(button.redirectPath);
}); });
it('switches to the next tour part and calls initActionPopover', () => { it('switches to the next tour part and calls initActionPopover', () => {
spyOn(vm.$store, 'dispatch'); jest.spyOn(vm.$store, 'dispatch');
spyOn(vm, 'initActionPopover'); jest.spyOn(vm, 'initActionPopover');
const nextPart = 2; const nextPart = 2;
const button = { const button = {
...@@ -294,7 +298,7 @@ describe('User onboarding helper app', () => { ...@@ -294,7 +298,7 @@ describe('User onboarding helper app', () => {
}); });
it('shows the next content item', () => { it('shows the next content item', () => {
spyOn(vm.$store, 'dispatch'); jest.spyOn(vm.$store, 'dispatch');
const button = {}; const button = {};
...@@ -309,8 +313,8 @@ describe('User onboarding helper app', () => { ...@@ -309,8 +313,8 @@ describe('User onboarding helper app', () => {
describe('handleFeedbackButton', () => { describe('handleFeedbackButton', () => {
beforeEach(() => { beforeEach(() => {
spyOn(Tracking, 'event'); jest.spyOn(Tracking, 'event');
spyOn(vm.$store, 'dispatch'); jest.spyOn(vm.$store, 'dispatch');
}); });
it('tracks feedback and shows the exit tour content', () => { it('tracks feedback and shows the exit tour content', () => {
...@@ -341,7 +345,7 @@ describe('User onboarding helper app', () => { ...@@ -341,7 +345,7 @@ describe('User onboarding helper app', () => {
}); });
it('calls the "setExitTour" method', () => { it('calls the "setExitTour" method', () => {
spyOn(vm.$store, 'dispatch'); jest.spyOn(vm.$store, 'dispatch');
vm.showExitTourContent(true); vm.showExitTourContent(true);
...@@ -357,7 +361,7 @@ describe('User onboarding helper app', () => { ...@@ -357,7 +361,7 @@ describe('User onboarding helper app', () => {
}); });
it('calls the "setTourFeedback" method', () => { it('calls the "setTourFeedback" method', () => {
spyOn(vm.$store, 'dispatch'); jest.spyOn(vm.$store, 'dispatch');
vm.handleFeedbackTourContent(true); vm.handleFeedbackTourContent(true);
...@@ -373,7 +377,7 @@ describe('User onboarding helper app', () => { ...@@ -373,7 +377,7 @@ describe('User onboarding helper app', () => {
}); });
it('calls the "setDntExitTour" method', () => { it('calls the "setDntExitTour" method', () => {
spyOn(vm.$store, 'dispatch'); jest.spyOn(vm.$store, 'dispatch');
vm.handleDntExitTourContent(true); vm.handleDntExitTourContent(true);
...@@ -383,7 +387,7 @@ describe('User onboarding helper app', () => { ...@@ -383,7 +387,7 @@ describe('User onboarding helper app', () => {
describe('handleExitTourButton', () => { describe('handleExitTourButton', () => {
it('emits the "onboardingHelper.hideActionPopover" event', () => { it('emits the "onboardingHelper.hideActionPopover" event', () => {
spyOn(eventHub, '$emit'); jest.spyOn(eventHub, '$emit');
vm.handleExitTourButton(); vm.handleExitTourButton();
...@@ -391,7 +395,7 @@ describe('User onboarding helper app', () => { ...@@ -391,7 +395,7 @@ describe('User onboarding helper app', () => {
}); });
it('calls the "setDismissed" method with true', () => { it('calls the "setDismissed" method with true', () => {
spyOn(vm.$store, 'dispatch'); jest.spyOn(vm.$store, 'dispatch');
vm.handleExitTourButton(); vm.handleExitTourButton();
...@@ -399,7 +403,7 @@ describe('User onboarding helper app', () => { ...@@ -399,7 +403,7 @@ describe('User onboarding helper app', () => {
}); });
it('emits the "onboardingHelper.destroyActionPopover" event', () => { it('emits the "onboardingHelper.destroyActionPopover" event', () => {
spyOn(eventHub, '$emit'); jest.spyOn(eventHub, '$emit');
vm.handleExitTourButton(); vm.handleExitTourButton();
......
...@@ -238,7 +238,7 @@ describe('User onboarding tour parts list', () => { ...@@ -238,7 +238,7 @@ describe('User onboarding tour parts list', () => {
const findExitTourLink = () => wrapper.find('.qa-exit-tour-link'); const findExitTourLink = () => wrapper.find('.qa-exit-tour-link');
it('emits the "showDntExitContent" event when the "Exit Learn GitLab" link is clicked and tracking is not enabled', () => { it('emits the "showDntExitContent" event when the "Exit Learn GitLab" link is clicked and tracking is not enabled', () => {
spyOn(Tracking, 'enabled').and.returnValue(false); jest.spyOn(Tracking, 'enabled').mockReturnValue(false);
findExitTourLink().vm.$emit('click'); findExitTourLink().vm.$emit('click');
...@@ -247,7 +247,7 @@ describe('User onboarding tour parts list', () => { ...@@ -247,7 +247,7 @@ describe('User onboarding tour parts list', () => {
}); });
it('emits the "showFeedbackContent" event when the "Exit Learn GitLab" link is clicked and tracking is enabled', () => { it('emits the "showFeedbackContent" event when the "Exit Learn GitLab" link is clicked and tracking is enabled', () => {
spyOn(Tracking, 'enabled').and.returnValue(true); jest.spyOn(Tracking, 'enabled').mockReturnValue(true);
findExitTourLink().vm.$emit('click'); findExitTourLink().vm.$emit('click');
...@@ -348,7 +348,7 @@ describe('User onboarding tour parts list', () => { ...@@ -348,7 +348,7 @@ describe('User onboarding tour parts list', () => {
expect(wrapper.find(TourPartsList).exists()).toBe(true); expect(wrapper.find(TourPartsList).exists()).toBe(true);
expect(wrapper.find(TourPartsList).props()).toEqual( expect(wrapper.find(TourPartsList).props()).toEqual(
jasmine.objectContaining({ expect.objectContaining({
tourTitles, tourTitles,
activeTour, activeTour,
totalStepsForTour, totalStepsForTour,
......
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import testAction from 'spec/helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import createState from 'ee/onboarding/onboarding_helper/store/state'; import createState from 'ee/onboarding/onboarding_helper/store/state';
import * as types from 'ee/onboarding/onboarding_helper/store/mutation_types'; import * as types from 'ee/onboarding/onboarding_helper/store/mutation_types';
import { import {
...@@ -41,7 +41,7 @@ describe('User onboarding helper store actions', () => { ...@@ -41,7 +41,7 @@ describe('User onboarding helper store actions', () => {
describe('setTourKey', () => { describe('setTourKey', () => {
beforeEach(() => { beforeEach(() => {
spyOn(onboardingUtils, 'updateLocalStorage').and.stub(); jest.spyOn(onboardingUtils, 'updateLocalStorage');
}); });
it(`commits ${types.SET_TOUR_KEY} mutation`, done => { it(`commits ${types.SET_TOUR_KEY} mutation`, done => {
...@@ -68,7 +68,7 @@ describe('User onboarding helper store actions', () => { ...@@ -68,7 +68,7 @@ describe('User onboarding helper store actions', () => {
describe('setLastStepIndex', () => { describe('setLastStepIndex', () => {
beforeEach(() => { beforeEach(() => {
spyOn(onboardingUtils, 'updateLocalStorage').and.stub(); jest.spyOn(onboardingUtils, 'updateLocalStorage');
}); });
it(`commits ${types.SET_LAST_STEP_INDEX} mutation`, done => { it(`commits ${types.SET_LAST_STEP_INDEX} mutation`, done => {
...@@ -183,10 +183,10 @@ describe('User onboarding helper store actions', () => { ...@@ -183,10 +183,10 @@ describe('User onboarding helper store actions', () => {
[{ type: types.SET_DISMISSED, payload: dismissed }], [{ type: types.SET_DISMISSED, payload: dismissed }],
[], [],
() => { () => {
setTimeout(() => { setImmediate(() => {
expect(Cookies.get(ONBOARDING_DISMISSED_COOKIE_NAME)).toEqual(`${dismissed}`); expect(Cookies.get(ONBOARDING_DISMISSED_COOKIE_NAME)).toEqual(`${dismissed}`);
done(); done();
}, 0); });
}, },
); );
}); });
......
...@@ -5,6 +5,11 @@ import ActionPopover from 'ee/onboarding/onboarding_helper/components/action_pop ...@@ -5,6 +5,11 @@ import ActionPopover from 'ee/onboarding/onboarding_helper/components/action_pop
import HelpContentPopover from 'ee/onboarding/onboarding_helper/components/help_content_popover.vue'; import HelpContentPopover from 'ee/onboarding/onboarding_helper/components/help_content_popover.vue';
import onboardingUtils from 'ee/onboarding/utils'; import onboardingUtils from 'ee/onboarding/utils';
import UserAvatarImage from '~/vue_shared/components/user_avatar/user_avatar_image.vue'; import UserAvatarImage from '~/vue_shared/components/user_avatar/user_avatar_image.vue';
import { redirectTo } from '~/lib/utils/url_utility';
jest.mock('~/lib/utils/url_utility', () => ({
redirectTo: jest.fn(),
}));
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -38,8 +43,7 @@ describe('User onboarding welcome page', () => { ...@@ -38,8 +43,7 @@ describe('User onboarding welcome page', () => {
describe('methods', () => { describe('methods', () => {
describe('startTour', () => { describe('startTour', () => {
it('resets the localStorage', done => { it('resets the localStorage', done => {
spyOnDependency(component, 'redirectTo'); jest.spyOn(onboardingUtils, 'resetOnboardingLocalStorage');
spyOn(onboardingUtils, 'resetOnboardingLocalStorage').and.stub();
wrapper.vm wrapper.vm
.$nextTick() .$nextTick()
...@@ -53,8 +57,7 @@ describe('User onboarding welcome page', () => { ...@@ -53,8 +57,7 @@ describe('User onboarding welcome page', () => {
}); });
it('sets the dismissed property to false', done => { it('sets the dismissed property to false', done => {
spyOnDependency(component, 'redirectTo'); jest.spyOn(onboardingUtils, 'updateOnboardingDismissed');
spyOn(onboardingUtils, 'updateOnboardingDismissed').and.stub();
wrapper.vm wrapper.vm
.$nextTick() .$nextTick()
...@@ -68,13 +71,12 @@ describe('User onboarding welcome page', () => { ...@@ -68,13 +71,12 @@ describe('User onboarding welcome page', () => {
}); });
it('redirects to the project path', done => { it('redirects to the project path', done => {
const redirectSpy = spyOnDependency(component, 'redirectTo');
wrapper.vm wrapper.vm
.$nextTick() .$nextTick()
.then(() => wrapper.vm.startTour()) .then(() => wrapper.vm.startTour())
.then(wrapper.vm.$nextTick) .then(wrapper.vm.$nextTick)
.then(() => { .then(() => {
expect(redirectSpy).toHaveBeenCalledWith(props.projectFullPath); expect(redirectTo).toHaveBeenCalledWith(props.projectFullPath);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -83,8 +85,7 @@ describe('User onboarding welcome page', () => { ...@@ -83,8 +85,7 @@ describe('User onboarding welcome page', () => {
describe('skipTour', () => { describe('skipTour', () => {
it('sets the dismissed property to true', done => { it('sets the dismissed property to true', done => {
spyOnDependency(component, 'redirectTo'); jest.spyOn(onboardingUtils, 'updateOnboardingDismissed');
spyOn(onboardingUtils, 'updateOnboardingDismissed').and.stub();
wrapper.vm wrapper.vm
.$nextTick() .$nextTick()
...@@ -98,13 +99,12 @@ describe('User onboarding welcome page', () => { ...@@ -98,13 +99,12 @@ describe('User onboarding welcome page', () => {
}); });
it('redirects to the skip url', done => { it('redirects to the skip url', done => {
const redirectSpy = spyOnDependency(component, 'redirectTo');
wrapper.vm wrapper.vm
.$nextTick() .$nextTick()
.then(() => wrapper.vm.skipTour()) .then(() => wrapper.vm.skipTour())
.then(wrapper.vm.$nextTick) .then(wrapper.vm.$nextTick)
.then(() => { .then(() => {
expect(redirectSpy).toHaveBeenCalledWith(props.skipUrl); expect(redirectTo).toHaveBeenCalledWith(props.skipUrl);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
......
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
import { import {
ONBOARDING_DISMISSED_COOKIE_NAME, ONBOARDING_DISMISSED_COOKIE_NAME,
STORAGE_KEY, STORAGE_KEY,
...@@ -8,10 +9,12 @@ import onboardingUtils from 'ee/onboarding/utils'; ...@@ -8,10 +9,12 @@ import onboardingUtils from 'ee/onboarding/utils';
import AccessorUtilities from '~/lib/utils/accessor'; import AccessorUtilities from '~/lib/utils/accessor';
describe('User onboarding utils', () => { describe('User onboarding utils', () => {
useLocalStorageSpy();
beforeEach(() => { beforeEach(() => {
Cookies.remove(ONBOARDING_DISMISSED_COOKIE_NAME); Cookies.remove(ONBOARDING_DISMISSED_COOKIE_NAME);
onboardingUtils.resetOnboardingLocalStorage(); onboardingUtils.resetOnboardingLocalStorage();
spyOn(AccessorUtilities, 'isLocalStorageAccessSafe').and.returnValue(true); jest.spyOn(AccessorUtilities, 'isLocalStorageAccessSafe').mockReturnValue(true);
}); });
describe('isOnboardingDismissed', () => { describe('isOnboardingDismissed', () => {
...@@ -34,8 +37,6 @@ describe('User onboarding utils', () => { ...@@ -34,8 +37,6 @@ describe('User onboarding utils', () => {
}); });
it('removes onboarding related data from localStorage', () => { it('removes onboarding related data from localStorage', () => {
spyOn(localStorage, 'removeItem');
onboardingUtils.updateOnboardingDismissed(true); onboardingUtils.updateOnboardingDismissed(true);
expect(localStorage.removeItem).toHaveBeenCalledWith(STORAGE_KEY); expect(localStorage.removeItem).toHaveBeenCalledWith(STORAGE_KEY);
...@@ -44,46 +45,33 @@ describe('User onboarding utils', () => { ...@@ -44,46 +45,33 @@ describe('User onboarding utils', () => {
describe('resetOnboardingLocalStorage', () => { describe('resetOnboardingLocalStorage', () => {
it('resets the onboarding props in the localStorage to the default', () => { it('resets the onboarding props in the localStorage to the default', () => {
const modified = { jest.spyOn(window.localStorage, 'setItem');
tourKey: 2,
lastStepIndex: 5,
createdProjectPath: 'foo',
};
localStorage.setItem(STORAGE_KEY, JSON.stringify(modified));
onboardingUtils.resetOnboardingLocalStorage(); onboardingUtils.resetOnboardingLocalStorage();
expect(localStorage.setItem).toHaveBeenCalledWith(
expect(JSON.parse(localStorage.getItem(STORAGE_KEY))).toEqual(ONBOARDING_PROPS_DEFAULTS); STORAGE_KEY,
JSON.stringify(ONBOARDING_PROPS_DEFAULTS),
);
}); });
}); });
describe('getOnboardingLocalStorageState', () => { describe('getOnboardingLocalStorageState', () => {
it('retrieves the proper values from localStorage', () => { it('retrieves the proper values from localStorage', () => {
const modified = { jest.spyOn(window.localStorage, 'getItem').mockReturnValue('{}');
tourKey: 2, onboardingUtils.getOnboardingLocalStorageState();
lastStepIndex: 5, expect(localStorage.getItem).toHaveBeenCalledWith(STORAGE_KEY);
createdProjectPath: 'foo',
};
localStorage.setItem(STORAGE_KEY, JSON.stringify(modified));
expect(onboardingUtils.getOnboardingLocalStorageState()).toEqual(modified);
}); });
}); });
describe('updateLocalStorage', () => { describe('updateLocalStorage', () => {
it('updates the onboarding state on the localStorage', () => { it('updates the onboarding state on the localStorage', () => {
spyOn(localStorage, 'setItem'); jest.spyOn(window.localStorage, 'getItem').mockReturnValue('{}');
jest.spyOn(window.localStorage, 'setItem');
const modified = { const modified = {
tourKey: 2, tourKey: 2,
lastStepIndex: 5, lastStepIndex: 5,
createdProjectPath: 'foo', createdProjectPath: 'foo',
}; };
onboardingUtils.updateLocalStorage(modified); onboardingUtils.updateLocalStorage(modified);
expect(localStorage.setItem).toHaveBeenCalledWith(STORAGE_KEY, JSON.stringify(modified)); expect(localStorage.setItem).toHaveBeenCalledWith(STORAGE_KEY, JSON.stringify(modified));
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment