summaryrefslogtreecommitdiff
path: root/spec/frontend
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-08 12:09:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-08 12:09:42 +0000
commit403678e00406edc8094f087ec70e00aa29e49bef (patch)
tree447d6d4967e9a11895683b27e637a50bd9fc0602 /spec/frontend
parentf5050253469fc0961c02deec0e698ad62bdd9de5 (diff)
downloadgitlab-ce-403678e00406edc8094f087ec70e00aa29e49bef.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/static_site_editor/components/static_site_editor_spec.js10
-rw-r--r--spec/frontend/static_site_editor/store/actions_spec.js76
-rw-r--r--spec/frontend/static_site_editor/store/getters_spec.js15
-rw-r--r--spec/frontend/static_site_editor/store/mutations_spec.js52
4 files changed, 150 insertions, 3 deletions
diff --git a/spec/frontend/static_site_editor/components/static_site_editor_spec.js b/spec/frontend/static_site_editor/components/static_site_editor_spec.js
index 919763ce9fe..cde95d0a21e 100644
--- a/spec/frontend/static_site_editor/components/static_site_editor_spec.js
+++ b/spec/frontend/static_site_editor/components/static_site_editor_spec.js
@@ -17,11 +17,15 @@ describe('StaticSiteEditor', () => {
let store;
let loadContentActionMock;
- const buildStore = (initialState = {}) => {
+ const buildStore = ({ initialState, getters } = {}) => {
loadContentActionMock = jest.fn();
store = new Vuex.Store({
state: createState(initialState),
+ getters: {
+ isContentLoaded: () => false,
+ ...getters,
+ },
actions: {
loadContent: loadContentActionMock,
},
@@ -56,7 +60,7 @@ describe('StaticSiteEditor', () => {
const content = 'edit area content';
beforeEach(() => {
- buildStore({ content, isContentLoaded: true });
+ buildStore({ initialState: { content }, getters: { isContentLoaded: () => true } });
buildWrapper();
});
@@ -70,7 +74,7 @@ describe('StaticSiteEditor', () => {
});
it('displays skeleton loader while loading content', () => {
- buildStore({ isLoadingContent: true });
+ buildStore({ initialState: { isLoadingContent: true } });
buildWrapper();
expect(wrapper.find(GlSkeletonLoader).exists()).toBe(true);
diff --git a/spec/frontend/static_site_editor/store/actions_spec.js b/spec/frontend/static_site_editor/store/actions_spec.js
new file mode 100644
index 00000000000..98d7d0d2c2d
--- /dev/null
+++ b/spec/frontend/static_site_editor/store/actions_spec.js
@@ -0,0 +1,76 @@
+import testAction from 'helpers/vuex_action_helper';
+import createState from '~/static_site_editor/store/state';
+import * as actions from '~/static_site_editor/store/actions';
+import * as mutationTypes from '~/static_site_editor/store/mutation_types';
+import loadSourceContent from '~/static_site_editor/services/load_source_content';
+
+import createFlash from '~/flash';
+
+import {
+ projectId,
+ sourcePath,
+ sourceContentTitle as title,
+ sourceContent as content,
+} from '../mock_data';
+
+jest.mock('~/flash');
+jest.mock('~/static_site_editor/services/load_source_content', () => jest.fn());
+
+describe('Static Site Editor Store actions', () => {
+ let state;
+
+ beforeEach(() => {
+ state = createState({
+ projectId,
+ sourcePath,
+ });
+ });
+
+ describe('loadContent', () => {
+ describe('on success', () => {
+ const payload = { title, content };
+
+ beforeEach(() => {
+ loadSourceContent.mockResolvedValueOnce(payload);
+ });
+
+ it('commits receiveContentSuccess', () => {
+ testAction(
+ actions.loadContent,
+ null,
+ state,
+ [
+ { type: mutationTypes.LOAD_CONTENT },
+ { type: mutationTypes.RECEIVE_CONTENT_SUCCESS, payload },
+ ],
+ [],
+ );
+
+ expect(loadSourceContent).toHaveBeenCalledWith({ projectId, sourcePath });
+ });
+ });
+
+ describe('on error', () => {
+ const expectedMutations = [
+ { type: mutationTypes.LOAD_CONTENT },
+ { type: mutationTypes.RECEIVE_CONTENT_ERROR },
+ ];
+
+ beforeEach(() => {
+ loadSourceContent.mockRejectedValueOnce();
+ });
+
+ it('commits receiveContentError', () => {
+ testAction(actions.loadContent, null, state, expectedMutations);
+ });
+
+ it('displays flash communicating error', () => {
+ return testAction(actions.loadContent, null, state, expectedMutations).then(() => {
+ expect(createFlash).toHaveBeenCalledWith(
+ 'An error ocurred while loading your content. Please try again.',
+ );
+ });
+ });
+ });
+ });
+});
diff --git a/spec/frontend/static_site_editor/store/getters_spec.js b/spec/frontend/static_site_editor/store/getters_spec.js
new file mode 100644
index 00000000000..8800216f3b0
--- /dev/null
+++ b/spec/frontend/static_site_editor/store/getters_spec.js
@@ -0,0 +1,15 @@
+import createState from '~/static_site_editor/store/state';
+import { isContentLoaded } from '~/static_site_editor/store/getters';
+import { sourceContent as content } from '../mock_data';
+
+describe('Static Site Editor Store getters', () => {
+ describe('isContentLoaded', () => {
+ it('returns true when content is not empty', () => {
+ expect(isContentLoaded(createState({ content }))).toBe(true);
+ });
+
+ it('returns false when content is empty', () => {
+ expect(isContentLoaded(createState({ content: '' }))).toBe(false);
+ });
+ });
+});
diff --git a/spec/frontend/static_site_editor/store/mutations_spec.js b/spec/frontend/static_site_editor/store/mutations_spec.js
new file mode 100644
index 00000000000..c7055fbb2f0
--- /dev/null
+++ b/spec/frontend/static_site_editor/store/mutations_spec.js
@@ -0,0 +1,52 @@
+import createState from '~/static_site_editor/store/state';
+import mutations from '~/static_site_editor/store/mutations';
+import * as types from '~/static_site_editor/store/mutation_types';
+import { sourceContentTitle as title, sourceContent as content } from '../mock_data';
+
+describe('Static Site Editor Store mutations', () => {
+ let state;
+
+ beforeEach(() => {
+ state = createState();
+ });
+
+ describe('loadContent', () => {
+ beforeEach(() => {
+ mutations[types.LOAD_CONTENT](state);
+ });
+
+ it('sets isLoadingContent to true', () => {
+ expect(state.isLoadingContent).toBe(true);
+ });
+ });
+
+ describe('receiveContentSuccess', () => {
+ const payload = { title, content };
+
+ beforeEach(() => {
+ mutations[types.RECEIVE_CONTENT_SUCCESS](state, payload);
+ });
+
+ it('sets current state to LOADING', () => {
+ expect(state.isLoadingContent).toBe(false);
+ });
+
+ it('sets title', () => {
+ expect(state.title).toBe(payload.title);
+ });
+
+ it('sets content', () => {
+ expect(state.content).toBe(payload.content);
+ });
+ });
+
+ describe('receiveContentError', () => {
+ beforeEach(() => {
+ mutations[types.RECEIVE_CONTENT_ERROR](state);
+ });
+
+ it('sets current state to LOADING_ERROR', () => {
+ expect(state.isLoadingContent).toBe(false);
+ });
+ });
+});