Commit b687e8dc authored by Miguel Rincon's avatar Miguel Rincon

Merge branch '321599-devops-adoption-add-this-group-badge-in-adoption-table' into 'master'

Resolve "[DevOps Adoption] Add "This group" badge in adoption table"

See merge request gitlab-org/gitlab!57689
parents 08e972e0 a2698aab
<script> <script>
import { GlTable, GlButton, GlModalDirective, GlTooltipDirective, GlIcon } from '@gitlab/ui'; import {
GlTable,
GlButton,
GlModalDirective,
GlTooltipDirective,
GlIcon,
GlBadge,
} from '@gitlab/ui';
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue'; import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
import { import {
DEVOPS_ADOPTION_TABLE_TEST_IDS, DEVOPS_ADOPTION_TABLE_TEST_IDS,
...@@ -58,6 +65,7 @@ export default { ...@@ -58,6 +65,7 @@ export default {
LocalStorageSync, LocalStorageSync,
DevopsAdoptionDeleteModal, DevopsAdoptionDeleteModal,
GlIcon, GlIcon,
GlBadge,
}, },
i18n, i18n,
devopsSegmentModalId: DEVOPS_ADOPTION_SEGMENT_MODAL_ID, devopsSegmentModalId: DEVOPS_ADOPTION_SEGMENT_MODAL_ID,
...@@ -66,6 +74,11 @@ export default { ...@@ -66,6 +74,11 @@ export default {
GlTooltip: GlTooltipDirective, GlTooltip: GlTooltipDirective,
GlModal: GlModalDirective, GlModal: GlModalDirective,
}, },
inject: {
groupGid: {
default: null,
},
},
tableHeaderFields: [ tableHeaderFields: [
...headers, ...headers,
{ {
...@@ -102,6 +115,9 @@ export default { ...@@ -102,6 +115,9 @@ export default {
slotName(key) { slotName(key) {
return `head(${key})`; return `head(${key})`;
}, },
isCurrentGroup(item) {
return item.namespace?.id === this.groupGid;
},
}, },
}; };
</script> </script>
...@@ -140,20 +156,16 @@ export default { ...@@ -140,20 +156,16 @@ export default {
</div> </div>
</template> </template>
<template <template #cell(name)="{ item }">
#cell(name)="{
item: {
namespace: { fullName },
latestSnapshot,
},
}"
>
<div :data-testid="$options.testids.SEGMENT"> <div :data-testid="$options.testids.SEGMENT">
<strong v-if="latestSnapshot">{{ fullName }}</strong> <strong v-if="item.latestSnapshot">{{ item.namespace.fullName }}</strong>
<template v-else> <template v-else>
<span class="gl-text-gray-400">{{ fullName }}</span> <span class="gl-text-gray-400">{{ item.namespace.fullName }}</span>
<gl-icon name="hourglass" class="gl-text-gray-400" /> <gl-icon name="hourglass" class="gl-text-gray-400" />
</template> </template>
<gl-badge v-if="isCurrentGroup(item)" class="gl-ml-1" variant="info">{{
__('This group')
}}</gl-badge>
</div> </div>
</template> </template>
......
import { GlTable, GlButton, GlIcon } from '@gitlab/ui'; import { GlTable, GlButton, GlIcon, GlBadge } from '@gitlab/ui';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import { nextTick } from 'vue'; import { nextTick } from 'vue';
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';
...@@ -12,12 +12,15 @@ import { devopsAdoptionSegmentsData, devopsAdoptionTableHeaders } from '../mock_ ...@@ -12,12 +12,15 @@ import { devopsAdoptionSegmentsData, devopsAdoptionTableHeaders } from '../mock_
describe('DevopsAdoptionTable', () => { describe('DevopsAdoptionTable', () => {
let wrapper; let wrapper;
const createComponent = () => { const createComponent = (options = {}) => {
const { provide = {} } = options;
wrapper = mount(DevopsAdoptionTable, { wrapper = mount(DevopsAdoptionTable, {
propsData: { propsData: {
segments: devopsAdoptionSegmentsData.nodes, segments: devopsAdoptionSegmentsData.nodes,
selectedSegment: devopsAdoptionSegmentsData.nodes[0], selectedSegment: devopsAdoptionSegmentsData.nodes[0],
}, },
provide,
directives: { directives: {
GlTooltip: createMockDirective(), GlTooltip: createMockDirective(),
}, },
...@@ -26,7 +29,6 @@ describe('DevopsAdoptionTable', () => { ...@@ -26,7 +29,6 @@ describe('DevopsAdoptionTable', () => {
beforeEach(() => { beforeEach(() => {
localStorage.clear(); localStorage.clear();
createComponent();
}); });
afterEach(() => { afterEach(() => {
...@@ -53,6 +55,7 @@ describe('DevopsAdoptionTable', () => { ...@@ -53,6 +55,7 @@ describe('DevopsAdoptionTable', () => {
let headers; let headers;
beforeEach(() => { beforeEach(() => {
createComponent();
headers = findTable().findAll(`[data-testid="${TEST_IDS.TABLE_HEADERS}"]`); headers = findTable().findAll(`[data-testid="${TEST_IDS.TABLE_HEADERS}"]`);
}); });
...@@ -97,10 +100,33 @@ describe('DevopsAdoptionTable', () => { ...@@ -97,10 +100,33 @@ describe('DevopsAdoptionTable', () => {
describe('table fields', () => { describe('table fields', () => {
describe('segment name', () => { describe('segment name', () => {
it('displays the correct segment name', () => { it('displays the correct segment name', () => {
createComponent();
expect(findCol(TEST_IDS.SEGMENT).text()).toBe('Group 1'); expect(findCol(TEST_IDS.SEGMENT).text()).toBe('Group 1');
}); });
describe('"This group" badge', () => {
const thisGroupGid = devopsAdoptionSegmentsData.nodes[0].namespace.id;
it.each`
scenario | expected | provide
${'is not shown by default'} | ${false} | ${null}
${'is not shown for other groups'} | ${false} | ${{ groupGid: 'anotherGroupGid' }}
${'is shown for the current group'} | ${true} | ${{ groupGid: thisGroupGid }}
`('$scenario', ({ expected, provide }) => {
createComponent({ provide });
const badge = findColSubComponent(TEST_IDS.SEGMENT, GlBadge);
expect(badge.exists()).toBe(expected);
});
});
describe('pending state (no snapshot data available)', () => { describe('pending state (no snapshot data available)', () => {
beforeEach(() => {
createComponent();
});
it('grays the text out', () => { it('grays the text out', () => {
const name = findColRowChild(TEST_IDS.SEGMENT, 1, 'span'); const name = findColRowChild(TEST_IDS.SEGMENT, 1, 'span');
...@@ -132,12 +158,16 @@ describe('DevopsAdoptionTable', () => { ...@@ -132,12 +158,16 @@ describe('DevopsAdoptionTable', () => {
${TEST_IDS.DEPLOYS} | ${'deploys'} | ${false} ${TEST_IDS.DEPLOYS} | ${'deploys'} | ${false}
${TEST_IDS.SCANNING} | ${'scanning'} | ${false} ${TEST_IDS.SCANNING} | ${'scanning'} | ${false}
`('displays the correct $field snapshot value', ({ id, flag }) => { `('displays the correct $field snapshot value', ({ id, flag }) => {
createComponent();
const booleanFlag = findColSubComponent(id, DevopsAdoptionTableCellFlag); const booleanFlag = findColSubComponent(id, DevopsAdoptionTableCellFlag);
expect(booleanFlag.props('enabled')).toBe(flag); expect(booleanFlag.props('enabled')).toBe(flag);
}); });
it('displays the actions icon', () => { it('displays the actions icon', () => {
createComponent();
const button = findColSubComponent(TEST_IDS.ACTIONS, GlButton); const button = findColSubComponent(TEST_IDS.ACTIONS, GlButton);
expect(button.exists()).toBe(true); expect(button.exists()).toBe(true);
...@@ -147,6 +177,10 @@ describe('DevopsAdoptionTable', () => { ...@@ -147,6 +177,10 @@ describe('DevopsAdoptionTable', () => {
}); });
describe('delete modal integration', () => { describe('delete modal integration', () => {
beforeEach(() => {
createComponent();
});
it('re emits trackModalOpenState with the given value', async () => { it('re emits trackModalOpenState with the given value', async () => {
findDeleteModal().vm.$emit('trackModalOpenState', true); findDeleteModal().vm.$emit('trackModalOpenState', true);
...@@ -158,6 +192,7 @@ describe('DevopsAdoptionTable', () => { ...@@ -158,6 +192,7 @@ describe('DevopsAdoptionTable', () => {
let headers; let headers;
beforeEach(() => { beforeEach(() => {
createComponent();
headers = findTable().findAll(`[data-testid="${TEST_IDS.TABLE_HEADERS}"]`); headers = findTable().findAll(`[data-testid="${TEST_IDS.TABLE_HEADERS}"]`);
}); });
......
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