debian-mirror-gitlab/spec/lib/gitlab/time_tracking_formatter_spec.rb

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

78 lines
1.7 KiB
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::TimeTrackingFormatter do
2019-09-30 21:07:59 +05:30
describe '#parse' do
2023-04-23 21:23:45 +05:30
let(:keep_zero) { false }
subject { described_class.parse(duration_string, keep_zero: keep_zero) }
2019-09-30 21:07:59 +05:30
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-12-04 20:38:33 +05:30
context 'durations with months' do
let(:duration_string) { '1mo' }
it 'uses our custom conversions' do
expect(subject).to eq(576_000)
end
end
2023-04-23 21:23:45 +05:30
context 'when the duration is zero' do
let(:duration_string) { '0h' }
context 'when keep_zero is false' do
it 'returns nil' do
expect(subject).to be_nil
end
end
context 'when keep_zero is true' do
let(:keep_zero) { true }
it 'returns zero' do
expect(subject).to eq(0)
end
end
end
2019-09-30 21:07:59 +05:30
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
2021-09-04 01:27:46 +05:30
context 'handles negative time input' do
let(:num_seconds) { -178_800 }
it { expect(subject).to eq('-1w 1d 1h 40m') }
end
2019-09-30 21:07:59 +05:30
end
end