debian-mirror-gitlab/spec/helpers/admin/background_migrations_helper_spec.rb

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

68 lines
1.7 KiB
Ruby
Raw Normal View History

2021-09-04 01:27:46 +05:30
# frozen_string_literal: true
require "spec_helper"
RSpec.describe Admin::BackgroundMigrationsHelper do
2022-03-02 08:16:31 +05:30
describe '#batched_migration_status_badge_variant' do
2021-09-04 01:27:46 +05:30
using RSpec::Parameterized::TableSyntax
2022-06-21 17:19:12 +05:30
where(:status_name, :variant) do
2022-03-02 08:16:31 +05:30
:active | :info
:paused | :warning
:failed | :danger
:finished | :success
2021-09-04 01:27:46 +05:30
end
2022-03-02 08:16:31 +05:30
subject { helper.batched_migration_status_badge_variant(migration) }
2021-09-04 01:27:46 +05:30
with_them do
2022-06-21 17:19:12 +05:30
let(:migration) { build(:batched_background_migration, status_name) }
2021-09-04 01:27:46 +05:30
2022-03-02 08:16:31 +05:30
it { is_expected.to eq(variant) }
2021-09-04 01:27:46 +05:30
end
end
describe '#batched_migration_progress' do
subject { helper.batched_migration_progress(migration, completed_rows) }
2022-06-21 17:19:12 +05:30
let(:migration) { build(:batched_background_migration, :active, total_tuple_count: 100) }
2021-09-04 01:27:46 +05:30
let(:completed_rows) { 25 }
it 'returns completion percentage' do
expect(subject).to eq(25)
end
context 'when migration is finished' do
2022-06-21 17:19:12 +05:30
let(:migration) { build(:batched_background_migration, :finished, total_tuple_count: nil) }
2021-09-04 01:27:46 +05:30
it 'returns 100 percent' do
expect(subject).to eq(100)
end
end
context 'when total_tuple_count is nil' do
2022-06-21 17:19:12 +05:30
let(:migration) { build(:batched_background_migration, :active, total_tuple_count: nil) }
2021-09-04 01:27:46 +05:30
it 'returns nil' do
expect(subject).to eq(nil)
end
context 'when there are no completed rows' do
let(:completed_rows) { 0 }
it 'returns 0 percent' do
expect(subject).to eq(0)
end
end
end
context 'when completed rows are greater than total count' do
let(:completed_rows) { 150 }
it 'returns 99 percent' do
expect(subject).to eq(99)
end
end
end
end