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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe WorkItems::Widgets::Description do
let_it_be(:user) { create(:user) }
let_it_be(:description) do
<<~DESC
- [ ] One
- [ ] Two
- [x] Three
DESC
end
let_it_be(:work_item, refind: true) do
create(:work_item, description: description, last_edited_at: 10.days.ago, last_edited_by: user)
end
describe '.type' do
subject { described_class.type }
it { is_expected.to eq(:description) }
end
describe '#type' do
subject { described_class.new(work_item).type }
it { is_expected.to eq(:description) }
end
describe '#description' do
subject { described_class.new(work_item).description }
it { is_expected.to eq(work_item.description) }
end
describe '#edited?' do
subject { described_class.new(work_item).edited? }
it { is_expected.to be_truthy }
end
describe '#last_edited_at' do
subject { described_class.new(work_item).last_edited_at }
it { is_expected.to eq(work_item.last_edited_at) }
end
describe '#last_edited_by' do
subject { described_class.new(work_item).last_edited_by }
context 'when the work item is edited' do
context 'when last edited user still exists in the DB' do
it { is_expected.to eq(user) }
end
context 'when last edited user no longer exists' do
before do
work_item.update!(last_edited_by: nil)
end
it { is_expected.to eq(Users::Internal.ghost) }
end
end
context 'when the work item is not edited yet' do
before do
work_item.update!(last_edited_at: nil)
end
it { is_expected.to be_nil }
end
end
describe '#task_completion_status' do
subject { described_class.new(work_item).task_completion_status }
expected_status = { completed_count: 1, count: 3 }
it { is_expected.to eq(expected_status) }
end
end
|