2019-06-11 06:40:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::TimeTrackingFormatter do
|
2019-06-11 06:40:01 -04:00
|
|
|
describe '#parse' do
|
|
|
|
subject { described_class.parse(duration_string) }
|
|
|
|
|
|
|
|
context 'positive durations' do
|
|
|
|
let(:duration_string) { '3h 20m' }
|
|
|
|
|
|
|
|
it { expect(subject).to eq(12_000) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'negative durations' do
|
|
|
|
let(:duration_string) { '-3h 20m' }
|
|
|
|
|
|
|
|
it { expect(subject).to eq(-12_000) }
|
|
|
|
end
|
2019-08-23 16:05:39 -04:00
|
|
|
|
|
|
|
context 'durations with months' do
|
|
|
|
let(:duration_string) { '1mo' }
|
|
|
|
|
|
|
|
it 'uses our custom conversions' do
|
|
|
|
expect(subject).to eq(576_000)
|
|
|
|
end
|
|
|
|
end
|
2019-06-11 06:40:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#output' do
|
|
|
|
let(:num_seconds) { 178_800 }
|
|
|
|
|
|
|
|
subject { described_class.output(num_seconds) }
|
|
|
|
|
|
|
|
context 'time_tracking_limit_to_hours setting is true' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(time_tracking_limit_to_hours: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject).to eq('49h 40m') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'time_tracking_limit_to_hours setting is false' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(time_tracking_limit_to_hours: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject).to eq('1w 1d 1h 40m') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|