Skip to content
代码片段 群组 项目
提交 cb549e15 编辑于 作者: Natalia Tepluhina's avatar Natalia Tepluhina
浏览文件

Merge branch 'jlouw-update-compliance-labels-to-use-shared-component' into 'master'

Update compliance labels to use shared component

See merge request gitlab-org/gitlab!90606
No related branches found
No related tags found
无相关合并请求
显示
36 个添加96 个删除
...@@ -4,6 +4,7 @@ import { ...@@ -4,6 +4,7 @@ import {
GlLoadingIcon, GlLoadingIcon,
GlBadge, GlBadge,
GlIcon, GlIcon,
GlLabel,
GlTooltipDirective, GlTooltipDirective,
GlSafeHtmlDirective, GlSafeHtmlDirective,
} from '@gitlab/ui'; } from '@gitlab/ui';
...@@ -28,11 +29,8 @@ export default { ...@@ -28,11 +29,8 @@ export default {
GlBadge, GlBadge,
GlLoadingIcon, GlLoadingIcon,
GlIcon, GlIcon,
GlLabel,
UserAccessRoleBadge, UserAccessRoleBadge,
ComplianceFrameworkLabel: () =>
import(
'ee_component/vue_shared/components/compliance_framework_label/compliance_framework_label.vue'
),
itemCaret, itemCaret,
itemTypeIcon, itemTypeIcon,
itemActions, itemActions,
...@@ -184,12 +182,13 @@ export default { ...@@ -184,12 +182,13 @@ export default {
<user-access-role-badge v-if="group.permission" class="gl-mt-3"> <user-access-role-badge v-if="group.permission" class="gl-mt-3">
{{ group.permission }} {{ group.permission }}
</user-access-role-badge> </user-access-role-badge>
<compliance-framework-label <gl-label
v-if="hasComplianceFramework" v-if="hasComplianceFramework"
class="gl-mt-3" class="gl-mt-3"
:name="complianceFramework.name" :title="complianceFramework.name"
:color="complianceFramework.color" :background-color="complianceFramework.color"
:description="complianceFramework.description" :description="complianceFramework.description"
size="sm"
/> />
</div> </div>
<div v-if="group.description" class="description"> <div v-if="group.description" class="description">
......
<script> <script>
import { GlAvatarLabeled, GlAvatarLink } from '@gitlab/ui'; import { GlAvatarLabeled, GlAvatarLink, GlLabel } from '@gitlab/ui';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import ComplianceFrameworkLabel from 'ee/vue_shared/components/compliance_framework_label/compliance_framework_label.vue';
import { __ } from '~/locale'; import { __ } from '~/locale';
import { DRAWER_AVATAR_SIZE } from '../../constants'; import { DRAWER_AVATAR_SIZE } from '../../constants';
import DrawerSectionHeader from '../shared/drawer_section_header.vue'; import DrawerSectionHeader from '../shared/drawer_section_header.vue';
export default { export default {
components: { components: {
ComplianceFrameworkLabel,
DrawerSectionHeader, DrawerSectionHeader,
GlAvatarLabeled, GlAvatarLabeled,
GlAvatarLink, GlAvatarLink,
GlLabel,
}, },
props: { props: {
avatarUrl: { avatarUrl: {
...@@ -57,12 +56,13 @@ export default { ...@@ -57,12 +56,13 @@ export default {
:src="avatarUrl" :src="avatarUrl"
/> />
</gl-avatar-link> </gl-avatar-link>
<compliance-framework-label <gl-label
v-if="hasComplianceFramework" v-if="hasComplianceFramework"
class="gl-ml-3" class="gl-ml-3"
:name="complianceFramework.name" :title="complianceFramework.name"
:color="complianceFramework.color" :background-color="complianceFramework.color"
:description="complianceFramework.description" :description="complianceFramework.description"
size="sm"
/> />
</div> </div>
</div> </div>
......
<script> <script>
import { GlLabel, GlButton, GlTooltipDirective } from '@gitlab/ui'; import { GlButton, GlTooltipDirective, GlLabel } from '@gitlab/ui';
import { DELETE_BUTTON_LABEL, EDIT_BUTTON_LABEL } from '../constants'; import { DELETE_BUTTON_LABEL, EDIT_BUTTON_LABEL } from '../constants';
export default { export default {
...@@ -32,11 +32,11 @@ export default { ...@@ -32,11 +32,11 @@ export default {
> >
<div class="gl-w-quarter gl-mr-3 gl-flex-shrink-0"> <div class="gl-w-quarter gl-mr-3 gl-flex-shrink-0">
<gl-label <gl-label
:target="framework.editPath"
:background-color="framework.color" :background-color="framework.color"
:title="framework.name"
:description="$options.i18n.editFramework" :description="$options.i18n.editFramework"
:disabled="loading" :disabled="loading"
:title="framework.name"
:target="framework.editPath"
/> />
</div> </div>
<p class="gl-w-full gl-m-0!" data-testid="compliance-framework-description"> <p class="gl-w-full gl-m-0!" data-testid="compliance-framework-description">
......
<script>
import { GlLabel } from '@gitlab/ui';
import { validateHexColor } from '~/lib/utils/color_utils';
export default {
components: {
GlLabel,
},
props: {
color: {
type: String,
required: true,
validator: (color) => validateHexColor(color),
},
description: {
type: String,
required: true,
},
name: {
type: String,
required: true,
},
},
};
</script>
<template>
<gl-label size="sm" :background-color="color" :title="name" :description="description" />
</template>
import { GlAvatarLabeled, GlAvatarLink } from '@gitlab/ui'; import { GlAvatarLabeled, GlAvatarLink, GlLabel } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Project from 'ee/compliance_dashboard/components/drawer_sections/project.vue'; import Project from 'ee/compliance_dashboard/components/drawer_sections/project.vue';
import DrawerSectionHeader from 'ee/compliance_dashboard/components/shared/drawer_section_header.vue'; import DrawerSectionHeader from 'ee/compliance_dashboard/components/shared/drawer_section_header.vue';
import ComplianceFrameworkLabel from 'ee/vue_shared/components/compliance_framework_label/compliance_framework_label.vue'; import { complianceFramework } from '../../mock_data';
import { complianceFramework } from 'ee_jest/vue_shared/components/compliance_framework_label/mock_data';
describe('Project component', () => { describe('Project component', () => {
let wrapper; let wrapper;
...@@ -14,7 +13,7 @@ describe('Project component', () => { ...@@ -14,7 +13,7 @@ describe('Project component', () => {
const findSectionHeader = () => wrapper.findComponent(DrawerSectionHeader); const findSectionHeader = () => wrapper.findComponent(DrawerSectionHeader);
const findAvatarLink = () => wrapper.findComponent(GlAvatarLink); const findAvatarLink = () => wrapper.findComponent(GlAvatarLink);
const findAvatarLabel = () => wrapper.findComponent(GlAvatarLabeled); const findAvatarLabel = () => wrapper.findComponent(GlAvatarLabeled);
const findComplianceFrameworkLabel = () => wrapper.findComponent(ComplianceFrameworkLabel); const findComplianceFrameworkLabel = () => wrapper.findComponent(GlLabel);
const createComponent = (props) => { const createComponent = (props) => {
return shallowMount(Project, { return shallowMount(Project, {
...@@ -86,10 +85,11 @@ describe('Project component', () => { ...@@ -86,10 +85,11 @@ describe('Project component', () => {
it('renders the compliance framework label', () => { it('renders the compliance framework label', () => {
const { color, description, name } = complianceFramework; const { color, description, name } = complianceFramework;
expect(findComplianceFrameworkLabel().props()).toStrictEqual({ expect(findComplianceFrameworkLabel().props()).toMatchObject({
color, backgroundColor: color,
description, description,
name, title: name,
size: 'sm',
}); });
}); });
}); });
......
...@@ -112,3 +112,9 @@ export const createComplianceViolationsResponse = ({ count = 1, pageInfo = {} } ...@@ -112,3 +112,9 @@ export const createComplianceViolationsResponse = ({ count = 1, pageInfo = {} }
}, },
}, },
}); });
export const complianceFramework = {
color: '#009966',
description: 'General Data Protection Regulation',
name: 'GDPR',
};
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import ComplianceFrameworkLabel from 'ee_component/vue_shared/components/compliance_framework_label/compliance_framework_label.vue'; import { GlLabel } from '@gitlab/ui';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import GroupFolder from '~/groups/components/group_folder.vue'; import GroupFolder from '~/groups/components/group_folder.vue';
import GroupItem from '~/groups/components/group_item.vue'; import GroupItem from '~/groups/components/group_item.vue';
...@@ -18,7 +18,7 @@ const createComponent = (props = {}) => { ...@@ -18,7 +18,7 @@ const createComponent = (props = {}) => {
describe('GroupItemComponent', () => { describe('GroupItemComponent', () => {
let wrapper; let wrapper;
const findComplianceFrameworkLabel = () => wrapper.findComponent(ComplianceFrameworkLabel); const findComplianceFrameworkLabel = () => wrapper.findComponent(GlLabel);
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
...@@ -38,10 +38,11 @@ describe('GroupItemComponent', () => { ...@@ -38,10 +38,11 @@ describe('GroupItemComponent', () => {
wrapper = createComponent({ group: mockChildren[1] }); wrapper = createComponent({ group: mockChildren[1] });
await waitForPromises(); await waitForPromises();
expect(findComplianceFrameworkLabel().props()).toStrictEqual({ expect(findComplianceFrameworkLabel().props()).toMatchObject({
color, backgroundColor: color,
description, description,
name, title: name,
size: 'sm',
}); });
}); });
}); });
......
import { GlLabel } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlLabel } from '@gitlab/ui';
import ListItem from 'ee/groups/settings/compliance_frameworks/components/list_item.vue'; import ListItem from 'ee/groups/settings/compliance_frameworks/components/list_item.vue';
import { import {
DELETE_BUTTON_LABEL, DELETE_BUTTON_LABEL,
...@@ -71,6 +70,7 @@ describe('ListItem', () => { ...@@ -71,6 +70,7 @@ describe('ListItem', () => {
expect(findLabel().props()).toMatchObject({ expect(findLabel().props()).toMatchObject({
title: framework.name, title: framework.name,
backgroundColor: framework.color,
target: framework.editPath, target: framework.editPath,
disabled: false, disabled: false,
description: 'Edit framework', description: 'Edit framework',
......
import { GlLabel } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import ComplianceFrameworkLabel from 'ee/vue_shared/components/compliance_framework_label/compliance_framework_label.vue';
import { complianceFramework } from './mock_data';
describe('ComplianceFrameworkLabel component', () => {
let wrapper;
const propsData = { ...complianceFramework };
const findLabel = () => wrapper.findComponent(GlLabel);
beforeEach(() => {
wrapper = shallowMount(ComplianceFrameworkLabel, {
propsData,
});
});
afterEach(() => {
wrapper.destroy();
});
it('has the correct props', () => {
const { color: backgroundColor, description, name: title } = propsData;
expect(findLabel().props()).toMatchObject({
backgroundColor,
description,
size: 'sm',
title,
});
});
});
export const complianceFramework = {
color: '#009966',
description: 'General Data Protection Regulation',
name: 'GDPR',
};
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册