summaryrefslogtreecommitdiff
path: root/spec/frontend/registry/explorer/stores/actions_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/registry/explorer/stores/actions_spec.js')
-rw-r--r--spec/frontend/registry/explorer/stores/actions_spec.js79
1 files changed, 60 insertions, 19 deletions
diff --git a/spec/frontend/registry/explorer/stores/actions_spec.js b/spec/frontend/registry/explorer/stores/actions_spec.js
index fb93ab06ca8..dcd4d8015a4 100644
--- a/spec/frontend/registry/explorer/stores/actions_spec.js
+++ b/spec/frontend/registry/explorer/stores/actions_spec.js
@@ -1,18 +1,29 @@
import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper';
import { TEST_HOST } from 'helpers/test_constants';
+import createFlash from '~/flash';
+import Api from '~/api';
import axios from '~/lib/utils/axios_utils';
import * as actions from '~/registry/explorer/stores/actions';
import * as types from '~/registry/explorer/stores/mutation_types';
-import { deprecatedCreateFlash as createFlash } from '~/flash';
import { reposServerResponse, registryServerResponse } from '../mock_data';
+import * as utils from '~/registry/explorer/utils';
+import {
+ FETCH_IMAGES_LIST_ERROR_MESSAGE,
+ FETCH_TAGS_LIST_ERROR_MESSAGE,
+ FETCH_IMAGE_DETAILS_ERROR_MESSAGE,
+} from '~/registry/explorer/constants/index';
jest.mock('~/flash.js');
+jest.mock('~/registry/explorer/utils');
describe('Actions RegistryExplorer Store', () => {
let mock;
const endpoint = `${TEST_HOST}/endpoint.json`;
+ const url = `${endpoint}/1}`;
+ jest.spyOn(utils, 'pathGenerator').mockReturnValue(url);
+
beforeEach(() => {
mock = new MockAdapter(axios);
});
@@ -123,7 +134,7 @@ describe('Actions RegistryExplorer Store', () => {
],
[],
() => {
- expect(createFlash).toHaveBeenCalled();
+ expect(createFlash).toHaveBeenCalledWith({ message: FETCH_IMAGES_LIST_ERROR_MESSAGE });
done();
},
);
@@ -131,15 +142,12 @@ describe('Actions RegistryExplorer Store', () => {
});
describe('fetch tags list', () => {
- const url = `${endpoint}/1}`;
- const params = window.btoa(JSON.stringify({ tags_path: `${endpoint}/1}` }));
-
it('sets the tagsList', done => {
mock.onGet(url).replyOnce(200, registryServerResponse, {});
testAction(
actions.requestTagsList,
- { params },
+ {},
{},
[
{ type: types.SET_MAIN_LOADING, payload: true },
@@ -158,7 +166,7 @@ describe('Actions RegistryExplorer Store', () => {
it('should create flash on error', done => {
testAction(
actions.requestTagsList,
- { params },
+ {},
{},
[
{ type: types.SET_MAIN_LOADING, payload: true },
@@ -166,7 +174,7 @@ describe('Actions RegistryExplorer Store', () => {
],
[],
() => {
- expect(createFlash).toHaveBeenCalled();
+ expect(createFlash).toHaveBeenCalledWith({ message: FETCH_TAGS_LIST_ERROR_MESSAGE });
done();
},
);
@@ -176,8 +184,6 @@ describe('Actions RegistryExplorer Store', () => {
describe('request delete single tag', () => {
it('successfully performs the delete request', done => {
const deletePath = 'delete/path';
- const params = window.btoa(JSON.stringify({ tags_path: `${endpoint}/1}`, id: 1 }));
-
mock.onDelete(deletePath).replyOnce(200);
testAction(
@@ -186,7 +192,6 @@ describe('Actions RegistryExplorer Store', () => {
tag: {
destroy_path: deletePath,
},
- params,
},
{
tagsPagination: {},
@@ -202,7 +207,7 @@ describe('Actions RegistryExplorer Store', () => {
},
{
type: 'requestTagsList',
- payload: { pagination: {}, params },
+ payload: {},
},
],
done,
@@ -227,18 +232,55 @@ describe('Actions RegistryExplorer Store', () => {
});
});
- describe('request delete multiple tags', () => {
- const url = `project-path/registry/repository/foo/tags`;
- const params = window.btoa(JSON.stringify({ tags_path: `${url}?format=json` }));
+ describe('requestImageDetailsAndTagsList', () => {
+ it('sets the imageDetails and dispatch requestTagsList', done => {
+ const resolvedValue = { foo: 'bar' };
+ jest.spyOn(Api, 'containerRegistryDetails').mockResolvedValue({ data: resolvedValue });
+
+ testAction(
+ actions.requestImageDetailsAndTagsList,
+ 1,
+ {},
+ [
+ { type: types.SET_MAIN_LOADING, payload: true },
+ { type: types.SET_IMAGE_DETAILS, payload: resolvedValue },
+ ],
+ [
+ {
+ type: 'requestTagsList',
+ },
+ ],
+ done,
+ );
+ });
+
+ it('should create flash on error', done => {
+ jest.spyOn(Api, 'containerRegistryDetails').mockRejectedValue();
+ testAction(
+ actions.requestImageDetailsAndTagsList,
+ 1,
+ {},
+ [
+ { type: types.SET_MAIN_LOADING, payload: true },
+ { type: types.SET_MAIN_LOADING, payload: false },
+ ],
+ [],
+ () => {
+ expect(createFlash).toHaveBeenCalledWith({ message: FETCH_IMAGE_DETAILS_ERROR_MESSAGE });
+ done();
+ },
+ );
+ });
+ });
+ describe('request delete multiple tags', () => {
it('successfully performs the delete request', done => {
- mock.onDelete(`${url}/bulk_destroy`).replyOnce(200);
+ mock.onDelete(url).replyOnce(200);
testAction(
actions.requestDeleteTags,
{
ids: [1, 2],
- params,
},
{
tagsPagination: {},
@@ -254,7 +296,7 @@ describe('Actions RegistryExplorer Store', () => {
},
{
type: 'requestTagsList',
- payload: { pagination: {}, params },
+ payload: {},
},
],
done,
@@ -268,7 +310,6 @@ describe('Actions RegistryExplorer Store', () => {
actions.requestDeleteTags,
{
ids: [1, 2],
- params,
},
{
tagsPagination: {},