Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/import_entities/import_groups/graphql/services/source_groups_manager_spec.js')
-rw-r--r--spec/frontend/import_entities/import_groups/graphql/services/source_groups_manager_spec.js55
1 files changed, 53 insertions, 2 deletions
diff --git a/spec/frontend/import_entities/import_groups/graphql/services/source_groups_manager_spec.js b/spec/frontend/import_entities/import_groups/graphql/services/source_groups_manager_spec.js
index ca987ab3ab4..5baa201906a 100644
--- a/spec/frontend/import_entities/import_groups/graphql/services/source_groups_manager_spec.js
+++ b/spec/frontend/import_entities/import_groups/graphql/services/source_groups_manager_spec.js
@@ -1,11 +1,17 @@
import { defaultDataIdFromObject } from 'apollo-cache-inmemory';
import { clientTypenames } from '~/import_entities/import_groups/graphql/client_factory';
import ImportSourceGroupFragment from '~/import_entities/import_groups/graphql/fragments/bulk_import_source_group_item.fragment.graphql';
-import { SourceGroupsManager } from '~/import_entities/import_groups/graphql/services/source_groups_manager';
+import {
+ KEY,
+ SourceGroupsManager,
+} from '~/import_entities/import_groups/graphql/services/source_groups_manager';
+
+const FAKE_SOURCE_URL = 'http://demo.host';
describe('SourceGroupsManager', () => {
let manager;
let client;
+ let storage;
const getFakeGroup = () => ({
__typename: clientTypenames.BulkImportSourceGroup,
@@ -17,8 +23,53 @@ describe('SourceGroupsManager', () => {
readFragment: jest.fn(),
writeFragment: jest.fn(),
};
+ storage = {
+ getItem: jest.fn(),
+ setItem: jest.fn(),
+ };
+
+ manager = new SourceGroupsManager({ client, storage, sourceUrl: FAKE_SOURCE_URL });
+ });
+
+ describe('storage management', () => {
+ const IMPORT_ID = 1;
+ const IMPORT_TARGET = { destination_name: 'demo', destination_namespace: 'foo' };
+ const STATUS = 'FAKE_STATUS';
+ const FAKE_GROUP = { id: 1, import_target: IMPORT_TARGET, status: STATUS };
+
+ it('loads state from storage on creation', () => {
+ expect(storage.getItem).toHaveBeenCalledWith(KEY);
+ });
+
+ it('saves to storage when import is starting', () => {
+ manager.startImport({
+ importId: IMPORT_ID,
+ group: FAKE_GROUP,
+ });
+ const storedObject = JSON.parse(storage.setItem.mock.calls[0][1]);
+ expect(Object.values(storedObject)[0]).toStrictEqual({
+ id: FAKE_GROUP.id,
+ importTarget: IMPORT_TARGET,
+ status: STATUS,
+ });
+ });
- manager = new SourceGroupsManager({ client });
+ it('saves to storage when import status is updated', () => {
+ const CHANGED_STATUS = 'changed';
+
+ manager.startImport({
+ importId: IMPORT_ID,
+ group: FAKE_GROUP,
+ });
+
+ manager.setImportStatusByImportId(IMPORT_ID, CHANGED_STATUS);
+ const storedObject = JSON.parse(storage.setItem.mock.calls[1][1]);
+ expect(Object.values(storedObject)[0]).toStrictEqual({
+ id: FAKE_GROUP.id,
+ importTarget: IMPORT_TARGET,
+ status: CHANGED_STATUS,
+ });
+ });
});
it('finds item by group id', () => {