Welcome to mirror list, hosted at ThFree Co, Russian Federation.

time_tracking_formatter_spec.rb « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8bbd12630576de5f8e397416772586cf4c1f6ab8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::TimeTrackingFormatter do
  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

    context 'durations with months' do
      let(:duration_string) { '1mo' }

      it 'uses our custom conversions' do
        expect(subject).to eq(576_000)
      end
    end
  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