1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
import { nextTick } from 'vue';
import { mount } from '@vue/test-utils';
import { TEST_HOST } from 'helpers/test_constants';
import JobDetail from '~/ide/components/jobs/detail.vue';
import { createStore } from '~/ide/stores';
import { jobs } from '../../mock_data';
describe('IDE jobs detail view', () => {
let wrapper;
let store;
const createComponent = () => {
store = createStore();
store.state.pipelines.detailJob = {
...jobs[0],
isLoading: true,
output: 'testing',
rawPath: `${TEST_HOST}/raw`,
};
jest.spyOn(store, 'dispatch');
store.dispatch.mockResolvedValue();
wrapper = mount(JobDetail, { store });
};
const findBuildJobLog = () => wrapper.find('pre');
const findScrollToBottomButton = () => wrapper.find('button[aria-label="Scroll to bottom"]');
const findScrollToTopButton = () => wrapper.find('button[aria-label="Scroll to top"]');
beforeEach(() => {
createComponent();
});
describe('mounted', () => {
const findJobOutput = () => wrapper.find('.bash');
const findBuildLoaderAnimation = () => wrapper.find('.build-loader-animation');
it('calls fetchJobLogs', () => {
expect(store.dispatch).toHaveBeenCalledWith('pipelines/fetchJobLogs', undefined);
});
it('scrolls to bottom', () => {
expect(findBuildJobLog().element.scrollTo).toHaveBeenCalled();
});
it('renders job output', () => {
expect(findJobOutput().text()).toContain('testing');
});
it('renders empty message output', async () => {
store.state.pipelines.detailJob.output = '';
await nextTick();
expect(findJobOutput().text()).toContain('No messages were logged');
});
it('renders loading icon', () => {
expect(findBuildLoaderAnimation().exists()).toBe(true);
expect(findBuildLoaderAnimation().isVisible()).toBe(true);
});
it('hides output when loading', () => {
expect(findJobOutput().exists()).toBe(true);
expect(findJobOutput().isVisible()).toBe(false);
});
it('hide loading icon when isLoading is false', async () => {
store.state.pipelines.detailJob.isLoading = false;
await nextTick();
expect(findBuildLoaderAnimation().isVisible()).toBe(false);
});
it('resets detailJob when clicking header button', async () => {
await wrapper.find('.btn').trigger('click');
expect(store.dispatch).toHaveBeenCalledWith('pipelines/setDetailJob', null);
});
it('renders raw path link', () => {
expect(wrapper.find('.controllers-buttons').attributes('href')).toBe(`${TEST_HOST}/raw`);
});
});
describe('scroll buttons', () => {
beforeEach(() => {
createComponent();
});
it.each`
fnName | btnName | scrollPos | targetScrollPos
${'scroll down'} | ${'down'} | ${0} | ${200}
${'scroll up'} | ${'up'} | ${200} | ${0}
`('triggers $fnName when clicking $btnName button', async ({ scrollPos, targetScrollPos }) => {
jest.spyOn(findBuildJobLog().element, 'offsetHeight', 'get').mockReturnValue(0);
jest.spyOn(findBuildJobLog().element, 'scrollHeight', 'get').mockReturnValue(200);
jest.spyOn(findBuildJobLog().element, 'scrollTop', 'get').mockReturnValue(scrollPos);
findBuildJobLog().element.scrollTo.mockReset();
await findBuildJobLog().trigger('scroll'); // trigger button updates
await wrapper.find('.controllers button:not(:disabled)').trigger('click');
expect(findBuildJobLog().element.scrollTo).toHaveBeenCalledWith(0, targetScrollPos);
});
});
describe('scrolling build log', () => {
beforeEach(() => {
jest.spyOn(findBuildJobLog().element, 'offsetHeight', 'get').mockReturnValue(100);
jest.spyOn(findBuildJobLog().element, 'scrollHeight', 'get').mockReturnValue(200);
});
it('keeps scroll at bottom when already at the bottom', async () => {
jest.spyOn(findBuildJobLog().element, 'scrollTop', 'get').mockReturnValue(100);
await findBuildJobLog().trigger('scroll');
expect(findScrollToBottomButton().attributes('disabled')).toBeDefined();
expect(findScrollToTopButton().attributes('disabled')).toBeUndefined();
});
it('keeps scroll at top when already at top', async () => {
jest.spyOn(findBuildJobLog().element, 'scrollTop', 'get').mockReturnValue(0);
await findBuildJobLog().trigger('scroll');
expect(findScrollToBottomButton().attributes('disabled')).toBeUndefined();
expect(findScrollToTopButton().attributes('disabled')).toBeDefined();
});
it('resets scroll when not at top or bottom', async () => {
jest.spyOn(findBuildJobLog().element, 'scrollTop', 'get').mockReturnValue(10);
await findBuildJobLog().trigger('scroll');
expect(findScrollToBottomButton().attributes('disabled')).toBeUndefined();
expect(findScrollToTopButton().attributes('disabled')).toBeUndefined();
});
});
});
|