Commit dfa76037 authored by Filipa Lacerda's avatar Filipa Lacerda

Fix broken icon + prevent page reload

parent 7038b4d6
...@@ -13,10 +13,6 @@ ...@@ -13,10 +13,6 @@
required: false, required: false,
default: () => ([]), default: () => ([]),
}, },
link: {
type: String,
required: true,
},
}, },
computed: { computed: {
sastText() { sastText() {
...@@ -36,7 +32,7 @@ ...@@ -36,7 +32,7 @@
return s__('ciReport|no security vulnerabilities'); return s__('ciReport|no security vulnerabilities');
}, },
statusIcon() { statusIcon() {
if (this.unresolvedIssues) { if (this.unresolvedIssues.length) {
return { return {
group: 'warning', group: 'warning',
icon: 'status_warning', icon: 'status_warning',
...@@ -69,13 +65,13 @@ ...@@ -69,13 +65,13 @@
class="prepend-left-10 flex flex-align-self-center" class="prepend-left-10 flex flex-align-self-center"
> >
{{ sastText }} {{ sastText }}
<a <button
:href="link" type="button"
class="prepend-left-5" class="btn-link btn-blank prepend-left-5"
@click="openTab" @click="openTab"
> >
{{ sastLink }} {{ sastLink }}
</a> </button>
</span> </span>
</div> </div>
</template> </template>
...@@ -89,9 +89,11 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -89,9 +89,11 @@ document.addEventListener('DOMContentLoaded', () => {
mediator.fetchSastReport(endpoint, blobPath) mediator.fetchSastReport(endpoint, blobPath)
.then(() => { .then(() => {
// update the badge // update the badge
const badge = document.querySelector('.js-sast-counter'); if (mediator.store.state.securityReports.sast.newIssues.length) {
badge.textContent = mediator.store.state.securityReports.sast.newIssues.length; const badge = document.querySelector('.js-sast-counter');
badge.classList.remove('hidden'); badge.textContent = mediator.store.state.securityReports.sast.newIssues.length;
badge.classList.remove('hidden');
}
}) })
.catch(() => { .catch(() => {
Flash(__('Something went wrong while fetching SAST.')); Flash(__('Something went wrong while fetching SAST.'));
...@@ -113,7 +115,6 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -113,7 +115,6 @@ document.addEventListener('DOMContentLoaded', () => {
return createElement('sast-summary-widget', { return createElement('sast-summary-widget', {
props: { props: {
unresolvedIssues: this.mediator.store.state.securityReports.sast.newIssues, unresolvedIssues: this.mediator.store.state.securityReports.sast.newIssues,
link: sastSummary.dataset.tabPath,
}, },
}); });
}, },
......
...@@ -19,26 +19,24 @@ describe('SAST report summary widget', () => { ...@@ -19,26 +19,24 @@ describe('SAST report summary widget', () => {
beforeEach(() => { beforeEach(() => {
vm = mountComponent(Component, { vm = mountComponent(Component, {
unresolvedIssues: parsedSastIssuesHead, unresolvedIssues: parsedSastIssuesHead,
link: 'group/project/pipelines/2/security',
}); });
}); });
it('renders summary text with link for the security tab', () => { it('renders summary text with warning icon', () => {
expect(vm.$el.textContent.trim().replace(/\s\s+/g, ' ')).toEqual('SAST degraded on 2 security vulnerabilities'); expect(vm.$el.textContent.trim().replace(/\s\s+/g, ' ')).toEqual('SAST degraded on 2 security vulnerabilities');
expect(vm.$el.querySelector('a').getAttribute('href')).toEqual('group/project/pipelines/2/security'); expect(vm.$el.querySelector('span').classList).toContain('ci-status-icon-warning');
}); });
}); });
describe('without vulnerabilities', () => { describe('without vulnerabilities', () => {
beforeEach(() => { beforeEach(() => {
vm = mountComponent(Component, { vm = mountComponent(Component, {
link: 'group/project/pipelines/2/security',
}); });
}); });
it('render summary text with link for the security tab', () => { it('render summary text with success icon', () => {
expect(vm.$el.textContent.trim().replace(/\s\s+/g, ' ')).toEqual('SAST detected no security vulnerabilities'); expect(vm.$el.textContent.trim().replace(/\s\s+/g, ' ')).toEqual('SAST detected no security vulnerabilities');
expect(vm.$el.querySelector('a').getAttribute('href')).toEqual('group/project/pipelines/2/security'); expect(vm.$el.querySelector('span').classList).toContain('ci-status-icon-success');
}); });
}); });
}); });
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