2018-06-16 09:20:30 -04:00
|
|
|
/* eslint-disable no-unused-vars, func-call-spacing, no-spaced-func, semi, quotes, space-infix-ops, max-len */
|
2017-03-17 13:21:25 -04:00
|
|
|
|
2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-03-17 13:21:25 -04:00
|
|
|
import Vue from 'vue';
|
2017-01-18 23:23:53 -05:00
|
|
|
|
2018-02-06 10:20:07 -05:00
|
|
|
import timeTracker from '~/sidebar/components/time_tracking/time_tracker.vue';
|
2016-12-20 09:44:24 -05:00
|
|
|
|
|
|
|
function initTimeTrackingComponent(opts) {
|
2017-01-18 23:23:53 -05:00
|
|
|
setFixtures(`
|
2016-12-20 09:44:24 -05:00
|
|
|
<div>
|
|
|
|
<div id="mock-container"></div>
|
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
|
|
|
|
this.initialData = {
|
|
|
|
time_estimate: opts.timeEstimate,
|
|
|
|
time_spent: opts.timeSpent,
|
|
|
|
human_time_estimate: opts.timeEstimateHumanReadable,
|
|
|
|
human_time_spent: opts.timeSpentHumanReadable,
|
2017-05-04 08:11:15 -04:00
|
|
|
rootPath: '/',
|
2016-12-20 09:44:24 -05:00
|
|
|
};
|
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
const TimeTrackingComponent = Vue.extend(timeTracker);
|
2016-12-20 09:44:24 -05:00
|
|
|
this.timeTracker = new TimeTrackingComponent({
|
|
|
|
el: '#mock-container',
|
|
|
|
propsData: this.initialData,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
describe('Issuable Time Tracker', function() {
|
|
|
|
describe('Initialization', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
initTimeTrackingComponent.call(this, { timeEstimate: 100000, timeSpent: 5000, timeEstimateHumanReadable: '2h 46m', timeSpentHumanReadable: '1h 23m' });
|
|
|
|
});
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
it('should return something defined', function() {
|
|
|
|
expect(this.timeTracker).toBeDefined();
|
|
|
|
});
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
it ('should correctly set timeEstimate', function(done) {
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(this.timeTracker.timeEstimate).toBe(this.initialData.time_estimate);
|
|
|
|
done();
|
2016-12-20 09:44:24 -05:00
|
|
|
});
|
2017-05-04 08:11:15 -04:00
|
|
|
});
|
|
|
|
it ('should correctly set time_spent', function(done) {
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(this.timeTracker.timeSpent).toBe(this.initialData.time_spent);
|
|
|
|
done();
|
2016-12-20 09:44:24 -05:00
|
|
|
});
|
|
|
|
});
|
2017-05-04 08:11:15 -04:00
|
|
|
});
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
describe('Content Display', function() {
|
|
|
|
describe('Panes', function() {
|
|
|
|
describe('Comparison pane', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
initTimeTrackingComponent.call(this, { timeEstimate: 100000, timeSpent: 5000, timeEstimateHumanReadable: '', timeSpentHumanReadable: '' });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show the "Comparison" pane when timeEstimate and time_spent are truthy', function(done) {
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
const $comparisonPane = this.timeTracker.$el.querySelector('.time-tracking-comparison-pane');
|
|
|
|
expect(this.timeTracker.showComparisonState).toBe(true);
|
|
|
|
done();
|
2016-12-20 09:44:24 -05:00
|
|
|
});
|
2017-05-04 08:11:15 -04:00
|
|
|
});
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
describe('Remaining meter', function() {
|
|
|
|
it('should display the remaining meter with the correct width', function(done) {
|
2016-12-20 09:44:24 -05:00
|
|
|
Vue.nextTick(() => {
|
2017-05-04 08:11:15 -04:00
|
|
|
const meterWidth = this.timeTracker.$el.querySelector('.time-tracking-comparison-pane .meter-fill').style.width;
|
|
|
|
const correctWidth = '5%';
|
|
|
|
|
|
|
|
expect(meterWidth).toBe(correctWidth);
|
2016-12-20 09:44:24 -05:00
|
|
|
done();
|
2017-05-04 08:11:15 -04:00
|
|
|
})
|
2016-12-20 09:44:24 -05:00
|
|
|
});
|
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
it('should display the remaining meter with the correct background color when within estimate', function(done) {
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
const styledMeter = $(this.timeTracker.$el).find('.time-tracking-comparison-pane .within_estimate .meter-fill');
|
|
|
|
expect(styledMeter.length).toBe(1);
|
|
|
|
done()
|
2016-12-20 09:44:24 -05:00
|
|
|
});
|
2017-05-04 08:11:15 -04:00
|
|
|
});
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
it('should display the remaining meter with the correct background color when over estimate', function(done) {
|
|
|
|
this.timeTracker.time_estimate = 100000;
|
|
|
|
this.timeTracker.time_spent = 20000000;
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
const styledMeter = $(this.timeTracker.$el).find('.time-tracking-comparison-pane .over_estimate .meter-fill');
|
|
|
|
expect(styledMeter.length).toBe(1);
|
|
|
|
done();
|
2016-12-20 09:44:24 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-05-04 08:11:15 -04:00
|
|
|
});
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
describe("Estimate only pane", function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
initTimeTrackingComponent.call(this, { timeEstimate: 100000, timeSpent: 0, timeEstimateHumanReadable: '2h 46m', timeSpentHumanReadable: '' });
|
|
|
|
});
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
it('should display the human readable version of time estimated', function(done) {
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
const estimateText = this.timeTracker.$el.querySelector('.time-tracking-estimate-only-pane').innerText;
|
|
|
|
const correctText = 'Estimated: 2h 46m';
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
expect(estimateText).toBe(correctText);
|
|
|
|
done();
|
2016-12-20 09:44:24 -05:00
|
|
|
});
|
|
|
|
});
|
2017-05-04 08:11:15 -04:00
|
|
|
});
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
describe('Spent only pane', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
initTimeTrackingComponent.call(this, { timeEstimate: 0, timeSpent: 5000, timeEstimateHumanReadable: '2h 46m', timeSpentHumanReadable: '1h 23m' });
|
|
|
|
});
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
it('should display the human readable version of time spent', function(done) {
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
const spentText = this.timeTracker.$el.querySelector('.time-tracking-spend-only-pane').innerText;
|
|
|
|
const correctText = 'Spent: 1h 23m';
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
expect(spentText).toBe(correctText);
|
|
|
|
done();
|
2016-12-20 09:44:24 -05:00
|
|
|
});
|
|
|
|
});
|
2017-05-04 08:11:15 -04:00
|
|
|
});
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
describe('No time tracking pane', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
initTimeTrackingComponent.call(this, { timeEstimate: 0, timeSpent: 0, timeEstimateHumanReadable: '', timeSpentHumanReadable: '' });
|
|
|
|
});
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
it('should only show the "No time tracking" pane when both timeEstimate and time_spent are falsey', function(done) {
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
const $noTrackingPane = this.timeTracker.$el.querySelector('.time-tracking-no-tracking-pane');
|
|
|
|
const noTrackingText =$noTrackingPane.innerText;
|
|
|
|
const correctText = 'No estimate or time spent';
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
expect(this.timeTracker.showNoTimeTrackingState).toBe(true);
|
|
|
|
expect($noTrackingPane).toBeVisible();
|
|
|
|
expect(noTrackingText).toBe(correctText);
|
|
|
|
done();
|
2016-12-20 09:44:24 -05:00
|
|
|
});
|
|
|
|
});
|
2017-05-04 08:11:15 -04:00
|
|
|
});
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
describe("Help pane", function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
initTimeTrackingComponent.call(this, { timeEstimate: 0, timeSpent: 0 });
|
|
|
|
});
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
it('should not show the "Help" pane by default', function(done) {
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
const $helpPane = this.timeTracker.$el.querySelector('.time-tracking-help-state');
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
expect(this.timeTracker.showHelpState).toBe(false);
|
|
|
|
expect($helpPane).toBeNull();
|
|
|
|
done();
|
2016-12-20 09:44:24 -05:00
|
|
|
});
|
2017-05-04 08:11:15 -04:00
|
|
|
});
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
it('should show the "Help" pane when help button is clicked', function(done) {
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
$(this.timeTracker.$el).find('.help-button').click();
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
const $helpPane = this.timeTracker.$el.querySelector('.time-tracking-help-state');
|
|
|
|
expect(this.timeTracker.showHelpState).toBe(true);
|
|
|
|
expect($helpPane).toBeVisible();
|
|
|
|
done();
|
|
|
|
}, 10);
|
2016-12-20 09:44:24 -05:00
|
|
|
});
|
2017-05-04 08:11:15 -04:00
|
|
|
});
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
it('should not show the "Help" pane when help button is clicked and then closed', function(done) {
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
$(this.timeTracker.$el).find('.help-button').click();
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
setTimeout(() => {
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
$(this.timeTracker.$el).find('.close-help-button').click();
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
const $helpPane = this.timeTracker.$el.querySelector('.time-tracking-help-state');
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
expect(this.timeTracker.showHelpState).toBe(false);
|
|
|
|
expect($helpPane).toBeNull();
|
2016-12-20 09:44:24 -05:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
done();
|
2016-12-20 09:44:24 -05:00
|
|
|
}, 1000);
|
2017-05-04 08:11:15 -04:00
|
|
|
}, 1000);
|
2016-12-20 09:44:24 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-05-04 08:11:15 -04:00
|
|
|
});
|