Commit 920e7f26 authored by Phil Hughes's avatar Phil Hughes

Merge branch '331416-devops-adoption-fe-remove-remaining-references-to-segments' into 'master'

DevOps Adoption - Remove remaining references to segments

See merge request gitlab-org/gitlab!65434
parents 10bf0ac7 b3a9c3af
......@@ -100,7 +100,7 @@ export default {
bulkEnableDevopsAdoptionNamespaces: { enabledNamespaces, errors: requestErrors },
} = data;
if (!requestErrors.length) this.$emit('segmentsAdded', enabledNamespaces);
if (!requestErrors.length) this.$emit('enabledNamespacesAdded', enabledNamespaces);
},
})
.catch((error) => {
......
......@@ -19,7 +19,10 @@ import {
import bulkEnableDevopsAdoptionNamespacesMutation from '../graphql/mutations/bulk_enable_devops_adoption_namespaces.mutation.graphql';
import devopsAdoptionEnabledNamespacesQuery from '../graphql/queries/devops_adoption_enabled_namespaces.query.graphql';
import getGroupsQuery from '../graphql/queries/get_groups.query.graphql';
import { addSegmentsToCache, deleteSegmentsFromCache } from '../utils/cache_updates';
import {
addEnabledNamespacesToCache,
deleteEnabledNamespacesFromCache,
} from '../utils/cache_updates';
import { shouldPollTableData } from '../utils/helpers';
import DevopsAdoptionAddDropdown from './devops_adoption_add_dropdown.vue';
import DevopsAdoptionOverview from './devops_adoption_overview.vue';
......@@ -69,15 +72,15 @@ export default {
openModal: false,
errors: {
[DEVOPS_ADOPTION_ERROR_KEYS.groups]: false,
[DEVOPS_ADOPTION_ERROR_KEYS.segments]: false,
[DEVOPS_ADOPTION_ERROR_KEYS.addSegment]: false,
[DEVOPS_ADOPTION_ERROR_KEYS.enabledNamespaces]: false,
[DEVOPS_ADOPTION_ERROR_KEYS.addEnabledNamespaces]: false,
},
groups: {
nodes: [],
pageInfo: null,
},
pollingTableData: null,
segmentsQueryVariables: {
enabledNamespaceQueryVariables: {
displayNamespaceId: this.isGroup ? this.groupGid : null,
},
adoptionTabClicked: false,
......@@ -92,7 +95,7 @@ export default {
isSingleRequest: true,
},
variables() {
return this.segmentsQueryVariables;
return this.enabledNamespaceQueryVariables;
},
result({ data }) {
if (this.isGroup) {
......@@ -106,7 +109,7 @@ export default {
}
},
error(error) {
this.handleError(DEVOPS_ADOPTION_ERROR_KEYS.segments, error);
this.handleError(DEVOPS_ADOPTION_ERROR_KEYS.enabledNamespaces, error);
},
},
},
......@@ -117,7 +120,7 @@ export default {
hasGroupData() {
return Boolean(this.groups?.nodes?.length);
},
hasSegmentsData() {
hasEnabledNamespaceData() {
return Boolean(this.devopsAdoptionEnabledNamespaces?.nodes?.length);
},
hasLoadingError() {
......@@ -191,14 +194,14 @@ export default {
} = data;
if (errors.length) {
this.handleError(DEVOPS_ADOPTION_ERROR_KEYS.addSegment, errors);
this.handleError(DEVOPS_ADOPTION_ERROR_KEYS.addEnabledNamespaces, errors);
} else {
this.addSegmentsToCache(enabledNamespaces);
this.addEnabledNamespacesToCache(enabledNamespaces);
}
},
})
.catch((error) => {
this.handleError(DEVOPS_ADOPTION_ERROR_KEYS.addSegment, error);
this.handleError(DEVOPS_ADOPTION_ERROR_KEYS.addEnabledNamespaces, error);
})
.finally(() => {
this.isLoadingEnableGroup = false;
......@@ -206,7 +209,7 @@ export default {
},
pollTableData() {
const shouldPoll = shouldPollTableData({
segments: this.devopsAdoptionEnabledNamespaces.nodes,
enabledNamespaces: this.devopsAdoptionEnabledNamespaces.nodes,
timestamp: this.devopsAdoptionEnabledNamespaces?.nodes[0]?.latestSnapshot?.recordedAt,
openModal: this.openModal,
});
......@@ -250,15 +253,15 @@ export default {
})
.catch((error) => this.handleError(DEVOPS_ADOPTION_ERROR_KEYS.groups, error));
},
addSegmentsToCache(segments) {
addEnabledNamespacesToCache(enabledNamespaces) {
const { cache } = this.$apollo.getClient();
addSegmentsToCache(cache, segments, this.segmentsQueryVariables);
addEnabledNamespacesToCache(cache, enabledNamespaces, this.enabledNamespaceQueryVariables);
},
deleteSegmentsFromCache(ids) {
deleteEnabledNamespacesFromCache(ids) {
const { cache } = this.$apollo.getClient();
deleteSegmentsFromCache(cache, ids, this.segmentsQueryVariables);
deleteEnabledNamespacesFromCache(cache, ids, this.enabledNamespaceQueryVariables);
},
selectTab() {
const [value] = getParameterValues('tab');
......@@ -327,18 +330,18 @@ export default {
<devops-adoption-section
v-else
:is-loading="isLoadingAdoptionData"
:has-segments-data="hasSegmentsData"
:has-enabled-namespace-data="hasEnabledNamespaceData"
:timestamp="timestamp"
:has-group-data="hasGroupData"
:cols="tab.cols"
:segments="devopsAdoptionEnabledNamespaces"
:enabled-namespaces="devopsAdoptionEnabledNamespaces"
:search-term="searchTerm"
:disabled-group-nodes="disabledGroupNodes"
:is-loading-groups="isLoadingGroups"
:has-subgroups="hasSubgroups"
@segmentsRemoved="deleteSegmentsFromCache"
@enabledNamespacesRemoved="deleteEnabledNamespacesFromCache"
@fetchGroups="fetchGroups"
@segmentsAdded="addSegmentsToCache"
@enabledNamespacesAdded="addEnabledNamespacesToCache"
@trackModalOpenState="trackModalOpenState"
/>
</gl-tab>
......@@ -359,7 +362,7 @@ export default {
:is-loading-groups="isLoadingGroups"
:has-subgroups="hasSubgroups"
@fetchGroups="fetchGroups"
@segmentsAdded="addSegmentsToCache"
@enabledNamespacesAdded="addEnabledNamespacesToCache"
/>
</span>
</template>
......
<script>
import { GlModal, GlSprintf, GlAlert } from '@gitlab/ui';
import * as Sentry from '@sentry/browser';
import { DEVOPS_ADOPTION_STRINGS, DEVOPS_ADOPTION_SEGMENT_DELETE_MODAL_ID } from '../constants';
import { DEVOPS_ADOPTION_STRINGS, DEVOPS_ADOPTION_DELETE_MODAL_ID } from '../constants';
import disableDevopsAdoptionNamespaceMutation from '../graphql/mutations/disable_devops_adoption_namespace.mutation.graphql';
export default {
name: 'DevopsAdoptionDeleteModal',
components: { GlModal, GlSprintf, GlAlert },
i18n: DEVOPS_ADOPTION_STRINGS.deleteModal,
devopsSegmentDeleteModalId: DEVOPS_ADOPTION_SEGMENT_DELETE_MODAL_ID,
deleteModalId: DEVOPS_ADOPTION_DELETE_MODAL_ID,
props: {
segment: {
namespace: {
type: Object,
required: true,
},
......@@ -43,14 +43,14 @@ export default {
return this.errors[0];
},
displayName() {
return this.segment.namespace?.fullName;
return this.namespace.namespace?.fullName;
},
},
methods: {
async deleteSegment() {
async deleteEnabledNamespace() {
try {
const {
segment: { id },
namespace: { id },
} = this;
this.loading = true;
......@@ -65,7 +65,7 @@ export default {
id: [id],
},
update: () => {
this.$emit('segmentsRemoved', [id]);
this.$emit('enabledNamespacesRemoved', [id]);
},
});
......@@ -90,11 +90,11 @@ export default {
<template>
<gl-modal
ref="modal"
:modal-id="$options.devopsSegmentDeleteModalId"
:modal-id="$options.deleteModalId"
size="sm"
:action-primary="primaryOptions"
:action-cancel="cancelOptions"
@primary.prevent="deleteSegment"
@primary.prevent="deleteEnabledNamespace"
@hide="$emit('trackModalOpenState', false)"
@show="$emit('trackModalOpenState', true)"
>
......
......@@ -21,7 +21,7 @@ export default {
type: Boolean,
required: true,
},
hasSegmentsData: {
hasEnabledNamespaceData: {
type: Boolean,
required: true,
},
......@@ -37,7 +37,7 @@ export default {
type: Array,
required: true,
},
segments: {
enabledNamespaces: {
type: Object,
required: false,
default: () => {},
......@@ -64,7 +64,7 @@ export default {
</script>
<template>
<gl-loading-icon v-if="isLoading" size="md" class="gl-my-5" />
<div v-else-if="hasSegmentsData" class="gl-mt-3">
<div v-else-if="hasEnabledNamespaceData" class="gl-mt-3">
<div class="gl-mb-3" data-testid="tableHeader">
<p class="gl-text-gray-400">
<gl-sprintf :message="$options.i18n.tableHeaderText">
......@@ -79,14 +79,14 @@ export default {
:is-loading-groups="isLoadingGroups"
:has-subgroups="hasSubgroups"
@fetchGroups="$emit('fetchGroups', $event)"
@segmentsAdded="$emit('segmentsAdded', $event)"
@enabledNamespacesAdded="$emit('enabledNamespacesAdded', $event)"
@trackModalOpenState="$emit('trackModalOpenState', $event)"
/>
</div>
<devops-adoption-table
:cols="cols"
:segments="segments.nodes"
@segmentsRemoved="$emit('segmentsRemoved', $event)"
:enabled-namespaces="enabledNamespaces.nodes"
@enabledNamespacesRemoved="$emit('enabledNamespacesRemoved', $event)"
@trackModalOpenState="$emit('trackModalOpenState', $event)"
/>
</div>
......
......@@ -11,9 +11,9 @@ import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
import {
DEVOPS_ADOPTION_TABLE_TEST_IDS,
DEVOPS_ADOPTION_STRINGS,
DEVOPS_ADOPTION_SEGMENT_DELETE_MODAL_ID,
DEVOPS_ADOPTION_SEGMENTS_TABLE_SORT_BY_STORAGE_KEY,
DEVOPS_ADOPTION_SEGMENTS_TABLE_SORT_DESC_STORAGE_KEY,
DEVOPS_ADOPTION_DELETE_MODAL_ID,
DEVOPS_ADOPTION_TABLE_SORT_BY_STORAGE_KEY,
DEVOPS_ADOPTION_TABLE_SORT_DESC_STORAGE_KEY,
DEVOPS_ADOPTION_TABLE_REMOVE_BUTTON_DISABLED,
DEVOPS_ADOPTION_GROUP_COL_LABEL,
} from '../constants';
......@@ -70,12 +70,12 @@ export default {
...i18n,
removeButtonDisabled: DEVOPS_ADOPTION_TABLE_REMOVE_BUTTON_DISABLED,
},
devopsSegmentDeleteModalId: DEVOPS_ADOPTION_SEGMENT_DELETE_MODAL_ID,
deleteModalId: DEVOPS_ADOPTION_DELETE_MODAL_ID,
testids: DEVOPS_ADOPTION_TABLE_TEST_IDS,
sortByStorageKey: DEVOPS_ADOPTION_SEGMENTS_TABLE_SORT_BY_STORAGE_KEY,
sortDescStorageKey: DEVOPS_ADOPTION_SEGMENTS_TABLE_SORT_DESC_STORAGE_KEY,
sortByStorageKey: DEVOPS_ADOPTION_TABLE_SORT_BY_STORAGE_KEY,
sortDescStorageKey: DEVOPS_ADOPTION_TABLE_SORT_DESC_STORAGE_KEY,
props: {
segments: {
enabledNamespaces: {
type: Array,
required: true,
},
......@@ -88,7 +88,7 @@ export default {
return {
sortBy: NAME_HEADER,
sortDesc: false,
selectedSegment: null,
selectedNamespace: null,
};
},
computed: {
......@@ -113,8 +113,8 @@ export default {
},
},
methods: {
setSelectedSegment(segment) {
this.selectedSegment = segment;
setSelectedNamespace(namespace) {
this.selectedNamespace = namespace;
},
headerSlotName(key) {
return `head(${key})`;
......@@ -149,7 +149,7 @@ export default {
/>
<gl-table
:fields="tableHeaderFields"
:items="segments"
:items="enabledNamespaces"
:sort-by.sync="sortBy"
:sort-desc.sync="sortDesc"
thead-class="gl-border-t-0 gl-border-b-solid gl-border-b-1 gl-border-b-gray-100"
......@@ -169,7 +169,7 @@ export default {
</template>
<template #cell(name)="{ item }">
<div :data-testid="$options.testids.SEGMENT">
<div :data-testid="$options.testids.NAMESPACE">
<strong v-if="item.latestSnapshot">{{ item.namespace.fullName }}</strong>
<template v-else>
<span class="gl-text-gray-400">{{ item.namespace.fullName }}</span>
......@@ -196,20 +196,20 @@ export default {
:data-testid="$options.testids.ACTIONS"
>
<gl-button
v-gl-modal="$options.devopsSegmentDeleteModalId"
v-gl-modal="$options.deleteModalId"
:disabled="isCurrentGroup(item)"
category="tertiary"
icon="remove"
:aria-label="$options.i18n.removeButton"
@click="setSelectedSegment(item)"
@click="setSelectedNamespace(item)"
/>
</span>
</template>
</gl-table>
<devops-adoption-delete-modal
v-if="selectedSegment"
:segment="selectedSegment"
@segmentsRemoved="$emit('segmentsRemoved', $event)"
v-if="selectedNamespace"
:namespace="selectedNamespace"
@enabledNamespacesRemoved="$emit('enabledNamespacesRemoved', $event)"
@trackModalOpenState="$emit('trackModalOpenState', $event)"
/>
</div>
......
......@@ -8,14 +8,14 @@ export const DEBOUNCE_DELAY = 500;
export const DEVOPS_ADOPTION_PROGRESS_BAR_HEIGHT = '8px';
export const DEVOPS_ADOPTION_SEGMENT_DELETE_MODAL_ID = 'devopsSegmentDeleteModal';
export const DEVOPS_ADOPTION_DELETE_MODAL_ID = 'devopsDeleteModal';
export const DATE_TIME_FORMAT = 'yyyy-mm-dd HH:MM';
export const DEVOPS_ADOPTION_ERROR_KEYS = {
groups: 'groupsError',
segments: 'segmentsError',
addSegment: 'addSegmentsError',
enabledNamespaces: 'enabledNamespacesError',
addEnabledNamespaces: 'addEnabledNamespacesError',
};
export const TABLE_HEADER_TEXT = s__(
......@@ -46,10 +46,10 @@ export const DEVOPS_ADOPTION_STRINGS = {
[DEVOPS_ADOPTION_ERROR_KEYS.groups]: s__(
'DevopsAdoption|There was an error fetching Groups. Please refresh the page.',
),
[DEVOPS_ADOPTION_ERROR_KEYS.segments]: s__(
[DEVOPS_ADOPTION_ERROR_KEYS.enabledNamespaces]: s__(
'DevopsAdoption|There was an error fetching Group adoption data. Please refresh the page.',
),
[DEVOPS_ADOPTION_ERROR_KEYS.addSegment]: s__(
[DEVOPS_ADOPTION_ERROR_KEYS.addEnabledNamespaces]: s__(
'DevopsAdoption|There was an error enabling the current group. Please refresh the page.',
),
tableHeader: {
......@@ -92,17 +92,15 @@ export const DEVOPS_ADOPTION_STRINGS = {
export const DEVOPS_ADOPTION_TABLE_TEST_IDS = {
TABLE_HEADERS: 'header',
SEGMENT: 'segmentCol',
NAMESPACE: 'namespaceCol',
ACTIONS: 'actionsCol',
LOCAL_STORAGE_SORT_BY: 'localStorageSortBy',
LOCAL_STORAGE_SORT_DESC: 'localStorageSortDesc',
};
export const DEVOPS_ADOPTION_SEGMENTS_TABLE_SORT_BY_STORAGE_KEY =
'devops_adoption_segments_table_sort_by';
export const DEVOPS_ADOPTION_TABLE_SORT_BY_STORAGE_KEY = 'devops_adoption_table_sort_by';
export const DEVOPS_ADOPTION_SEGMENTS_TABLE_SORT_DESC_STORAGE_KEY =
'devops_adoption_segments_table_sort_desc';
export const DEVOPS_ADOPTION_TABLE_SORT_DESC_STORAGE_KEY = 'devops_adoption_table_sort_desc';
export const DEVOPS_ADOPTION_GROUP_COL_LABEL = __('Group');
......
import produce from 'immer';
import devopsAdoptionEnabledNamespacesQuery from '../graphql/queries/devops_adoption_enabled_namespaces.query.graphql';
export const addSegmentsToCache = (store, segments, variables) => {
export const addEnabledNamespacesToCache = (store, enabledNamespaces, variables) => {
const sourceData = store.readQuery({
query: devopsAdoptionEnabledNamespacesQuery,
variables,
......@@ -10,7 +10,7 @@ export const addSegmentsToCache = (store, segments, variables) => {
const data = produce(sourceData, (draftData) => {
draftData.devopsAdoptionEnabledNamespaces.nodes = [
...draftData.devopsAdoptionEnabledNamespaces.nodes,
...segments,
...enabledNamespaces,
];
});
......@@ -21,7 +21,7 @@ export const addSegmentsToCache = (store, segments, variables) => {
});
};
export const deleteSegmentsFromCache = (store, segmentIds, variables) => {
export const deleteEnabledNamespacesFromCache = (store, enabledNamespaceIds, variables) => {
const sourceData = store.readQuery({
query: devopsAdoptionEnabledNamespacesQuery,
variables,
......@@ -29,7 +29,7 @@ export const deleteSegmentsFromCache = (store, segmentIds, variables) => {
const updatedData = produce(sourceData, (draftData) => {
draftData.devopsAdoptionEnabledNamespaces.nodes = draftData.devopsAdoptionEnabledNamespaces.nodes.filter(
({ id }) => !segmentIds.includes(id),
({ id }) => !enabledNamespaceIds.includes(id),
);
});
......
import { isToday } from '~/lib/utils/datetime_utility';
/**
* A helper function which accepts the segments,
* A helper function which accepts the enabledNamespaces,
*
* @param {Object} params the segment data, timestamp and check for open modals
* @param {Object} params the enabledNamespaces data, timestamp and check for open modals
*
* @return {Boolean} a boolean to determine if table data should be polled
*/
export const shouldPollTableData = ({ segments, timestamp, openModal }) => {
export const shouldPollTableData = ({ enabledNamespaces, timestamp, openModal }) => {
if (openModal) {
return false;
} else if (!segments.length) {
} else if (!enabledNamespaces.length) {
return true;
}
const anyPendingSegments = segments.some((node) => node.latestSnapshot === null);
const anyPendingEnabledNamespaces = enabledNamespaces.some(
(node) => node.latestSnapshot === null,
);
const dataNotRefreshedToday = !isToday(new Date(timestamp));
return anyPendingSegments || dataNotRefreshedToday;
return anyPendingEnabledNamespaces || dataNotRefreshedToday;
};
......@@ -149,8 +149,8 @@ describe('DevopsAdoptionAddDropdown', () => {
});
});
it('emits the segmentsAdded event', () => {
const [params] = wrapper.emitted().segmentsAdded[0];
it('emits the enabledNamespacesAdded event', () => {
const [params] = wrapper.emitted().enabledNamespacesAdded[0];
expect(params).toStrictEqual([devopsAdoptionNamespaceData.nodes[0]]);
});
......@@ -174,8 +174,8 @@ describe('DevopsAdoptionAddDropdown', () => {
);
});
it('does not emit the segmentsAdded event', () => {
expect(wrapper.emitted().segmentsAdded).not.toBeDefined();
it('does not emit the enabledNamespacesAdded event', () => {
expect(wrapper.emitted().enabledNamespacesAdded).not.toBeDefined();
});
});
});
......
......@@ -15,7 +15,7 @@ import {
import bulkEnableDevopsAdoptionNamespacesMutation from 'ee/analytics/devops_report/devops_adoption/graphql/mutations/bulk_enable_devops_adoption_namespaces.mutation.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 { addSegmentsToCache } from 'ee/analytics/devops_report/devops_adoption/utils/cache_updates';
import { addEnabledNamespacesToCache } from 'ee/analytics/devops_report/devops_adoption/utils/cache_updates';
import createMockApollo from 'helpers/mock_apollo_helper';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises';
......@@ -24,7 +24,7 @@ import API from '~/api';
import { groupNodes, devopsAdoptionNamespaceData } from '../mock_data';
jest.mock('ee/analytics/devops_report/devops_adoption/utils/cache_updates', () => ({
addSegmentsToCache: jest.fn(),
addEnabledNamespacesToCache: jest.fn(),
}));
const localVue = createLocalVue();
......@@ -234,9 +234,9 @@ describe('DevopsAdoptionApp', () => {
);
});
it('calls addSegmentsToCache with the correct variables', () => {
expect(addSegmentsToCache).toHaveBeenCalledTimes(1);
expect(addSegmentsToCache).toHaveBeenCalledWith(
it('calls addEnabledNamespacesToCache with the correct variables', () => {
expect(addEnabledNamespacesToCache).toHaveBeenCalledTimes(1);
expect(addEnabledNamespacesToCache).toHaveBeenCalledWith(
expect.anything(),
[devopsAdoptionNamespaceData.nodes[0]],
{
......@@ -270,7 +270,7 @@ describe('DevopsAdoptionApp', () => {
it('displays the error message ', () => {
const alert = wrapper.findComponent(GlAlert);
expect(alert.exists()).toBe(true);
expect(alert.text()).toBe(DEVOPS_ADOPTION_STRINGS.app.addSegmentsError);
expect(alert.text()).toBe(DEVOPS_ADOPTION_STRINGS.app.addEnabledNamespacesError);
});
it('calls Sentry', () => {
......@@ -301,7 +301,7 @@ describe('DevopsAdoptionApp', () => {
it('displays the error message ', () => {
const alert = wrapper.findComponent(GlAlert);
expect(alert.exists()).toBe(true);
expect(alert.text()).toBe(DEVOPS_ADOPTION_STRINGS.app.segmentsError);
expect(alert.text()).toBe(DEVOPS_ADOPTION_STRINGS.app.enabledNamespacesError);
});
it('calls Sentry', () => {
......
......@@ -4,7 +4,7 @@ import { createLocalVue, shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import VueApollo from 'vue-apollo';
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_DELETE_MODAL_ID } from 'ee/analytics/devops_report/devops_adoption/constants';
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 waitForPromises from 'helpers/wait_for_promises';
......@@ -38,16 +38,16 @@ const mutateWithErrors = jest.fn().mockRejectedValue(genericDeleteErrorMessage);
describe('DevopsAdoptionDeleteModal', () => {
let wrapper;
const createComponent = ({ deleteSegmentsSpy = mutate, props = {} } = {}) => {
const createComponent = ({ deleteEnabledNamespacesSpy = mutate, props = {} } = {}) => {
const mockApollo = createMockApollo([
[disableDevopsAdoptionNamespaceMutation, deleteSegmentsSpy],
[disableDevopsAdoptionNamespaceMutation, deleteEnabledNamespacesSpy],
]);
wrapper = shallowMount(DevopsAdoptionDeleteModal, {
localVue,
apolloProvider: mockApollo,
propsData: {
segment: devopsAdoptionNamespaceData.nodes[0],
namespace: devopsAdoptionNamespaceData.nodes[0],
...props,
},
stubs: {
......@@ -63,7 +63,6 @@ describe('DevopsAdoptionDeleteModal', () => {
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
describe('default display', () => {
......@@ -73,7 +72,7 @@ describe('DevopsAdoptionDeleteModal', () => {
const modal = findModal();
expect(modal.exists()).toBe(true);
expect(modal.props('modalId')).toBe(DEVOPS_ADOPTION_SEGMENT_DELETE_MODAL_ID);
expect(modal.props('modalId')).toBe(DEVOPS_ADOPTION_DELETE_MODAL_ID);
});
it('displays the confirmation message', () => {
......@@ -104,7 +103,7 @@ describe('DevopsAdoptionDeleteModal', () => {
describe('submitting the form', () => {
describe('while waiting for the mutation', () => {
beforeEach(() => createComponent({ deleteSegmentsSpy: mutateLoading }));
beforeEach(() => createComponent({ deleteEnabledNamespacesSpy: mutateLoading }));
it('disables the cancel button', async () => {
expect(cancelButtonDisabledState()).toBe(false);
......@@ -142,8 +141,8 @@ describe('DevopsAdoptionDeleteModal', () => {
});
});
it('emits segmentsRemoved with the correct variables', () => {
const [params] = wrapper.emitted().segmentsRemoved[0];
it('emits dNamespacesRemoved with the correct variables', () => {
const [params] = wrapper.emitted().enabledNamespacesRemoved[0];
expect(params).toStrictEqual([devopsAdoptionNamespaceData.nodes[0].id]);
});
......@@ -161,7 +160,7 @@ describe('DevopsAdoptionDeleteModal', () => {
`(
'displays a $errorType error if the mutation has a $errorLocation error',
async ({ mutationSpy, message }) => {
createComponent({ deleteSegmentsSpy: mutationSpy });
createComponent({ deleteEnabledNamespacesSpy: mutationSpy });
findModal().vm.$emit('primary', mockEvent);
......@@ -178,7 +177,7 @@ describe('DevopsAdoptionDeleteModal', () => {
it('calls sentry on top level error', async () => {
jest.spyOn(Sentry, 'captureException');
createComponent({ deleteSegmentsSpy: mutateWithErrors });
createComponent({ deleteEnabledNamespacesSpy: mutateWithErrors });
findModal().vm.$emit('primary', mockEvent);
......
......@@ -27,7 +27,6 @@ describe('DevopsAdoptionEmptyState', () => {
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
it('contains the correct svg', () => {
......
......@@ -17,11 +17,11 @@ describe('DevopsAdoptionSection', () => {
shallowMount(DevopsAdoptionSection, {
propsData: {
isLoading: false,
hasSegmentsData: true,
hasEnabledNamespaceData: true,
timestamp: '2020-10-31 23:59',
hasGroupData: true,
cols: DEVOPS_ADOPTION_TABLE_CONFIGURATION[0].cols,
segments: devopsAdoptionNamespaceData,
enabledNamespaces: devopsAdoptionNamespaceData,
disabledGroupNodes: groupNodes,
searchTerm: '',
isLoadingGroups: false,
......@@ -59,7 +59,7 @@ describe('DevopsAdoptionSection', () => {
});
});
describe('with segment data', () => {
describe('with enabledNamespace data', () => {
beforeEach(() => {
createComponent();
});
......@@ -81,9 +81,9 @@ describe('DevopsAdoptionSection', () => {
});
});
describe('with no segment data', () => {
describe('with no enabledNamespace data', () => {
beforeEach(() => {
createComponent({ hasSegmentsData: false });
createComponent({ hasEnabledNamespaceData: false });
});
it('displays an empty state', () => {
......
......@@ -21,7 +21,7 @@ describe('DevopsAdoptionTable', () => {
wrapper = mount(DevopsAdoptionTable, {
propsData: {
cols: DEVOPS_ADOPTION_TABLE_CONFIGURATION[0].cols,
segments: devopsAdoptionNamespaceData.nodes,
enabledNamespaces: devopsAdoptionNamespaceData.nodes,
},
provide,
directives: {
......@@ -100,15 +100,15 @@ describe('DevopsAdoptionTable', () => {
});
describe('table fields', () => {
describe('segment name', () => {
describe('enabled namespace name', () => {
beforeEach(() => {
createComponent();
});
it('displays the correct segment name', () => {
it('displays the correct name', () => {
createComponent();
expect(findCol(TEST_IDS.SEGMENT).text()).toBe('Group 1');
expect(findCol(TEST_IDS.NAMESPACE).text()).toBe('Group 1');
});
describe('"This group" badge', () => {
......@@ -122,7 +122,7 @@ describe('DevopsAdoptionTable', () => {
`('$scenario', ({ expected, provide }) => {
createComponent({ provide });
const badge = findColSubComponent(TEST_IDS.SEGMENT, GlBadge);
const badge = findColSubComponent(TEST_IDS.NAMESPACE, GlBadge);
expect(badge.exists()).toBe(expected);
});
......@@ -134,7 +134,7 @@ describe('DevopsAdoptionTable', () => {
});
it('grays the text out', () => {
const name = findColRowChild(TEST_IDS.SEGMENT, 1, 'span');
const name = findColRowChild(TEST_IDS.NAMESPACE, 1, 'span');
expect(name.classes()).toStrictEqual(['gl-text-gray-400']);
});
......@@ -143,7 +143,7 @@ describe('DevopsAdoptionTable', () => {
let icon;
beforeEach(() => {
icon = findColRowChild(TEST_IDS.SEGMENT, 1, GlIcon);
icon = findColRowChild(TEST_IDS.NAMESPACE, 1, GlIcon);
});
it('displays the icon', () => {
......@@ -198,7 +198,7 @@ describe('DevopsAdoptionTable', () => {
createComponent();
wrapper.setData({
selectedSegment: devopsAdoptionNamespaceData.nodes[0],
selectedNamespace: devopsAdoptionNamespaceData.nodes[0],
});
});
......@@ -217,14 +217,14 @@ describe('DevopsAdoptionTable', () => {
headers = findTable().findAll(`[data-testid="${TEST_IDS.TABLE_HEADERS}"]`);
});
it('sorts the segments by name', async () => {
expect(findCol(TEST_IDS.SEGMENT).text()).toBe('Group 1');
it('sorts the namespaces by name', async () => {
expect(findCol(TEST_IDS.NAMESPACE).text()).toBe('Group 1');
headers.at(0).trigger('click');
await nextTick();
expect(findCol(TEST_IDS.SEGMENT).text()).toBe('Group 2');
expect(findCol(TEST_IDS.NAMESPACE).text()).toBe('Group 2');
});
it('should update local storage when the sort column changes', async () => {
......
......@@ -95,8 +95,6 @@ export const devopsAdoptionTableHeaders = [
},
];
export const segmentName = 'Foooo';
export const genericErrorMessage = 'An error occurred while saving changes. Please try again.';
export const dataErrorMessage = 'Name already taken.';
......
import {
deleteSegmentsFromCache,
addSegmentsToCache,
deleteEnabledNamespacesFromCache,
addEnabledNamespacesToCache,
} from 'ee/analytics/devops_report/devops_adoption/utils/cache_updates';
import { devopsAdoptionNamespaceData } from '../mock_data';
describe('addSegmentsToCache', () => {
describe('addEnabledNamespacesToCache', () => {
const store = {
readQuery: jest.fn(() => ({ devopsAdoptionEnabledNamespaces: { nodes: [] } })),
writeQuery: jest.fn(),
};
it('calls writeQuery with the correct response', () => {
addSegmentsToCache(store, devopsAdoptionNamespaceData.nodes);
addEnabledNamespacesToCache(store, devopsAdoptionNamespaceData.nodes);
expect(store.writeQuery).toHaveBeenCalledWith(
expect.objectContaining({
......@@ -25,7 +25,7 @@ describe('addSegmentsToCache', () => {
});
});
describe('deleteSegmentsFromCache', () => {
describe('deleteEnabledNamespacesFromCache', () => {
const store = {
readQuery: jest.fn(() => ({ devopsAdoptionEnabledNamespaces: devopsAdoptionNamespaceData })),
writeQuery: jest.fn(),
......@@ -33,7 +33,7 @@ describe('deleteSegmentsFromCache', () => {
it('calls writeQuery with the correct response', () => {
// Remove the item at the first index
deleteSegmentsFromCache(store, [devopsAdoptionNamespaceData.nodes[0].id]);
deleteEnabledNamespacesFromCache(store, [devopsAdoptionNamespaceData.nodes[0].id]);
expect(store.writeQuery).toHaveBeenCalledWith(
expect.not.objectContaining({
......
......@@ -8,15 +8,15 @@ describe('shouldPollTableData', () => {
const previousDay = '2020-07-05T00:00:00.000Z';
it.each`
scenario | segments | timestamp | openModal | expected
${'no segment data'} | ${[]} | ${mockDate} | ${false} | ${true}
${'no timestamp'} | ${comepleteData} | ${null} | ${false} | ${true}
${'open modal'} | ${comepleteData} | ${mockDate} | ${true} | ${false}
${'segment data, timestamp is today, modal is closed'} | ${comepleteData} | ${mockDate} | ${false} | ${false}
${'segment data, timestamp is yesterday, modal is closed'} | ${comepleteData} | ${previousDay} | ${false} | ${true}
${'segment data, timestamp is today, modal is open'} | ${comepleteData} | ${mockDate} | ${true} | ${false}
${'pending segment data, timestamp is today, modal is closed'} | ${pendingData} | ${mockDate} | ${false} | ${true}
`('returns $expected when $scenario', ({ segments, timestamp, openModal, expected }) => {
expect(shouldPollTableData({ segments, timestamp, openModal })).toBe(expected);
scenario | enabledNamespaces | timestamp | openModal | expected
${'no namespaces data'} | ${[]} | ${mockDate} | ${false} | ${true}
${'no timestamp'} | ${comepleteData} | ${null} | ${false} | ${true}
${'open modal'} | ${comepleteData} | ${mockDate} | ${true} | ${false}
${'namespaces data, timestamp is today, modal is closed'} | ${comepleteData} | ${mockDate} | ${false} | ${false}
${'namespaces data, timestamp is yesterday, modal is closed'} | ${comepleteData} | ${previousDay} | ${false} | ${true}
${'namespaces data, timestamp is today, modal is open'} | ${comepleteData} | ${mockDate} | ${true} | ${false}
${'pending namespaces data, timestamp is today, modal is closed'} | ${pendingData} | ${mockDate} | ${false} | ${true}
`('returns $expected when $scenario', ({ enabledNamespaces, timestamp, openModal, expected }) => {
expect(shouldPollTableData({ enabledNamespaces, timestamp, openModal })).toBe(expected);
});
});
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