Skip to content
代码片段 群组 项目
提交 130adb91 编辑于 作者: Samantha Ming's avatar Samantha Ming
浏览文件

Merge branch 'show-loading-icon-in-status-badge' into 'master'

Show loading icon in vulnerability status badge

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/135804



Merged-by: default avatarSamantha Ming <sming@gitlab.com>
Approved-by: default avatarSamantha Ming <sming@gitlab.com>
Approved-by: default avatarBecka Lippert <rlippert@gitlab.com>
Reviewed-by: default avatarDavid Pisek <dpisek@gitlab.com>
Co-authored-by: default avatarDavid Pisek <dpisek@gitlab.com>
Co-authored-by: default avatarlorenzvanherwaarden <lvanherwaarden@gitlab.com>
No related branches found
No related tags found
无相关合并请求
<script> <script>
import { GlBadge } from '@gitlab/ui'; import { GlBadge, GlLoadingIcon } from '@gitlab/ui';
import { VULNERABILITY_STATES } from 'ee/vulnerabilities/constants'; import { VULNERABILITY_STATES } from 'ee/vulnerabilities/constants';
...@@ -13,6 +13,7 @@ export const VARIANTS = { ...@@ -13,6 +13,7 @@ export const VARIANTS = {
export default { export default {
components: { components: {
GlBadge, GlBadge,
GlLoadingIcon,
}, },
props: { props: {
state: { state: {
...@@ -20,6 +21,11 @@ export default { ...@@ -20,6 +21,11 @@ export default {
required: true, required: true,
validator: (state) => Object.keys(VARIANTS).includes(state), validator: (state) => Object.keys(VARIANTS).includes(state),
}, },
loading: {
type: Boolean,
required: false,
default: false,
},
}, },
computed: { computed: {
stateName() { stateName() {
...@@ -34,6 +40,7 @@ export default { ...@@ -34,6 +40,7 @@ export default {
<template> <template>
<gl-badge :variant="stateVariant"> <gl-badge :variant="stateVariant">
{{ stateName }} <gl-loading-icon v-if="loading" size="sm" class="gl-mx-5" />
<template v-else>{{ stateName }}</template>
</gl-badge> </gl-badge>
</template> </template>
...@@ -218,8 +218,11 @@ export default { ...@@ -218,8 +218,11 @@ export default {
/> />
<div class="detail-page-header"> <div class="detail-page-header">
<div class="detail-page-header-body" data-testid="vulnerability-detail-body"> <div class="detail-page-header-body" data-testid="vulnerability-detail-body">
<gl-loading-icon v-if="isLoadingVulnerability" size="sm" class="gl-mr-3" /> <status-badge
<status-badge v-else :state="vulnerability.state" class="gl-mr-3" /> :state="vulnerability.state"
:loading="isLoadingVulnerability"
class="gl-mr-3"
/>
<status-description <status-description
:vulnerability="vulnerability" :vulnerability="vulnerability"
:user="user" :user="user"
......
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import { GlBadge } from '@gitlab/ui'; import { GlBadge, GlLoadingIcon } from '@gitlab/ui';
import StatusBadge, { VARIANTS } from 'ee/vue_shared/security_reports/components/status_badge.vue'; import StatusBadge, { VARIANTS } from 'ee/vue_shared/security_reports/components/status_badge.vue';
import { VULNERABILITY_STATES } from 'ee/vulnerabilities/constants'; import { VULNERABILITY_STATES } from 'ee/vulnerabilities/constants';
import { assertProps } from 'helpers/assert_props'; import { assertProps } from 'helpers/assert_props';
...@@ -8,11 +8,13 @@ describe('StatusBadge', () => { ...@@ -8,11 +8,13 @@ describe('StatusBadge', () => {
let wrapper; let wrapper;
const findBadge = () => wrapper.findComponent(GlBadge); const findBadge = () => wrapper.findComponent(GlBadge);
const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
const createWrapper = (state) => { const createWrapper = ({ state, loading }) => {
wrapper = mount(StatusBadge, { wrapper = mount(StatusBadge, {
propsData: { propsData: {
state, state,
loading,
}, },
}); });
}; };
...@@ -20,7 +22,7 @@ describe('StatusBadge', () => { ...@@ -20,7 +22,7 @@ describe('StatusBadge', () => {
it.each(Object.entries(VARIANTS))( it.each(Object.entries(VARIANTS))(
'the vulnerability state badge has the correct style for the %s state', 'the vulnerability state badge has the correct style for the %s state',
(state, variant) => { (state, variant) => {
createWrapper(state); createWrapper({ state });
const badge = findBadge(); const badge = findBadge();
expect(badge.props('variant')).toBe(variant); expect(badge.props('variant')).toBe(variant);
...@@ -33,4 +35,10 @@ describe('StatusBadge', () => { ...@@ -33,4 +35,10 @@ describe('StatusBadge', () => {
assertProps(StatusBadge, { state: 'invalid-prop' }); assertProps(StatusBadge, { state: 'invalid-prop' });
}).toThrow('Invalid prop: custom validator check failed for prop'); }).toThrow('Invalid prop: custom validator check failed for prop');
}); });
it.each([true, false])('renders the loading icon: "%s"', (loading) => {
createWrapper({ state: 'detected', loading });
expect(findLoadingIcon().exists()).toBe(loading);
});
}); });
...@@ -134,12 +134,12 @@ describe('Vulnerability Header', () => { ...@@ -134,12 +134,12 @@ describe('Vulnerability Header', () => {
createWrapper({ apolloProvider }); createWrapper({ apolloProvider });
}); });
it('shows the loading spinner but not the status badge', async () => { it('shows the loading icon and passes the correct "loading" prop to the status badge', async () => {
changeStatus(action); changeStatus(action);
await nextTick(); await nextTick();
expect(findGlLoadingIcon().exists()).toBe(true); expect(findGlLoadingIcon().exists()).toBe(true);
expect(findStatusBadge().exists()).toBe(false); expect(findStatusBadge().props('loading')).toBe(true);
}); });
it(`emits the updated vulnerability properly - ${action}`, async () => { it(`emits the updated vulnerability properly - ${action}`, async () => {
...@@ -158,12 +158,12 @@ describe('Vulnerability Header', () => { ...@@ -158,12 +158,12 @@ describe('Vulnerability Header', () => {
expect(wrapper.emitted()['vulnerability-state-change']).toHaveLength(1); expect(wrapper.emitted()['vulnerability-state-change']).toHaveLength(1);
}); });
it('hides the loading spinner and shows the status badge', async () => { it('does not show the loading icon and passes the correct "loading" prop to the status badge', async () => {
changeStatus(action); changeStatus(action);
await waitForPromises(); await waitForPromises();
expect(findGlLoadingIcon().exists()).toBe(false); expect(findGlLoadingIcon().exists()).toBe(false);
expect(findStatusBadge().exists()).toBe(true); expect(findStatusBadge().props('loading')).toBe(false);
}); });
}); });
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册