2019-12-10 04:07:51 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { config as vueConfig } from 'vue';
|
2019-10-31 05:06:29 -04:00
|
|
|
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,
|
|
|
|
},
|
2020-12-22 07:10:09 -05:00
|
|
|
provide: {
|
|
|
|
timeTrackingLimitToHours: false,
|
|
|
|
},
|
2019-10-31 05:06:29 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the correct time estimate', () => {
|
2020-12-23 07:10:26 -05:00
|
|
|
expect(wrapper.find('time').text().trim()).toEqual('2w 3d 1m');
|
2019-10-31 05:06:29 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders expanded time estimate in tooltip', () => {
|
|
|
|
expect(wrapper.find('.js-issue-time-estimate').text()).toContain('2 weeks 3 days 1 minute');
|
|
|
|
});
|
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
it('prevents tooltip xss', async () => {
|
2019-10-31 05:06:29 -04:00
|
|
|
const alertSpy = jest.spyOn(window, 'alert');
|
2020-12-25 04:10:31 -05:00
|
|
|
|
|
|
|
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-10-31 05:06:29 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when limitToHours is true', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = shallowMount(IssueTimeEstimate, {
|
|
|
|
propsData: {
|
|
|
|
estimate: 374460,
|
|
|
|
},
|
2020-12-22 07:10:09 -05:00
|
|
|
provide: {
|
|
|
|
timeTrackingLimitToHours: true,
|
|
|
|
},
|
2019-10-31 05:06:29 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the correct time estimate', () => {
|
2020-12-23 07:10:26 -05:00
|
|
|
expect(wrapper.find('time').text().trim()).toEqual('104h 1m');
|
2019-10-31 05:06:29 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders expanded time estimate in tooltip', () => {
|
|
|
|
expect(wrapper.find('.js-issue-time-estimate').text()).toContain('104 hours 1 minute');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|