summaryrefslogtreecommitdiff
path: root/spec/javascripts/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/javascripts/helpers')
-rw-r--r--spec/javascripts/helpers/scroll_into_view_promise.js28
-rw-r--r--spec/javascripts/helpers/vuex_action_helper_spec.js166
-rw-r--r--spec/javascripts/helpers/wait_for_attribute_change.js16
3 files changed, 0 insertions, 210 deletions
diff --git a/spec/javascripts/helpers/scroll_into_view_promise.js b/spec/javascripts/helpers/scroll_into_view_promise.js
deleted file mode 100644
index 0edea2103da..00000000000
--- a/spec/javascripts/helpers/scroll_into_view_promise.js
+++ /dev/null
@@ -1,28 +0,0 @@
-export default function scrollIntoViewPromise(intersectionTarget, timeout = 100, maxTries = 5) {
- return new Promise((resolve, reject) => {
- let intersectionObserver;
- let retry = 0;
-
- const intervalId = setInterval(() => {
- if (retry >= maxTries) {
- intersectionObserver.disconnect();
- clearInterval(intervalId);
- reject(new Error(`Could not scroll target into viewPort within ${timeout * maxTries} ms`));
- }
- retry += 1;
- intersectionTarget.scrollIntoView();
- }, timeout);
-
- intersectionObserver = new IntersectionObserver(entries => {
- if (entries[0].isIntersecting) {
- intersectionObserver.disconnect();
- clearInterval(intervalId);
- resolve();
- }
- });
-
- intersectionObserver.observe(intersectionTarget);
-
- intersectionTarget.scrollIntoView();
- });
-}
diff --git a/spec/javascripts/helpers/vuex_action_helper_spec.js b/spec/javascripts/helpers/vuex_action_helper_spec.js
deleted file mode 100644
index 09f0bd395c3..00000000000
--- a/spec/javascripts/helpers/vuex_action_helper_spec.js
+++ /dev/null
@@ -1,166 +0,0 @@
-import MockAdapter from 'axios-mock-adapter';
-import { TEST_HOST } from 'spec/test_constants';
-import axios from '~/lib/utils/axios_utils';
-import testAction from './vuex_action_helper';
-
-describe('VueX test helper (testAction)', () => {
- let originalExpect;
- let assertion;
- let mock;
- const noop = () => {};
-
- beforeAll(() => {
- mock = new MockAdapter(axios);
- /*
- In order to test the helper properly, we need to overwrite the jasmine `expect` helper.
- We test that the testAction helper properly passes the dispatched actions/committed mutations
- to the jasmine helper.
- */
- originalExpect = expect;
- assertion = null;
- global.expect = actual => ({
- toEqual: () => {
- originalExpect(actual).toEqual(assertion);
- },
- });
- });
-
- afterAll(() => {
- mock.restore();
- global.expect = originalExpect;
- });
-
- it('should properly pass on state and payload', () => {
- const exampleState = { FOO: 12, BAR: 3 };
- const examplePayload = { BAZ: 73, BIZ: 55 };
-
- const action = ({ state }, payload) => {
- originalExpect(state).toEqual(exampleState);
- originalExpect(payload).toEqual(examplePayload);
- };
-
- assertion = { mutations: [], actions: [] };
-
- testAction(action, examplePayload, exampleState);
- });
-
- describe('should work with synchronous actions', () => {
- it('committing mutation', () => {
- const action = ({ commit }) => {
- commit('MUTATION');
- };
-
- assertion = { mutations: [{ type: 'MUTATION' }], actions: [] };
-
- testAction(action, null, {}, assertion.mutations, assertion.actions, noop);
- });
-
- it('dispatching action', () => {
- const action = ({ dispatch }) => {
- dispatch('ACTION');
- };
-
- assertion = { actions: [{ type: 'ACTION' }], mutations: [] };
-
- testAction(action, null, {}, assertion.mutations, assertion.actions, noop);
- });
-
- it('work with jasmine done once finished', done => {
- assertion = { mutations: [], actions: [] };
-
- testAction(noop, null, {}, assertion.mutations, assertion.actions, done);
- });
-
- it('provide promise interface', done => {
- assertion = { mutations: [], actions: [] };
-
- testAction(noop, null, {}, assertion.mutations, assertion.actions)
- .then(done)
- .catch(done.fail);
- });
- });
-
- describe('should work with promise based actions (fetch action)', () => {
- let lastError;
- const data = { FOO: 'BAR' };
-
- const promiseAction = ({ commit, dispatch }) => {
- dispatch('ACTION');
-
- return axios
- .get(TEST_HOST)
- .catch(error => {
- commit('ERROR');
- lastError = error;
- throw error;
- })
- .then(() => {
- commit('SUCCESS');
- return data;
- });
- };
-
- beforeEach(() => {
- lastError = null;
- });
-
- it('work with jasmine done once finished', done => {
- mock.onGet(TEST_HOST).replyOnce(200, 42);
-
- assertion = { mutations: [{ type: 'SUCCESS' }], actions: [{ type: 'ACTION' }] };
-
- testAction(promiseAction, null, {}, assertion.mutations, assertion.actions, done);
- });
-
- it('return original data of successful promise while checking actions/mutations', done => {
- mock.onGet(TEST_HOST).replyOnce(200, 42);
-
- assertion = { mutations: [{ type: 'SUCCESS' }], actions: [{ type: 'ACTION' }] };
-
- testAction(promiseAction, null, {}, assertion.mutations, assertion.actions)
- .then(res => {
- originalExpect(res).toEqual(data);
- done();
- })
- .catch(done.fail);
- });
-
- it('return original error of rejected promise while checking actions/mutations', done => {
- mock.onGet(TEST_HOST).replyOnce(500, '');
-
- assertion = { mutations: [{ type: 'ERROR' }], actions: [{ type: 'ACTION' }] };
-
- testAction(promiseAction, null, {}, assertion.mutations, assertion.actions)
- .then(done.fail)
- .catch(error => {
- originalExpect(error).toBe(lastError);
- done();
- });
- });
- });
-
- it('should work with async actions not returning promises', done => {
- const data = { FOO: 'BAR' };
-
- const promiseAction = ({ commit, dispatch }) => {
- dispatch('ACTION');
-
- axios
- .get(TEST_HOST)
- .then(() => {
- commit('SUCCESS');
- return data;
- })
- .catch(error => {
- commit('ERROR');
- throw error;
- });
- };
-
- mock.onGet(TEST_HOST).replyOnce(200, 42);
-
- assertion = { mutations: [{ type: 'SUCCESS' }], actions: [{ type: 'ACTION' }] };
-
- testAction(promiseAction, null, {}, assertion.mutations, assertion.actions, done);
- });
-});
diff --git a/spec/javascripts/helpers/wait_for_attribute_change.js b/spec/javascripts/helpers/wait_for_attribute_change.js
deleted file mode 100644
index 8f22d569222..00000000000
--- a/spec/javascripts/helpers/wait_for_attribute_change.js
+++ /dev/null
@@ -1,16 +0,0 @@
-export default (domElement, attributes, timeout = 1500) =>
- new Promise((resolve, reject) => {
- let observer;
- const timeoutId = setTimeout(() => {
- observer.disconnect();
- reject(new Error(`Could not see an attribute update within ${timeout} ms`));
- }, timeout);
-
- observer = new MutationObserver(() => {
- clearTimeout(timeoutId);
- observer.disconnect();
- resolve();
- });
-
- observer.observe(domElement, { attributes: true, attributeFilter: attributes });
- });