Skip to content
Snippets Groups Projects
Unverified Commit f73b2c8e authored by Phil Hughes's avatar Phil Hughes
Browse files

component specs

parent 2d6022e0
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -33,9 +33,6 @@ export default {
isScrolledToTop() {
return this.scrollPos === scrollPositions.top;
},
jobId() {
return `#${this.detailJob.id}`;
},
},
mounted() {
this.getTrace();
Loading
Loading
@@ -43,15 +40,15 @@ export default {
methods: {
...mapActions('pipelines', ['fetchJobTrace', 'setDetailJob']),
scrollDown() {
this.$refs.buildTrace.scrollTo(0, this.$refs.buildTrace.scrollHeight);
if (this.$refs.buildTrace)
this.$refs.buildTrace.scrollTo(0, this.$refs.buildTrace.scrollHeight);
},
scrollUp() {
this.$refs.buildTrace.scrollTo(0, 0);
if (this.$refs.buildTrace) this.$refs.buildTrace.scrollTo(0, 0);
},
scrollBuildLog: _.throttle(function buildLogScrollDebounce() {
const scrollTop = this.$refs.buildTrace.scrollTop;
const offsetHeight = this.$refs.buildTrace.offsetHeight;
const scrollHeight = this.$refs.buildTrace.scrollHeight;
const { scrollTop } = this.$refs.buildTrace;
const { offsetHeight, scrollHeight } = this.$refs.buildTrace;
 
if (scrollTop + offsetHeight === scrollHeight) {
this.scrollPos = scrollPositions.bottom;
Loading
Loading
import Vue from 'vue';
import Description from '~/ide/components/jobs/detail/description.vue';
import mountComponent from '../../../../helpers/vue_mount_component_helper';
import { jobs } from '../../../mock_data';
describe('IDE job description', () => {
const Component = Vue.extend(Description);
let vm;
beforeEach(() => {
vm = mountComponent(Component, {
job: jobs[0],
});
});
afterEach(() => {
vm.$destroy();
});
it('renders job details', () => {
expect(vm.$el.textContent).toContain('#1');
expect(vm.$el.textContent).toContain('test');
});
it('renders CI icon', () => {
expect(vm.$el.querySelector('.ci-status-icon .ic-status_passed_borderless')).not.toBe(null);
});
});
import Vue from 'vue';
import ScrollButton from '~/ide/components/jobs/detail/scroll_button.vue';
import mountComponent from '../../../../helpers/vue_mount_component_helper';
describe('IDE job log scroll button', () => {
const Component = Vue.extend(ScrollButton);
let vm;
beforeEach(() => {
vm = mountComponent(Component, {
direction: 'up',
disabled: false,
});
});
afterEach(() => {
vm.$destroy();
});
describe('iconName', () => {
['up', 'down'].forEach(direction => {
it(`returns icon name for ${direction}`, () => {
vm.direction = direction;
expect(vm.iconName).toBe(`scroll_${direction}`);
});
});
});
describe('tooltipTitle', () => {
it('returns title for up', () => {
expect(vm.tooltipTitle).toBe('Scroll to top');
});
it('returns title for down', () => {
vm.direction = 'down';
expect(vm.tooltipTitle).toBe('Scroll to bottom');
});
});
it('emits click event on click', () => {
spyOn(vm, '$emit');
vm.$el.querySelector('.btn-scroll').click();
expect(vm.$emit).toHaveBeenCalledWith('click');
});
it('disables button when disabled is true', done => {
vm.disabled = true;
vm.$nextTick(() => {
expect(vm.$el.querySelector('.btn-scroll').hasAttribute('disabled')).toBe(true);
done();
});
});
});
import Vue from 'vue';
import JobDetail from '~/ide/components/jobs/detail.vue';
import { createStore } from '~/ide/stores';
import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper';
import { jobs } from '../../mock_data';
describe('IDE jobs detail view', () => {
const Component = Vue.extend(JobDetail);
let vm;
beforeEach(() => {
const store = createStore();
store.state.pipelines.detailJob = {
...jobs[0],
isLoading: true,
output: 'testing',
rawPath: `${gl.TEST_HOST}/raw`,
};
vm = createComponentWithStore(Component, store);
spyOn(vm, 'fetchJobTrace').and.returnValue(Promise.resolve());
vm = vm.$mount();
spyOn(vm.$refs.buildTrace, 'scrollTo');
});
afterEach(() => {
vm.$destroy();
});
it('calls fetchJobTrace on mount', () => {
expect(vm.fetchJobTrace).toHaveBeenCalled();
});
it('scrolls to bottom on mount', done => {
setTimeout(() => {
expect(vm.$refs.buildTrace.scrollTo).toHaveBeenCalled();
done();
});
});
it('renders job output', () => {
expect(vm.$el.querySelector('.bash').textContent).toContain('testing');
});
it('renders loading icon', () => {
expect(vm.$el.querySelector('.build-loader-animation')).not.toBe(null);
expect(vm.$el.querySelector('.build-loader-animation').style.display).toBe('');
});
it('hide loading icon when isLoading is false', done => {
vm.$store.state.pipelines.detailJob.isLoading = false;
vm.$nextTick(() => {
expect(vm.$el.querySelector('.build-loader-animation').style.display).toBe('none');
done();
});
});
it('resets detailJob when clicking header button', () => {
spyOn(vm, 'setDetailJob');
vm.$el.querySelector('.btn').click();
expect(vm.setDetailJob).toHaveBeenCalledWith(null);
});
it('renders raw path link', () => {
expect(vm.$el.querySelector('.controllers-buttons').getAttribute('href')).toBe(
`${gl.TEST_HOST}/raw`,
);
});
describe('scroll buttons', () => {
it('triggers scrollDown when clicking down button', done => {
spyOn(vm, 'scrollDown');
vm.$el.querySelectorAll('.btn-scroll')[1].click();
vm.$nextTick(() => {
expect(vm.scrollDown).toHaveBeenCalled();
done();
});
});
it('triggers scrollUp when clicking up button', done => {
spyOn(vm, 'scrollUp');
vm.scrollPos = 1;
vm
.$nextTick()
.then(() => vm.$el.querySelector('.btn-scroll').click())
.then(() => vm.$nextTick())
.then(() => {
expect(vm.scrollUp).toHaveBeenCalled();
})
.then(done)
.catch(done.fail);
});
});
describe('scrollDown', () => {
it('scrolls build trace to bottom', () => {
spyOnProperty(vm.$refs.buildTrace, 'scrollHeight').and.returnValue(1000);
vm.scrollDown();
expect(vm.$refs.buildTrace.scrollTo).toHaveBeenCalledWith(0, 1000);
});
});
describe('scrollUp', () => {
it('scrolls build trace to top', () => {
vm.scrollUp();
expect(vm.$refs.buildTrace.scrollTo).toHaveBeenCalledWith(0, 0);
});
});
describe('scrollBuildLog', () => {
beforeEach(() => {
spyOnProperty(vm.$refs.buildTrace, 'offsetHeight').and.returnValue(100);
spyOnProperty(vm.$refs.buildTrace, 'scrollHeight').and.returnValue(200);
});
it('sets scrollPos to bottom when at the bottom', done => {
spyOnProperty(vm.$refs.buildTrace, 'scrollTop').and.returnValue(100);
vm.scrollBuildLog();
setTimeout(() => {
expect(vm.scrollPos).toBe(1);
done();
});
});
it('sets scrollPos to top when at the top', done => {
spyOnProperty(vm.$refs.buildTrace, 'scrollTop').and.returnValue(0);
vm.scrollPos = 1;
vm.scrollBuildLog();
setTimeout(() => {
expect(vm.scrollPos).toBe(0);
done();
});
});
it('resets scrollPos when not at top or bottom', done => {
spyOnProperty(vm.$refs.buildTrace, 'scrollTop').and.returnValue(10);
vm.scrollBuildLog();
setTimeout(() => {
expect(vm.scrollPos).toBe('');
done();
});
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment