debian-mirror-gitlab/spec/frontend/boards/components/issue_time_estimate_spec.js

70 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-01-01 13:55:28 +05:30
import { shallowMount } from '@vue/test-utils';
2021-03-11 19:13:27 +05:30
import { config as vueConfig } from 'vue';
2019-12-26 22:10:19 +05:30
import IssueTimeEstimate from '~/boards/components/issue_time_estimate.vue';
describe('Issue Time Estimate component', () => {
let wrapper;
afterEach(() => {
wrapper.destroy();
});
describe('when limitToHours is false', () => {
beforeEach(() => {
wrapper = shallowMount(IssueTimeEstimate, {
propsData: {
estimate: 374460,
},
2021-03-08 18:12:59 +05:30
provide: {
timeTrackingLimitToHours: false,
},
2019-12-26 22:10:19 +05:30
});
});
it('renders the correct time estimate', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.find('time').text().trim()).toEqual('2w 3d 1m');
2019-12-26 22:10:19 +05:30
});
it('renders expanded time estimate in tooltip', () => {
expect(wrapper.find('.js-issue-time-estimate').text()).toContain('2 weeks 3 days 1 minute');
});
2021-03-08 18:12:59 +05:30
it('prevents tooltip xss', async () => {
2019-12-26 22:10:19 +05:30
const alertSpy = jest.spyOn(window, 'alert');
2021-03-08 18:12:59 +05:30
try {
// This will raise props validating warning by Vue, silencing it
vueConfig.silent = true;
await wrapper.setProps({ estimate: 'Foo <script>alert("XSS")</script>' });
} finally {
vueConfig.silent = false;
}
expect(alertSpy).not.toHaveBeenCalled();
expect(wrapper.find('time').text().trim()).toEqual('0m');
expect(wrapper.find('.js-issue-time-estimate').text()).toContain('0m');
2019-12-26 22:10:19 +05:30
});
});
describe('when limitToHours is true', () => {
beforeEach(() => {
wrapper = shallowMount(IssueTimeEstimate, {
propsData: {
estimate: 374460,
},
2021-03-08 18:12:59 +05:30
provide: {
timeTrackingLimitToHours: true,
},
2019-12-26 22:10:19 +05:30
});
});
it('renders the correct time estimate', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.find('time').text().trim()).toEqual('104h 1m');
2019-12-26 22:10:19 +05:30
});
it('renders expanded time estimate in tooltip', () => {
expect(wrapper.find('.js-issue-time-estimate').text()).toContain('104 hours 1 minute');
});
});
});