summaryrefslogtreecommitdiff
path: root/spec/frontend
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-10 15:08:54 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-10 15:08:54 +0000
commit11e5d1b9ca3efa7be34ddebb708a6aedb4e91639 (patch)
tree999fdffb9d3db2e5200994e289e50fa3a3a1684a /spec/frontend
parent7351a484d79236b7e9d47c86f2fcc970b7ae10b0 (diff)
downloadgitlab-ce-11e5d1b9ca3efa7be34ddebb708a6aedb4e91639.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/registry/explorer/mock_data.js38
-rw-r--r--spec/frontend/registry/explorer/stores/actions_spec.js331
-rw-r--r--spec/frontend/registry/explorer/stores/mutations_spec.js85
-rw-r--r--spec/frontend/repository/utils/dom_spec.js13
4 files changed, 464 insertions, 3 deletions
diff --git a/spec/frontend/registry/explorer/mock_data.js b/spec/frontend/registry/explorer/mock_data.js
new file mode 100644
index 00000000000..309e2ecd9bd
--- /dev/null
+++ b/spec/frontend/registry/explorer/mock_data.js
@@ -0,0 +1,38 @@
+export const reposServerResponse = [
+ {
+ destroy_path: 'path',
+ id: '123',
+ location: 'location',
+ path: 'foo',
+ tags_path: 'tags_path',
+ },
+ {
+ destroy_path: 'path_',
+ id: '456',
+ location: 'location_',
+ path: 'bar',
+ tags_path: 'tags_path_',
+ },
+];
+
+export const registryServerResponse = [
+ {
+ name: 'centos7',
+ short_revision: 'b118ab5b0',
+ revision: 'b118ab5b0e90b7cb5127db31d5321ac14961d097516a8e0e72084b6cdc783b43',
+ total_size: 679,
+ layers: 19,
+ location: 'location',
+ created_at: 1505828744434,
+ destroy_path: 'path_',
+ },
+ {
+ name: 'centos6',
+ short_revision: 'b118ab5b0',
+ revision: 'b118ab5b0e90b7cb5127db31d5321ac14961d097516a8e0e72084b6cdc783b43',
+ total_size: 679,
+ layers: 19,
+ location: 'location',
+ created_at: 1505828744434,
+ },
+];
diff --git a/spec/frontend/registry/explorer/stores/actions_spec.js b/spec/frontend/registry/explorer/stores/actions_spec.js
new file mode 100644
index 00000000000..0df3ef68441
--- /dev/null
+++ b/spec/frontend/registry/explorer/stores/actions_spec.js
@@ -0,0 +1,331 @@
+import axios from '~/lib/utils/axios_utils';
+import MockAdapter from 'axios-mock-adapter';
+import * as actions from '~/registry/explorer/stores/actions';
+import * as types from '~/registry/explorer/stores/mutation_types';
+import testAction from 'helpers/vuex_action_helper';
+import createFlash from '~/flash';
+import { TEST_HOST } from 'helpers/test_constants';
+import { reposServerResponse, registryServerResponse } from '../mock_data';
+
+jest.mock('~/flash.js');
+
+describe('Actions RegistryExplorer Store', () => {
+ let mock;
+ const endpoint = `${TEST_HOST}/endpoint.json`;
+
+ beforeEach(() => {
+ mock = new MockAdapter(axios);
+ });
+
+ afterEach(() => {
+ mock.restore();
+ });
+
+ it('sets initial state', done => {
+ const initialState = {
+ config: {
+ endpoint,
+ },
+ };
+
+ testAction(
+ actions.setInitialState,
+ initialState,
+ null,
+ [{ type: types.SET_INITIAL_STATE, payload: initialState }],
+ [],
+ done,
+ );
+ });
+
+ describe('receives api responses', () => {
+ const response = {
+ data: [1, 2, 3],
+ headers: {
+ page: 1,
+ perPage: 10,
+ },
+ };
+
+ it('images list response', done => {
+ testAction(
+ actions.receiveImagesListSuccess,
+ response,
+ null,
+ [
+ { type: types.SET_IMAGES_LIST_SUCCESS, payload: response.data },
+ { type: types.SET_PAGINATION, payload: response.headers },
+ ],
+ [],
+ done,
+ );
+ });
+
+ it('tags list response', done => {
+ testAction(
+ actions.receiveTagsListSuccess,
+ response,
+ null,
+ [
+ { type: types.SET_TAGS_LIST_SUCCESS, payload: response.data },
+ { type: types.SET_TAGS_PAGINATION, payload: response.headers },
+ ],
+ [],
+ done,
+ );
+ });
+ });
+
+ describe('fetch images list', () => {
+ it('sets the imagesList and pagination', done => {
+ mock.onGet(endpoint).replyOnce(200, reposServerResponse, {});
+
+ testAction(
+ actions.requestImagesList,
+ {},
+ {
+ config: {
+ endpoint,
+ },
+ },
+ [
+ { type: types.SET_MAIN_LOADING, payload: true },
+ { type: types.SET_MAIN_LOADING, payload: false },
+ ],
+ [{ type: 'receiveImagesListSuccess', payload: { data: reposServerResponse, headers: {} } }],
+ done,
+ );
+ });
+
+ it('should create flash on error', done => {
+ testAction(
+ actions.requestImagesList,
+ {},
+ {
+ config: {
+ endpoint: null,
+ },
+ },
+ [
+ { type: types.SET_MAIN_LOADING, payload: true },
+ { type: types.SET_MAIN_LOADING, payload: false },
+ ],
+ [],
+ () => {
+ expect(createFlash).toHaveBeenCalled();
+ done();
+ },
+ );
+ });
+ });
+
+ describe('fetch tags list', () => {
+ const url = window.btoa(`${endpoint}/1}`);
+
+ it('sets the tagsList', done => {
+ mock.onGet(window.atob(url)).replyOnce(200, registryServerResponse, {});
+
+ testAction(
+ actions.requestTagsList,
+ { id: url },
+ {},
+ [
+ { type: types.SET_MAIN_LOADING, payload: true },
+ { type: types.SET_MAIN_LOADING, payload: false },
+ ],
+ [
+ {
+ type: 'receiveTagsListSuccess',
+ payload: { data: registryServerResponse, headers: {} },
+ },
+ ],
+ done,
+ );
+ });
+
+ it('should create flash on error', done => {
+ testAction(
+ actions.requestTagsList,
+ { id: url },
+ {},
+ [
+ { type: types.SET_MAIN_LOADING, payload: true },
+ { type: types.SET_MAIN_LOADING, payload: false },
+ ],
+ [],
+ () => {
+ expect(createFlash).toHaveBeenCalled();
+ done();
+ },
+ );
+ });
+ });
+
+ describe('request delete single tag', () => {
+ it('successfully performs the delete request', done => {
+ const deletePath = 'delete/path';
+ const url = window.btoa(`${endpoint}/1}`);
+
+ mock.onDelete(deletePath).replyOnce(200);
+
+ testAction(
+ actions.requestDeleteTag,
+ {
+ tag: {
+ destroy_path: deletePath,
+ },
+ imageId: url,
+ },
+ {
+ tagsPagination: {},
+ },
+ [
+ { type: types.SET_MAIN_LOADING, payload: true },
+ { type: types.SET_MAIN_LOADING, payload: false },
+ ],
+ [
+ {
+ type: 'requestTagsList',
+ payload: { pagination: {}, id: url },
+ },
+ ],
+ () => {
+ expect(createFlash).toHaveBeenCalled();
+ done();
+ },
+ );
+ });
+
+ it('should show flash message on error', done => {
+ testAction(
+ actions.requestDeleteTag,
+ {
+ tag: {
+ destroy_path: null,
+ },
+ },
+ {},
+ [
+ { type: types.SET_MAIN_LOADING, payload: true },
+ { type: types.SET_MAIN_LOADING, payload: false },
+ ],
+ [],
+ () => {
+ expect(createFlash).toHaveBeenCalled();
+ done();
+ },
+ );
+ });
+ });
+
+ describe('request delete multiple tags', () => {
+ const imageId = 1;
+ const projectPath = 'project-path';
+ const url = `${projectPath}/registry/repository/${imageId}/tags/bulk_destroy`;
+
+ it('successfully performs the delete request', done => {
+ mock.onDelete(url).replyOnce(200);
+
+ testAction(
+ actions.requestDeleteTags,
+ {
+ ids: [1, 2],
+ imageId,
+ },
+ {
+ config: {
+ projectPath,
+ },
+ tagsPagination: {},
+ },
+ [
+ { type: types.SET_MAIN_LOADING, payload: true },
+ { type: types.SET_MAIN_LOADING, payload: false },
+ ],
+ [
+ {
+ type: 'requestTagsList',
+ payload: { pagination: {}, id: 1 },
+ },
+ ],
+ () => {
+ expect(createFlash).toHaveBeenCalled();
+ done();
+ },
+ );
+ });
+
+ it('should show flash message on error', done => {
+ mock.onDelete(url).replyOnce(500);
+
+ testAction(
+ actions.requestDeleteTags,
+ {
+ ids: [1, 2],
+ imageId,
+ },
+ {
+ config: {
+ projectPath,
+ },
+ tagsPagination: {},
+ },
+ [
+ { type: types.SET_MAIN_LOADING, payload: true },
+ { type: types.SET_MAIN_LOADING, payload: false },
+ ],
+ [],
+ () => {
+ expect(createFlash).toHaveBeenCalled();
+ done();
+ },
+ );
+ });
+ });
+
+ describe('request delete single image', () => {
+ it('successfully performs the delete request', done => {
+ const deletePath = 'delete/path';
+ mock.onDelete(deletePath).replyOnce(200);
+
+ testAction(
+ actions.requestDeleteImage,
+ deletePath,
+ {
+ pagination: {},
+ },
+ [
+ { type: types.SET_MAIN_LOADING, payload: true },
+ { type: types.SET_MAIN_LOADING, payload: false },
+ ],
+ [
+ {
+ type: 'requestImagesList',
+ payload: { pagination: {} },
+ },
+ ],
+ () => {
+ expect(createFlash).toHaveBeenCalled();
+ done();
+ },
+ );
+ });
+
+ it('should show flash message on error', done => {
+ testAction(
+ actions.requestDeleteImage,
+ null,
+ {},
+ [
+ { type: types.SET_MAIN_LOADING, payload: true },
+ { type: types.SET_MAIN_LOADING, payload: false },
+ ],
+ [],
+ () => {
+ expect(createFlash).toHaveBeenCalled();
+ done();
+ },
+ );
+ });
+ });
+});
diff --git a/spec/frontend/registry/explorer/stores/mutations_spec.js b/spec/frontend/registry/explorer/stores/mutations_spec.js
new file mode 100644
index 00000000000..5766f3082d6
--- /dev/null
+++ b/spec/frontend/registry/explorer/stores/mutations_spec.js
@@ -0,0 +1,85 @@
+import mutations from '~/registry/explorer/stores/mutations';
+import * as types from '~/registry/explorer/stores/mutation_types';
+
+describe('Mutations Registry Explorer Store', () => {
+ let mockState;
+
+ beforeEach(() => {
+ mockState = {};
+ });
+
+ describe('SET_INITIAL_STATE', () => {
+ it('should set the initial state', () => {
+ const expectedState = { ...mockState, config: { endpoint: 'foo' } };
+ mutations[types.SET_INITIAL_STATE](mockState, { endpoint: 'foo' });
+
+ expect(mockState).toEqual(expectedState);
+ });
+ });
+
+ describe('SET_IMAGES_LIST_SUCCESS', () => {
+ it('should set the images list', () => {
+ const images = [1, 2, 3];
+ const expectedState = { ...mockState, images };
+ mutations[types.SET_IMAGES_LIST_SUCCESS](mockState, images);
+
+ expect(mockState).toEqual(expectedState);
+ });
+ });
+
+ describe('SET_TAGS_LIST_SUCCESS', () => {
+ it('should set the tags list', () => {
+ const tags = [1, 2, 3];
+ const expectedState = { ...mockState, tags };
+ mutations[types.SET_TAGS_LIST_SUCCESS](mockState, tags);
+
+ expect(mockState).toEqual(expectedState);
+ });
+ });
+
+ describe('SET_MAIN_LOADING', () => {
+ it('should set the isLoading', () => {
+ const expectedState = { ...mockState, isLoading: true };
+ mutations[types.SET_MAIN_LOADING](mockState, true);
+
+ expect(mockState).toEqual(expectedState);
+ });
+ });
+
+ describe('SET_PAGINATION', () => {
+ const generatePagination = () => [
+ {
+ 'X-PAGE': '1',
+ 'X-PER-PAGE': '20',
+ 'X-TOTAL': '100',
+ 'X-TOTAL-PAGES': '5',
+ 'X-NEXT-PAGE': '2',
+ 'X-PREV-PAGE': '0',
+ },
+ {
+ page: 1,
+ perPage: 20,
+ total: 100,
+ totalPages: 5,
+ nextPage: 2,
+ previousPage: 0,
+ },
+ ];
+
+ it('should set the images pagination', () => {
+ const [headers, expectedResult] = generatePagination();
+ const expectedState = { ...mockState, pagination: expectedResult };
+ mutations[types.SET_PAGINATION](mockState, headers);
+
+ expect(mockState).toEqual(expectedState);
+ });
+
+ it('should set the tags pagination', () => {
+ const [headers, expectedResult] = generatePagination();
+ const expectedState = { ...mockState, tagsPagination: expectedResult };
+ mutations[types.SET_TAGS_PAGINATION](mockState, headers);
+
+ expect(mockState).toEqual(expectedState);
+ });
+ });
+});
diff --git a/spec/frontend/repository/utils/dom_spec.js b/spec/frontend/repository/utils/dom_spec.js
index bf98a9e1a4d..0b61161c9d0 100644
--- a/spec/frontend/repository/utils/dom_spec.js
+++ b/spec/frontend/repository/utils/dom_spec.js
@@ -20,11 +20,18 @@ describe('updateElementsVisibility', () => {
});
describe('updateFormAction', () => {
- it('updates form action', () => {
+ it.each`
+ path
+ ${'/test'}
+ ${'test'}
+ ${'/'}
+ `('updates form action for $path', ({ path }) => {
setHTMLFixture('<form class="js-test" action="/"></form>');
- updateFormAction('.js-test', '/gitlab/create', '/test');
+ updateFormAction('.js-test', '/gitlab/create', path);
- expect(document.querySelector('.js-test').action).toBe('http://localhost/gitlab/create/test');
+ expect(document.querySelector('.js-test').action).toBe(
+ `http://localhost/gitlab/create/${path.replace(/^\//, '')}`,
+ );
});
});