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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-01-01 13:55:28 +05:30
import { shallowMount } from '@vue/test-utils';
2021-04-29 21:17:54 +05:30
import Vue 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;
2022-06-21 17:19:12 +05:30
const findIssueTimeEstimate = () => wrapper.find('[data-testid="issue-time-estimate"]');
2019-12-26 22:10:19 +05:30
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', () => {
2022-06-21 17:19:12 +05:30
expect(findIssueTimeEstimate().text()).toContain('2 weeks 3 days 1 minute');
2019-12-26 22:10:19 +05:30
});
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
2021-04-29 21:17:54 +05:30
Vue.config.silent = true;
2021-03-08 18:12:59 +05:30
await wrapper.setProps({ estimate: 'Foo <script>alert("XSS")</script>' });
} finally {
2021-04-29 21:17:54 +05:30
Vue.config.silent = false;
2021-03-08 18:12:59 +05:30
}
expect(alertSpy).not.toHaveBeenCalled();
expect(wrapper.find('time').text().trim()).toEqual('0m');
2022-06-21 17:19:12 +05:30
expect(findIssueTimeEstimate().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', () => {
2022-06-21 17:19:12 +05:30
expect(findIssueTimeEstimate().text()).toContain('104 hours 1 minute');
2019-12-26 22:10:19 +05:30
});
});
});