Commit 55481425 authored by Brandon Labuschagne's avatar Brandon Labuschagne Committed by Pavel Shutsin

FE changes migrating segments to namespace

This commit applies the FE changes required to
allow the Devops Adoption feature to work with
the new namespace terminology

A follow up issue is open to remove the remaining
references to segments on the FE
parent 60e3a879
...@@ -17,8 +17,8 @@ import { ...@@ -17,8 +17,8 @@ import {
TRACK_ADOPTION_TAB_CLICK_EVENT, TRACK_ADOPTION_TAB_CLICK_EVENT,
TRACK_DEVOPS_SCORE_TAB_CLICK_EVENT, TRACK_DEVOPS_SCORE_TAB_CLICK_EVENT,
} from '../constants'; } from '../constants';
import bulkFindOrCreateDevopsAdoptionSegmentsMutation from '../graphql/mutations/bulk_find_or_create_devops_adoption_segments.mutation.graphql'; import bulkEnableDevopsAdoptionNamespacesMutation from '../graphql/mutations/bulk_enable_devops_adoption_namespaces.mutation.graphql';
import devopsAdoptionSegmentsQuery from '../graphql/queries/devops_adoption_segments.query.graphql'; import devopsAdoptionEnabledNamespacesQuery from '../graphql/queries/devops_adoption_enabled_namespaces.query.graphql';
import getGroupsQuery from '../graphql/queries/get_groups.query.graphql'; import getGroupsQuery from '../graphql/queries/get_groups.query.graphql';
import { addSegmentsToCache, deleteSegmentsFromCache } from '../utils/cache_updates'; import { addSegmentsToCache, deleteSegmentsFromCache } from '../utils/cache_updates';
import { shouldPollTableData } from '../utils/helpers'; import { shouldPollTableData } from '../utils/helpers';
...@@ -85,14 +85,14 @@ export default { ...@@ -85,14 +85,14 @@ export default {
}; };
}, },
apollo: { apollo: {
devopsAdoptionSegments: { devopsAdoptionEnabledNamespaces: {
query: devopsAdoptionSegmentsQuery, query: devopsAdoptionEnabledNamespacesQuery,
variables() { variables() {
return this.segmentsQueryVariables; return this.segmentsQueryVariables;
}, },
result({ data }) { result({ data }) {
if (this.isGroup) { if (this.isGroup) {
const groupEnabled = data.devopsAdoptionSegments.nodes.some( const groupEnabled = data.devopsAdoptionEnabledNamespaces.nodes.some(
({ namespace: { id } }) => id === this.groupGid, ({ namespace: { id } }) => id === this.groupGid,
); );
...@@ -114,14 +114,14 @@ export default { ...@@ -114,14 +114,14 @@ export default {
return Boolean(this.groups?.nodes?.length); return Boolean(this.groups?.nodes?.length);
}, },
hasSegmentsData() { hasSegmentsData() {
return Boolean(this.devopsAdoptionSegments?.nodes?.length); return Boolean(this.devopsAdoptionEnabledNamespaces?.nodes?.length);
}, },
hasLoadingError() { hasLoadingError() {
return Object.values(this.errors).some((error) => error === true); return Object.values(this.errors).some((error) => error === true);
}, },
timestamp() { timestamp() {
return dateformat( return dateformat(
this.devopsAdoptionSegments?.nodes[0]?.latestSnapshot?.recordedAt, this.devopsAdoptionEnabledNamespaces?.nodes[0]?.latestSnapshot?.recordedAt,
DATE_TIME_FORMAT, DATE_TIME_FORMAT,
); );
}, },
...@@ -129,11 +129,11 @@ export default { ...@@ -129,11 +129,11 @@ export default {
return ( return (
this.isLoadingGroups || this.isLoadingGroups ||
this.isLoadingEnableGroup || this.isLoadingEnableGroup ||
this.$apollo.queries.devopsAdoptionSegments.loading this.$apollo.queries.devopsAdoptionEnabledNamespaces.loading
); );
}, },
segmentLimitReached() { segmentLimitReached() {
return this.devopsAdoptionSegments?.nodes?.length > this.$options.maxSegments; return this.devopsAdoptionEnabledNamespaces?.nodes?.length > this.$options.maxSegments;
}, },
editGroupsButtonLabel() { editGroupsButtonLabel() {
return this.isGroup return this.isGroup
...@@ -165,19 +165,19 @@ export default { ...@@ -165,19 +165,19 @@ export default {
this.$apollo this.$apollo
.mutate({ .mutate({
mutation: bulkFindOrCreateDevopsAdoptionSegmentsMutation, mutation: bulkEnableDevopsAdoptionNamespacesMutation,
variables: { variables: {
namespaceIds: [this.groupGid], namespaceIds: [this.groupGid],
}, },
update: (store, { data }) => { update: (store, { data }) => {
const { const {
bulkFindOrCreateDevopsAdoptionSegments: { segments, errors }, bulkEnableDevopsAdoptionNamespaces: { enabledNamespaces, errors },
} = data; } = data;
if (errors.length) { if (errors.length) {
this.handleError(DEVOPS_ADOPTION_ERROR_KEYS.addSegment, errors); this.handleError(DEVOPS_ADOPTION_ERROR_KEYS.addSegment, errors);
} else { } else {
this.addSegmentsToCache(segments); this.addSegmentsToCache(enabledNamespaces);
} }
}, },
}) })
...@@ -190,13 +190,13 @@ export default { ...@@ -190,13 +190,13 @@ export default {
}, },
pollTableData() { pollTableData() {
const shouldPoll = shouldPollTableData({ const shouldPoll = shouldPollTableData({
segments: this.devopsAdoptionSegments.nodes, segments: this.devopsAdoptionEnabledNamespaces.nodes,
timestamp: this.devopsAdoptionSegments?.nodes[0]?.latestSnapshot?.recordedAt, timestamp: this.devopsAdoptionEnabledNamespaces?.nodes[0]?.latestSnapshot?.recordedAt,
openModal: this.openModal, openModal: this.openModal,
}); });
if (shouldPoll) { if (shouldPoll) {
this.$apollo.queries.devopsAdoptionSegments.refetch(); this.$apollo.queries.devopsAdoptionEnabledNamespaces.refetch();
} }
}, },
trackModalOpenState(state) { trackModalOpenState(state) {
...@@ -311,7 +311,7 @@ export default { ...@@ -311,7 +311,7 @@ export default {
:segment-limit-reached="segmentLimitReached" :segment-limit-reached="segmentLimitReached"
:edit-groups-button-label="editGroupsButtonLabel" :edit-groups-button-label="editGroupsButtonLabel"
:cols="tab.cols" :cols="tab.cols"
:segments="devopsAdoptionSegments" :segments="devopsAdoptionEnabledNamespaces"
@segmentsRemoved="deleteSegmentsFromCache" @segmentsRemoved="deleteSegmentsFromCache"
@openAddRemoveModal="openAddRemoveModal" @openAddRemoveModal="openAddRemoveModal"
/> />
...@@ -327,7 +327,7 @@ export default { ...@@ -327,7 +327,7 @@ export default {
v-if="canRenderModal" v-if="canRenderModal"
ref="addRemoveModal" ref="addRemoveModal"
:groups="groups.nodes" :groups="groups.nodes"
:enabled-groups="devopsAdoptionSegments.nodes" :enabled-groups="devopsAdoptionEnabledNamespaces.nodes"
@segmentsAdded="addSegmentsToCache" @segmentsAdded="addSegmentsToCache"
@segmentsRemoved="deleteSegmentsFromCache" @segmentsRemoved="deleteSegmentsFromCache"
@trackModalOpenState="trackModalOpenState" @trackModalOpenState="trackModalOpenState"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { GlModal, GlSprintf, GlAlert } from '@gitlab/ui'; import { GlModal, GlSprintf, GlAlert } from '@gitlab/ui';
import * as Sentry from '@sentry/browser'; import * as Sentry from '@sentry/browser';
import { DEVOPS_ADOPTION_STRINGS, DEVOPS_ADOPTION_SEGMENT_DELETE_MODAL_ID } from '../constants'; import { DEVOPS_ADOPTION_STRINGS, DEVOPS_ADOPTION_SEGMENT_DELETE_MODAL_ID } from '../constants';
import deleteDevopsAdoptionSegmentMutation from '../graphql/mutations/delete_devops_adoption_segment.mutation.graphql'; import disableDevopsAdoptionNamespaceMutation from '../graphql/mutations/disable_devops_adoption_namespace.mutation.graphql';
export default { export default {
name: 'DevopsAdoptionDeleteModal', name: 'DevopsAdoptionDeleteModal',
...@@ -57,10 +57,10 @@ export default { ...@@ -57,10 +57,10 @@ export default {
const { const {
data: { data: {
deleteDevopsAdoptionSegment: { errors }, disableDevopsAdoptionNamespace: { errors },
}, },
} = await this.$apollo.mutate({ } = await this.$apollo.mutate({
mutation: deleteDevopsAdoptionSegmentMutation, mutation: disableDevopsAdoptionNamespaceMutation,
variables: { variables: {
id: [id], id: [id],
}, },
......
...@@ -8,8 +8,8 @@ import { ...@@ -8,8 +8,8 @@ import {
DEVOPS_ADOPTION_SEGMENT_MODAL_ID, DEVOPS_ADOPTION_SEGMENT_MODAL_ID,
DEVOPS_ADOPTION_GROUP_LEVEL_LABEL, DEVOPS_ADOPTION_GROUP_LEVEL_LABEL,
} from '../constants'; } from '../constants';
import bulkFindOrCreateDevopsAdoptionSegmentsMutation from '../graphql/mutations/bulk_find_or_create_devops_adoption_segments.mutation.graphql'; import bulkEnableDevopsAdoptionNamespacesMutation from '../graphql/mutations/bulk_enable_devops_adoption_namespaces.mutation.graphql';
import deleteDevopsAdoptionSegmentMutation from '../graphql/mutations/delete_devops_adoption_segment.mutation.graphql'; import disableDevopsAdoptionNamespaceMutation from '../graphql/mutations/disable_devops_adoption_namespace.mutation.graphql';
export default { export default {
name: 'DevopsAdoptionSegmentModal', name: 'DevopsAdoptionSegmentModal',
...@@ -139,20 +139,20 @@ export default { ...@@ -139,20 +139,20 @@ export default {
this.loadingAdd = true; this.loadingAdd = true;
const { const {
data: { data: {
bulkFindOrCreateDevopsAdoptionSegments: { errors }, bulkEnableDevopsAdoptionNamespaces: { errors },
}, },
} = await this.$apollo.mutate({ } = await this.$apollo.mutate({
mutation: bulkFindOrCreateDevopsAdoptionSegmentsMutation, mutation: bulkEnableDevopsAdoptionNamespacesMutation,
variables: { variables: {
namespaceIds, namespaceIds,
displayNamespaceId: this.groupGid, displayNamespaceId: this.groupGid,
}, },
update: (store, { data }) => { update: (store, { data }) => {
const { const {
bulkFindOrCreateDevopsAdoptionSegments: { segments, errors: requestErrors }, bulkEnableDevopsAdoptionNamespaces: { enabledNamespaces, errors: requestErrors },
} = data; } = data;
if (!requestErrors.length) this.$emit('segmentsAdded', segments); if (!requestErrors.length) this.$emit('segmentsAdded', enabledNamespaces);
}, },
}); });
...@@ -182,16 +182,16 @@ export default { ...@@ -182,16 +182,16 @@ export default {
const { const {
data: { data: {
deleteDevopsAdoptionSegment: { errors }, disableDevopsAdoptionNamespace: { errors },
}, },
} = await this.$apollo.mutate({ } = await this.$apollo.mutate({
mutation: deleteDevopsAdoptionSegmentMutation, mutation: disableDevopsAdoptionNamespaceMutation,
variables: { variables: {
id: removedGroupGids, id: removedGroupGids,
}, },
update: (store, { data }) => { update: (store, { data }) => {
const { const {
deleteDevopsAdoptionSegment: { errors: requestErrors }, disableDevopsAdoptionNamespace: { errors: requestErrors },
} = data; } = data;
if (!requestErrors.length) this.$emit('segmentsRemoved', removedGroupGids); if (!requestErrors.length) this.$emit('segmentsRemoved', removedGroupGids);
......
mutation($namespaceIds: [NamespaceID!]!, $displayNamespaceId: NamespaceID) { mutation($namespaceIds: [NamespaceID!]!, $displayNamespaceId: NamespaceID) {
bulkFindOrCreateDevopsAdoptionSegments( bulkEnableDevopsAdoptionNamespaces(
input: { namespaceIds: $namespaceIds, displayNamespaceId: $displayNamespaceId } input: { namespaceIds: $namespaceIds, displayNamespaceId: $displayNamespaceId }
) { ) {
segments { enabledNamespaces {
id id
latestSnapshot { latestSnapshot {
issueOpened issueOpened
......
mutation($id: [AnalyticsDevopsAdoptionSegmentID!]!) {
deleteDevopsAdoptionSegment(input: { id: $id }) {
errors
}
}
mutation($id: [AnalyticsDevopsAdoptionEnabledNamespaceID!]!) {
disableDevopsAdoptionNamespace(input: { id: $id }) {
errors
}
}
query devopsAdoptionSegments($displayNamespaceId: NamespaceID) { query devopsAdoptionEnabledNamespaces($displayNamespaceId: NamespaceID) {
devopsAdoptionSegments(displayNamespaceId: $displayNamespaceId) { devopsAdoptionEnabledNamespaces(displayNamespaceId: $displayNamespaceId) {
nodes { nodes {
id id
latestSnapshot { latestSnapshot {
......
import produce from 'immer'; import produce from 'immer';
import devopsAdoptionSegmentsQuery from '../graphql/queries/devops_adoption_segments.query.graphql'; import devopsAdoptionEnabledNamespacesQuery from '../graphql/queries/devops_adoption_enabled_namespaces.query.graphql';
export const addSegmentsToCache = (store, segments, variables) => { export const addSegmentsToCache = (store, segments, variables) => {
const sourceData = store.readQuery({ const sourceData = store.readQuery({
query: devopsAdoptionSegmentsQuery, query: devopsAdoptionEnabledNamespacesQuery,
variables, variables,
}); });
const data = produce(sourceData, (draftData) => { const data = produce(sourceData, (draftData) => {
draftData.devopsAdoptionSegments.nodes = [ draftData.devopsAdoptionEnabledNamespaces.nodes = [
...draftData.devopsAdoptionSegments.nodes, ...draftData.devopsAdoptionEnabledNamespaces.nodes,
...segments, ...segments,
]; ];
}); });
store.writeQuery({ store.writeQuery({
query: devopsAdoptionSegmentsQuery, query: devopsAdoptionEnabledNamespacesQuery,
variables, variables,
data, data,
}); });
...@@ -23,18 +23,18 @@ export const addSegmentsToCache = (store, segments, variables) => { ...@@ -23,18 +23,18 @@ export const addSegmentsToCache = (store, segments, variables) => {
export const deleteSegmentsFromCache = (store, segmentIds, variables) => { export const deleteSegmentsFromCache = (store, segmentIds, variables) => {
const sourceData = store.readQuery({ const sourceData = store.readQuery({
query: devopsAdoptionSegmentsQuery, query: devopsAdoptionEnabledNamespacesQuery,
variables, variables,
}); });
const updatedData = produce(sourceData, (draftData) => { const updatedData = produce(sourceData, (draftData) => {
draftData.devopsAdoptionSegments.nodes = draftData.devopsAdoptionSegments.nodes.filter( draftData.devopsAdoptionEnabledNamespaces.nodes = draftData.devopsAdoptionEnabledNamespaces.nodes.filter(
({ id }) => !segmentIds.includes(id), ({ id }) => !segmentIds.includes(id),
); );
}); });
store.writeQuery({ store.writeQuery({
query: devopsAdoptionSegmentsQuery, query: devopsAdoptionEnabledNamespacesQuery,
variables, variables,
data: updatedData, data: updatedData,
}); });
......
...@@ -11,8 +11,8 @@ import { ...@@ -11,8 +11,8 @@ import {
DEFAULT_POLLING_INTERVAL, DEFAULT_POLLING_INTERVAL,
DEVOPS_ADOPTION_TABLE_CONFIGURATION, DEVOPS_ADOPTION_TABLE_CONFIGURATION,
} from 'ee/analytics/devops_report/devops_adoption/constants'; } from 'ee/analytics/devops_report/devops_adoption/constants';
import bulkFindOrCreateDevopsAdoptionSegmentsMutation from 'ee/analytics/devops_report/devops_adoption/graphql/mutations/bulk_find_or_create_devops_adoption_segments.mutation.graphql'; import bulkEnableDevopsAdoptionNamespacesMutation from 'ee/analytics/devops_report/devops_adoption/graphql/mutations/bulk_enable_devops_adoption_namespaces.mutation.graphql';
import devopsAdoptionSegments from 'ee/analytics/devops_report/devops_adoption/graphql/queries/devops_adoption_segments.query.graphql'; import devopsAdoptionEnabledNamespaces from 'ee/analytics/devops_report/devops_adoption/graphql/queries/devops_adoption_enabled_namespaces.query.graphql';
import getGroupsQuery from 'ee/analytics/devops_report/devops_adoption/graphql/queries/get_groups.query.graphql'; import getGroupsQuery from 'ee/analytics/devops_report/devops_adoption/graphql/queries/get_groups.query.graphql';
import { addSegmentsToCache } from 'ee/analytics/devops_report/devops_adoption/utils/cache_updates'; import { addSegmentsToCache } from 'ee/analytics/devops_report/devops_adoption/utils/cache_updates';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
...@@ -24,8 +24,8 @@ import { ...@@ -24,8 +24,8 @@ import {
groupNodes, groupNodes,
nextGroupNode, nextGroupNode,
groupPageInfo, groupPageInfo,
devopsAdoptionSegmentsData, devopsAdoptionNamespaceData,
devopsAdoptionSegmentsDataEmpty, devopsAdoptionNamespaceDataEmpty,
} from '../mock_data'; } from '../mock_data';
jest.mock('ee/analytics/devops_report/devops_adoption/utils/cache_updates', () => ({ jest.mock('ee/analytics/devops_report/devops_adoption/utils/cache_updates', () => ({
...@@ -45,13 +45,13 @@ describe('DevopsAdoptionApp', () => { ...@@ -45,13 +45,13 @@ describe('DevopsAdoptionApp', () => {
let wrapper; let wrapper;
const groupsEmpty = jest.fn().mockResolvedValue({ __typename: 'Groups', nodes: [] }); const groupsEmpty = jest.fn().mockResolvedValue({ __typename: 'Groups', nodes: [] });
const segmentsEmpty = jest const segmentsEmpty = jest.fn().mockResolvedValue({
.fn() data: { devopsAdoptionEnabledNamespaces: devopsAdoptionNamespaceDataEmpty },
.mockResolvedValue({ data: { devopsAdoptionSegments: devopsAdoptionSegmentsDataEmpty } }); });
const addSegmentMutationSpy = jest.fn().mockResolvedValue({ const addSegmentMutationSpy = jest.fn().mockResolvedValue({
data: { data: {
bulkFindOrCreateDevopsAdoptionSegments: { bulkEnableDevopsAdoptionNamespaces: {
segments: [devopsAdoptionSegmentsData.nodes[0]], enabledNamespaces: [devopsAdoptionNamespaceData.nodes[0]],
errors: [], errors: [],
}, },
}, },
...@@ -66,8 +66,8 @@ describe('DevopsAdoptionApp', () => { ...@@ -66,8 +66,8 @@ describe('DevopsAdoptionApp', () => {
const mockApollo = createMockApollo( const mockApollo = createMockApollo(
[ [
[bulkFindOrCreateDevopsAdoptionSegmentsMutation, addSegmentsSpy], [bulkEnableDevopsAdoptionNamespacesMutation, addSegmentsSpy],
[devopsAdoptionSegments, segmentsSpy], [devopsAdoptionEnabledNamespaces, segmentsSpy],
], ],
{ {
Query: { Query: {
...@@ -291,12 +291,12 @@ describe('DevopsAdoptionApp', () => { ...@@ -291,12 +291,12 @@ describe('DevopsAdoptionApp', () => {
}); });
describe('when there is an active group', () => { describe('when there is an active group', () => {
const groupGid = devopsAdoptionSegmentsData.nodes[0].namespace.id; const groupGid = devopsAdoptionNamespaceData.nodes[0].namespace.id;
describe('which is enabled', () => { describe('which is enabled', () => {
beforeEach(async () => { beforeEach(async () => {
const segmentsWithData = jest.fn().mockResolvedValue({ const segmentsWithData = jest.fn().mockResolvedValue({
data: { devopsAdoptionSegments: devopsAdoptionSegmentsData }, data: { devopsAdoptionEnabledNamespaces: devopsAdoptionNamespaceData },
}); });
const mockApollo = createMockApolloProvider({ const mockApollo = createMockApolloProvider({
segmentsSpy: segmentsWithData, segmentsSpy: segmentsWithData,
...@@ -341,7 +341,7 @@ describe('DevopsAdoptionApp', () => { ...@@ -341,7 +341,7 @@ describe('DevopsAdoptionApp', () => {
expect(addSegmentsToCache).toHaveBeenCalledTimes(1); expect(addSegmentsToCache).toHaveBeenCalledTimes(1);
expect(addSegmentsToCache).toHaveBeenCalledWith( expect(addSegmentsToCache).toHaveBeenCalledWith(
expect.anything(), expect.anything(),
[devopsAdoptionSegmentsData.nodes[0]], [devopsAdoptionNamespaceData.nodes[0]],
{ {
displayNamespaceId: groupGid, displayNamespaceId: groupGid,
}, },
...@@ -523,7 +523,7 @@ describe('DevopsAdoptionApp', () => { ...@@ -523,7 +523,7 @@ describe('DevopsAdoptionApp', () => {
mockApollo, mockApollo,
provide: { provide: {
isGroup: true, isGroup: true,
groupGid: devopsAdoptionSegmentsData.nodes[0].namespace.id, groupGid: devopsAdoptionNamespaceData.nodes[0].namespace.id,
}, },
}); });
}); });
......
...@@ -5,13 +5,13 @@ import Vue from 'vue'; ...@@ -5,13 +5,13 @@ import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import DevopsAdoptionDeleteModal from 'ee/analytics/devops_report/devops_adoption/components/devops_adoption_delete_modal.vue'; import DevopsAdoptionDeleteModal from 'ee/analytics/devops_report/devops_adoption/components/devops_adoption_delete_modal.vue';
import { DEVOPS_ADOPTION_SEGMENT_DELETE_MODAL_ID } from 'ee/analytics/devops_report/devops_adoption/constants'; import { DEVOPS_ADOPTION_SEGMENT_DELETE_MODAL_ID } from 'ee/analytics/devops_report/devops_adoption/constants';
import deleteDevopsAdoptionSegmentMutation from 'ee/analytics/devops_report/devops_adoption/graphql/mutations/delete_devops_adoption_segment.mutation.graphql'; import disableDevopsAdoptionNamespaceMutation from 'ee/analytics/devops_report/devops_adoption/graphql/mutations/disable_devops_adoption_namespace.mutation.graphql';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import { import {
genericDeleteErrorMessage, genericDeleteErrorMessage,
dataErrorMessage, dataErrorMessage,
devopsAdoptionSegmentsData, devopsAdoptionNamespaceData,
} from '../mock_data'; } from '../mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -20,14 +20,14 @@ Vue.use(VueApollo); ...@@ -20,14 +20,14 @@ Vue.use(VueApollo);
const mockEvent = { preventDefault: jest.fn() }; const mockEvent = { preventDefault: jest.fn() };
const mutate = jest.fn().mockResolvedValue({ const mutate = jest.fn().mockResolvedValue({
data: { data: {
deleteDevopsAdoptionSegment: { disableDevopsAdoptionNamespace: {
errors: [], errors: [],
}, },
}, },
}); });
const mutateWithDataErrors = jest.fn().mockResolvedValue({ const mutateWithDataErrors = jest.fn().mockResolvedValue({
data: { data: {
deleteDevopsAdoptionSegment: { disableDevopsAdoptionNamespace: {
errors: [dataErrorMessage], errors: [dataErrorMessage],
}, },
}, },
...@@ -39,13 +39,15 @@ describe('DevopsAdoptionDeleteModal', () => { ...@@ -39,13 +39,15 @@ describe('DevopsAdoptionDeleteModal', () => {
let wrapper; let wrapper;
const createComponent = ({ deleteSegmentsSpy = mutate, props = {} } = {}) => { const createComponent = ({ deleteSegmentsSpy = mutate, props = {} } = {}) => {
const mockApollo = createMockApollo([[deleteDevopsAdoptionSegmentMutation, deleteSegmentsSpy]]); const mockApollo = createMockApollo([
[disableDevopsAdoptionNamespaceMutation, deleteSegmentsSpy],
]);
wrapper = shallowMount(DevopsAdoptionDeleteModal, { wrapper = shallowMount(DevopsAdoptionDeleteModal, {
localVue, localVue,
apolloProvider: mockApollo, apolloProvider: mockApollo,
propsData: { propsData: {
segment: devopsAdoptionSegmentsData.nodes[0], segment: devopsAdoptionNamespaceData.nodes[0],
...props, ...props,
}, },
stubs: { stubs: {
...@@ -75,7 +77,7 @@ describe('DevopsAdoptionDeleteModal', () => { ...@@ -75,7 +77,7 @@ describe('DevopsAdoptionDeleteModal', () => {
}); });
it('displays the confirmation message', () => { it('displays the confirmation message', () => {
const text = `Are you sure that you would like to remove ${devopsAdoptionSegmentsData.nodes[0].namespace.fullName} from the table?`; const text = `Are you sure that you would like to remove ${devopsAdoptionNamespaceData.nodes[0].namespace.fullName} from the table?`;
expect(findModal().text()).toBe(text); expect(findModal().text()).toBe(text);
}); });
...@@ -136,14 +138,14 @@ describe('DevopsAdoptionDeleteModal', () => { ...@@ -136,14 +138,14 @@ describe('DevopsAdoptionDeleteModal', () => {
it('submits the correct request variables', () => { it('submits the correct request variables', () => {
expect(mutate).toHaveBeenCalledWith({ expect(mutate).toHaveBeenCalledWith({
id: [devopsAdoptionSegmentsData.nodes[0].id], id: [devopsAdoptionNamespaceData.nodes[0].id],
}); });
}); });
it('emits segmentsRemoved with the correct variables', () => { it('emits segmentsRemoved with the correct variables', () => {
const [params] = wrapper.emitted().segmentsRemoved[0]; const [params] = wrapper.emitted().segmentsRemoved[0];
expect(params).toStrictEqual([devopsAdoptionSegmentsData.nodes[0].id]); expect(params).toStrictEqual([devopsAdoptionNamespaceData.nodes[0].id]);
}); });
it('closes the modal after a successful mutation', () => { it('closes the modal after a successful mutation', () => {
......
...@@ -7,7 +7,7 @@ import DevopsAdoptionTable from 'ee/analytics/devops_report/devops_adoption/comp ...@@ -7,7 +7,7 @@ import DevopsAdoptionTable from 'ee/analytics/devops_report/devops_adoption/comp
import { DEVOPS_ADOPTION_TABLE_CONFIGURATION } from 'ee/analytics/devops_report/devops_adoption/constants'; import { DEVOPS_ADOPTION_TABLE_CONFIGURATION } from 'ee/analytics/devops_report/devops_adoption/constants';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import { devopsAdoptionSegmentsData } from '../mock_data'; import { devopsAdoptionNamespaceData } from '../mock_data';
describe('DevopsAdoptionSection', () => { describe('DevopsAdoptionSection', () => {
let wrapper; let wrapper;
...@@ -23,7 +23,7 @@ describe('DevopsAdoptionSection', () => { ...@@ -23,7 +23,7 @@ describe('DevopsAdoptionSection', () => {
segmentLimitReached: false, segmentLimitReached: false,
editGroupsButtonLabel: 'Add/Remove groups', editGroupsButtonLabel: 'Add/Remove groups',
cols: DEVOPS_ADOPTION_TABLE_CONFIGURATION[0].cols, cols: DEVOPS_ADOPTION_TABLE_CONFIGURATION[0].cols,
segments: devopsAdoptionSegmentsData, segments: devopsAdoptionNamespaceData,
addSegmentButtonTooltipText: 'Maximum 30 groups allowed', addSegmentButtonTooltipText: 'Maximum 30 groups allowed',
...props, ...props,
}, },
......
...@@ -5,8 +5,8 @@ import Vue, { nextTick } from 'vue'; ...@@ -5,8 +5,8 @@ import Vue, { nextTick } from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import DevopsAdoptionSegmentModal from 'ee/analytics/devops_report/devops_adoption/components/devops_adoption_segment_modal.vue'; import DevopsAdoptionSegmentModal from 'ee/analytics/devops_report/devops_adoption/components/devops_adoption_segment_modal.vue';
import { DEVOPS_ADOPTION_SEGMENT_MODAL_ID } from 'ee/analytics/devops_report/devops_adoption/constants'; import { DEVOPS_ADOPTION_SEGMENT_MODAL_ID } from 'ee/analytics/devops_report/devops_adoption/constants';
import bulkFindOrCreateDevopsAdoptionSegmentsMutation from 'ee/analytics/devops_report/devops_adoption/graphql/mutations/bulk_find_or_create_devops_adoption_segments.mutation.graphql'; import bulkEnableDevopsAdoptionNamespacesMutation from 'ee/analytics/devops_report/devops_adoption/graphql/mutations/bulk_enable_devops_adoption_namespaces.mutation.graphql';
import deleteDevopsAdoptionSegmentMutation from 'ee/analytics/devops_report/devops_adoption/graphql/mutations/delete_devops_adoption_segment.mutation.graphql'; import disableDevopsAdoptionNamespaceMutation from 'ee/analytics/devops_report/devops_adoption/graphql/mutations/disable_devops_adoption_namespace.mutation.graphql';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import { import {
...@@ -16,7 +16,7 @@ import { ...@@ -16,7 +16,7 @@ import {
genericErrorMessage, genericErrorMessage,
dataErrorMessage, dataErrorMessage,
groupNodeLabelValues, groupNodeLabelValues,
devopsAdoptionSegmentsData, devopsAdoptionNamespaceData,
} from '../mock_data'; } from '../mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -25,25 +25,25 @@ Vue.use(VueApollo); ...@@ -25,25 +25,25 @@ Vue.use(VueApollo);
const mockEvent = { preventDefault: jest.fn() }; const mockEvent = { preventDefault: jest.fn() };
const mutate = jest.fn().mockResolvedValue({ const mutate = jest.fn().mockResolvedValue({
data: { data: {
bulkFindOrCreateDevopsAdoptionSegments: { bulkEnableDevopsAdoptionNamespaces: {
segments: [devopsAdoptionSegmentsData.nodes[0]], enabledNamespaces: [devopsAdoptionNamespaceData.nodes[0]],
errors: [], errors: [],
}, },
deleteDevopsAdoptionSegment: { disableDevopsAdoptionNamespace: {
segments: [devopsAdoptionSegmentsData.nodes[0]], enabledNamespaces: [devopsAdoptionNamespaceData.nodes[0]],
errors: [], errors: [],
}, },
}, },
}); });
const mutateWithDataErrors = jest.fn().mockResolvedValue({ const mutateWithDataErrors = jest.fn().mockResolvedValue({
data: { data: {
bulkFindOrCreateDevopsAdoptionSegments: { bulkEnableDevopsAdoptionNamespaces: {
errors: [dataErrorMessage], errors: [dataErrorMessage],
segments: [], enabledNamespaces: [],
}, },
deleteDevopsAdoptionSegment: { disableDevopsAdoptionNamespace: {
errors: [dataErrorMessage], errors: [dataErrorMessage],
segments: [], enabledNamespaces: [],
}, },
}, },
}); });
...@@ -60,8 +60,8 @@ describe('DevopsAdoptionSegmentModal', () => { ...@@ -60,8 +60,8 @@ describe('DevopsAdoptionSegmentModal', () => {
provide = {}, provide = {},
} = {}) => { } = {}) => {
const mockApollo = createMockApollo([ const mockApollo = createMockApollo([
[deleteDevopsAdoptionSegmentMutation, deleteSegmentsSpy], [disableDevopsAdoptionNamespaceMutation, deleteSegmentsSpy],
[bulkFindOrCreateDevopsAdoptionSegmentsMutation, addSegmentsSpy], [bulkEnableDevopsAdoptionNamespacesMutation, addSegmentsSpy],
]); ]);
wrapper = shallowMount(DevopsAdoptionSegmentModal, { wrapper = shallowMount(DevopsAdoptionSegmentModal, {
...@@ -236,7 +236,7 @@ describe('DevopsAdoptionSegmentModal', () => { ...@@ -236,7 +236,7 @@ describe('DevopsAdoptionSegmentModal', () => {
const enableFirstGroup = { checkboxValues: [groupIds[0]] }; const enableFirstGroup = { checkboxValues: [groupIds[0]] };
const enableSecondGroup = { checkboxValues: [groupIds[1]] }; const enableSecondGroup = { checkboxValues: [groupIds[1]] };
const noEnabledGroups = { checkboxValues: [] }; const noEnabledGroups = { checkboxValues: [] };
const firstGroupEnabledData = [devopsAdoptionSegmentsData.nodes[0]]; const firstGroupEnabledData = [devopsAdoptionNamespaceData.nodes[0]];
const firstGroupId = [groupIds[0]]; const firstGroupId = [groupIds[0]];
const firstGroupGid = [groupGids[0]]; const firstGroupGid = [groupGids[0]];
const secondGroupGid = [groupGids[1]]; const secondGroupGid = [groupGids[1]];
...@@ -311,7 +311,7 @@ describe('DevopsAdoptionSegmentModal', () => { ...@@ -311,7 +311,7 @@ describe('DevopsAdoptionSegmentModal', () => {
it('emits segmentsAdded with the correct variables', () => { it('emits segmentsAdded with the correct variables', () => {
const [params] = wrapper.emitted().segmentsAdded[0]; const [params] = wrapper.emitted().segmentsAdded[0];
expect(params).toStrictEqual([devopsAdoptionSegmentsData.nodes[0]]); expect(params).toStrictEqual([devopsAdoptionNamespaceData.nodes[0]]);
}); });
} }
......
...@@ -10,7 +10,7 @@ import { ...@@ -10,7 +10,7 @@ import {
} from 'ee/analytics/devops_report/devops_adoption/constants'; } from 'ee/analytics/devops_report/devops_adoption/constants';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue'; import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
import { devopsAdoptionSegmentsData, devopsAdoptionTableHeaders } from '../mock_data'; import { devopsAdoptionNamespaceData, devopsAdoptionTableHeaders } from '../mock_data';
describe('DevopsAdoptionTable', () => { describe('DevopsAdoptionTable', () => {
let wrapper; let wrapper;
...@@ -21,7 +21,7 @@ describe('DevopsAdoptionTable', () => { ...@@ -21,7 +21,7 @@ describe('DevopsAdoptionTable', () => {
wrapper = mount(DevopsAdoptionTable, { wrapper = mount(DevopsAdoptionTable, {
propsData: { propsData: {
cols: DEVOPS_ADOPTION_TABLE_CONFIGURATION[0].cols, cols: DEVOPS_ADOPTION_TABLE_CONFIGURATION[0].cols,
segments: devopsAdoptionSegmentsData.nodes, segments: devopsAdoptionNamespaceData.nodes,
}, },
provide, provide,
directives: { directives: {
...@@ -112,7 +112,7 @@ describe('DevopsAdoptionTable', () => { ...@@ -112,7 +112,7 @@ describe('DevopsAdoptionTable', () => {
}); });
describe('"This group" badge', () => { describe('"This group" badge', () => {
const thisGroupGid = devopsAdoptionSegmentsData.nodes[0].namespace.id; const thisGroupGid = devopsAdoptionNamespaceData.nodes[0].namespace.id;
it.each` it.each`
scenario | expected | provide scenario | expected | provide
...@@ -167,7 +167,7 @@ describe('DevopsAdoptionTable', () => { ...@@ -167,7 +167,7 @@ describe('DevopsAdoptionTable', () => {
describe.each` describe.each`
scenario | tooltipText | provide | disabled scenario | tooltipText | provide | disabled
${'not active group'} | ${'Remove Group from the table.'} | ${{}} | ${false} ${'not active group'} | ${'Remove Group from the table.'} | ${{}} | ${false}
${'active group'} | ${'You cannot remove the group you are currently in.'} | ${{ groupGid: devopsAdoptionSegmentsData.nodes[0].namespace.id }} | ${true} ${'active group'} | ${'You cannot remove the group you are currently in.'} | ${{ groupGid: devopsAdoptionNamespaceData.nodes[0].namespace.id }} | ${true}
`('actions column when $scenario', ({ tooltipText, provide, disabled }) => { `('actions column when $scenario', ({ tooltipText, provide, disabled }) => {
beforeEach(() => { beforeEach(() => {
createComponent({ provide }); createComponent({ provide });
...@@ -197,7 +197,9 @@ describe('DevopsAdoptionTable', () => { ...@@ -197,7 +197,9 @@ describe('DevopsAdoptionTable', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
wrapper.setData({ selectedSegment: devopsAdoptionSegmentsData.nodes[0] }); wrapper.setData({
selectedSegment: devopsAdoptionNamespaceData.nodes[0],
});
}); });
it('re emits trackModalOpenState with the given value', async () => { it('re emits trackModalOpenState with the given value', async () => {
......
...@@ -39,7 +39,7 @@ export const groupPageInfo = { ...@@ -39,7 +39,7 @@ export const groupPageInfo = {
nextPage: 2, nextPage: 2,
}; };
export const devopsAdoptionSegmentsData = { export const devopsAdoptionNamespaceData = {
nodes: [ nodes: [
{ {
id: 1, id: 1,
...@@ -59,7 +59,7 @@ export const devopsAdoptionSegmentsData = { ...@@ -59,7 +59,7 @@ export const devopsAdoptionSegmentsData = {
recordedAt: '2020-10-31T23:59:59Z', recordedAt: '2020-10-31T23:59:59Z',
__typename: 'latestSnapshot', __typename: 'latestSnapshot',
}, },
__typename: 'devopsSegment', __typename: 'devopsAdoptionEnabledNamespace',
}, },
{ {
id: 2, id: 2,
...@@ -68,13 +68,13 @@ export const devopsAdoptionSegmentsData = { ...@@ -68,13 +68,13 @@ export const devopsAdoptionSegmentsData = {
id: 'gid://gitlab/Group/2', id: 'gid://gitlab/Group/2',
}, },
latestSnapshot: null, latestSnapshot: null,
__typename: 'devopsSegment', __typename: 'devopsAdoptionEnabledNamespace',
}, },
], ],
__typename: 'devopsAdoptionSegments', __typename: 'devopsAdoptionEnabledNamespaces',
}; };
export const devopsAdoptionSegmentsDataEmpty = { export const devopsAdoptionNamespaceDataEmpty = {
nodes: [], nodes: [],
__typename: 'devopsAdoptionSegments', __typename: 'devopsAdoptionSegments',
}; };
......
...@@ -2,22 +2,22 @@ import { ...@@ -2,22 +2,22 @@ import {
deleteSegmentsFromCache, deleteSegmentsFromCache,
addSegmentsToCache, addSegmentsToCache,
} from 'ee/analytics/devops_report/devops_adoption/utils/cache_updates'; } from 'ee/analytics/devops_report/devops_adoption/utils/cache_updates';
import { devopsAdoptionSegmentsData } from '../mock_data'; import { devopsAdoptionNamespaceData } from '../mock_data';
describe('addSegmentsToCache', () => { describe('addSegmentsToCache', () => {
const store = { const store = {
readQuery: jest.fn(() => ({ devopsAdoptionSegments: { nodes: [] } })), readQuery: jest.fn(() => ({ devopsAdoptionEnabledNamespaces: { nodes: [] } })),
writeQuery: jest.fn(), writeQuery: jest.fn(),
}; };
it('calls writeQuery with the correct response', () => { it('calls writeQuery with the correct response', () => {
addSegmentsToCache(store, devopsAdoptionSegmentsData.nodes); addSegmentsToCache(store, devopsAdoptionNamespaceData.nodes);
expect(store.writeQuery).toHaveBeenCalledWith( expect(store.writeQuery).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
data: { data: {
devopsAdoptionSegments: { devopsAdoptionEnabledNamespaces: {
nodes: devopsAdoptionSegmentsData.nodes, nodes: devopsAdoptionNamespaceData.nodes,
}, },
}, },
}), }),
...@@ -27,20 +27,20 @@ describe('addSegmentsToCache', () => { ...@@ -27,20 +27,20 @@ describe('addSegmentsToCache', () => {
describe('deleteSegmentsFromCache', () => { describe('deleteSegmentsFromCache', () => {
const store = { const store = {
readQuery: jest.fn(() => ({ devopsAdoptionSegments: devopsAdoptionSegmentsData })), readQuery: jest.fn(() => ({ devopsAdoptionEnabledNamespaces: devopsAdoptionNamespaceData })),
writeQuery: jest.fn(), writeQuery: jest.fn(),
}; };
it('calls writeQuery with the correct response', () => { it('calls writeQuery with the correct response', () => {
// Remove the item at the first index // Remove the item at the first index
deleteSegmentsFromCache(store, [devopsAdoptionSegmentsData.nodes[0].id]); deleteSegmentsFromCache(store, [devopsAdoptionNamespaceData.nodes[0].id]);
expect(store.writeQuery).toHaveBeenCalledWith( expect(store.writeQuery).toHaveBeenCalledWith(
expect.not.objectContaining({ expect.not.objectContaining({
data: { data: {
devopsAdoptionSegments: { devopsAdoptionEnabledNamespaces: {
__typename: 'devopsAdoptionSegments', __typename: 'devopsAdoptionEnabledNamespaces',
nodes: devopsAdoptionSegmentsData.nodes, nodes: devopsAdoptionNamespaceData.nodes,
}, },
}, },
}), }),
...@@ -48,10 +48,10 @@ describe('deleteSegmentsFromCache', () => { ...@@ -48,10 +48,10 @@ describe('deleteSegmentsFromCache', () => {
expect(store.writeQuery).toHaveBeenCalledWith( expect(store.writeQuery).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
data: { data: {
devopsAdoptionSegments: { devopsAdoptionEnabledNamespaces: {
__typename: 'devopsAdoptionSegments', __typename: 'devopsAdoptionEnabledNamespaces',
// Remove the item at the first index // Remove the item at the first index
nodes: devopsAdoptionSegmentsData.nodes.slice(1), nodes: devopsAdoptionNamespaceData.nodes.slice(1),
}, },
}, },
}), }),
......
import { shouldPollTableData } from 'ee/analytics/devops_report/devops_adoption/utils/helpers'; import { shouldPollTableData } from 'ee/analytics/devops_report/devops_adoption/utils/helpers';
import { devopsAdoptionSegmentsData } from '../mock_data'; import { devopsAdoptionNamespaceData } from '../mock_data';
describe('shouldPollTableData', () => { describe('shouldPollTableData', () => {
const { nodes: pendingData } = devopsAdoptionSegmentsData; const { nodes: pendingData } = devopsAdoptionNamespaceData;
const comepleteData = [pendingData[0]]; const comepleteData = [pendingData[0]];
const mockDate = '2020-07-06T00:00:00.000Z'; const mockDate = '2020-07-06T00:00:00.000Z';
const previousDay = '2020-07-05T00:00:00.000Z'; const previousDay = '2020-07-05T00:00:00.000Z';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment