Commit 2b36c841 authored by Filipa Lacerda's avatar Filipa Lacerda

Moves terminal button into Vue.

Updates permission checks to use paths instead - backend already handles permissions
parent ab44f531
<script>
import detailRow from './sidebar_detail_row.vue';
import loadingIcon from '../../vue_shared/components/loading_icon.vue';
import timeagoMixin from '../../vue_shared/mixins/timeago';
import { timeIntervalInWords } from '../../lib/utils/datetime_utility';
import LoadingIcon from '~/vue_shared/components/loading_icon.vue';
import timeagoMixin from '~/vue_shared/mixins/timeago';
import { timeIntervalInWords } from '~/lib/utils/datetime_utility';
import Icon from '~/vue_shared/components/icon.vue';
import DetailRow from './sidebar_detail_row.vue';
export default {
name: 'SidebarDetailsBlock',
components: {
detailRow,
loadingIcon,
DetailRow,
LoadingIcon,
Icon,
},
mixins: [timeagoMixin],
props: {
......@@ -20,16 +22,16 @@ export default {
type: Boolean,
required: true,
},
canUserRetry: {
type: Boolean,
required: false,
default: false,
},
runnerHelpUrl: {
type: String,
required: false,
default: '',
},
terminalPath: {
type: String,
required: false,
default: null,
},
},
computed: {
shouldRenderContent() {
......@@ -92,7 +94,7 @@ export default {
{{ job.name }}
</strong>
<a
v-if="canUserRetry"
v-if="job.retry_path"
:class="retryButtonClass"
:href="job.retry_path"
data-method="post"
......@@ -100,6 +102,16 @@ export default {
>
{{ __('Retry') }}
</a>
<a
v-if="terminalPath"
:href="terminalPath"
class="js-terminal-link pull-right btn btn-primary
btn-inverted visible-md-block visible-lg-block"
target="_blank"
>
{{ __('Debug') }}
<icon name="external-link" />
</a>
<button
:aria-label="__('Toggle Sidebar')"
type="button"
......@@ -125,7 +137,7 @@ export default {
{{ __('New issue') }}
</a>
<a
v-if="canUserRetry"
v-if="job.retry_path"
:href="job.retry_path"
class="js-retry-job btn btn-inverted-secondary"
data-method="post"
......
......@@ -52,9 +52,9 @@ export default () => {
return createElement('details-block', {
props: {
isLoading: this.mediator.state.isLoading,
canUserRetry: !!('canUserRetry' in detailsBlockDataset),
job: this.mediator.store.state.job,
runnerHelpUrl: dataset.runnerHelpUrl,
terminalPath: detailsBlockDataset.terminalPath,
},
});
},
......
%aside.right-sidebar.right-sidebar-expanded.build-sidebar.js-build-sidebar.js-right-sidebar{ data: { "offset-top" => "101", "spy" => "affix" } }
.sidebar-container
.blocks-container
- if can?(current_user, :create_build_terminal, @build)
.block
= link_to terminal_project_job_path(@project, @build), class: 'pull-right btn btn-primary btn-inverted visible-md-block visible-lg-block', target: '_blank' do
Debug
= icon('external-link')
#js-details-block-vue{ data: { can_user_retry: can?(current_user, :update_build, @build) && @build.retryable? } }
#js-details-block-vue{ data: { terminal_path: can?(current_user, :create_build_terminal, @build) && @build.has_terminal? ? terminal_project_job_path(@project, @build) : nil } }
- if can?(current_user, :read_build, @project) && (@build.artifacts? || @build.artifacts_expired?)
.block
......
import Vue from 'vue';
import sidebarDetailsBlock from '~/jobs/components/sidebar_details_block.vue';
import job from './mock_data';
import mountComponent from '../helpers/vue_mount_component_helper';
describe('Sidebar details block', () => {
let SidebarComponent;
......@@ -20,39 +21,53 @@ describe('Sidebar details block', () => {
describe('when it is loading', () => {
it('should render a loading spinner', () => {
vm = new SidebarComponent({
propsData: {
vm = mountComponent(SidebarComponent, {
job: {},
isLoading: true,
},
}).$mount();
});
expect(vm.$el.querySelector('.fa-spinner')).toBeDefined();
});
});
describe("when user can't retry", () => {
describe('when there is no retry path retry', () => {
it('should not render a retry button', () => {
vm = new SidebarComponent({
propsData: {
vm = mountComponent(SidebarComponent, {
job: {},
canUserRetry: false,
isLoading: true,
},
}).$mount();
isLoading: false,
});
expect(vm.$el.querySelector('.js-retry-job')).toBeNull();
});
});
describe('without terminal path', () => {
it('does not render terminal link', () => {
vm = mountComponent(SidebarComponent, {
job,
isLoading: false,
});
expect(vm.$el.querySelector('.js-terminal-link')).toBeNull();
});
});
describe('with terminal path', () => {
it('renders terminal link', () => {
vm = mountComponent(SidebarComponent, {
job,
isLoading: false,
terminalPath: 'job/43123/terminal',
});
expect(vm.$el.querySelector('.js-terminal-link')).not.toBeNull();
});
});
beforeEach(() => {
vm = new SidebarComponent({
propsData: {
vm = mountComponent(SidebarComponent, {
job,
canUserRetry: true,
isLoading: false,
},
}).$mount();
});
});
describe('actions', () => {
......@@ -102,13 +117,15 @@ describe('Sidebar details block', () => {
});
it('should render runner ID', () => {
expect(trimWhitespace(vm.$el.querySelector('.js-job-runner'))).toEqual('Runner: local ci runner (#1)');
expect(trimWhitespace(vm.$el.querySelector('.js-job-runner'))).toEqual(
'Runner: local ci runner (#1)',
);
});
it('should render timeout information', () => {
expect(
trimWhitespace(vm.$el.querySelector('.js-job-timeout')),
).toEqual('Timeout: 1m 40s (from runner)');
expect(trimWhitespace(vm.$el.querySelector('.js-job-timeout'))).toEqual(
'Timeout: 1m 40s (from runner)',
);
});
it('should render coverage', () => {
......
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