debian-mirror-gitlab/spec/models/concerns/taskable_spec.rb

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

102 lines
2.3 KiB
Ruby
Raw Normal View History

2022-04-04 11:22:00 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-04-23 21:23:45 +05:30
RSpec.describe Taskable, feature_category: :team_planning do
2022-04-04 11:22:00 +05:30
using RSpec::Parameterized::TableSyntax
describe '.get_tasks' do
let(:description) do
<<~MARKDOWN
Any text before the list
- [ ] First item
- [x] Second item
* [x] First item
* [ ] Second item
2023-04-23 21:23:45 +05:30
<!-- a comment
- [ ] Item in comment, ignore
rest of comment -->
2022-06-21 17:19:12 +05:30
+ [ ] No-break space (U+00A0)
+ [] Figure space (U+2007)
2023-04-23 21:23:45 +05:30
```
- [ ] Item in code, ignore
```
2022-06-21 17:19:12 +05:30
+ [] Narrow no-break space (U+202F)
+ [] Thin space (U+2009)
2023-07-09 08:55:56 +05:30
1. [ ] Numbered 1
2) [x] Numbered 2
2022-04-04 11:22:00 +05:30
MARKDOWN
end
let(:expected_result) do
[
TaskList::Item.new('- [ ]', 'First item'),
TaskList::Item.new('- [x]', 'Second item'),
TaskList::Item.new('* [x]', 'First item'),
2023-07-09 08:55:56 +05:30
TaskList::Item.new('* [ ]', 'Second item'),
TaskList::Item.new('1. [ ]', 'Numbered 1'),
TaskList::Item.new('2) [x]', 'Numbered 2')
2022-04-04 11:22:00 +05:30
]
end
subject { described_class.get_tasks(description) }
it { is_expected.to match(expected_result) }
2023-05-08 21:46:49 +05:30
describe 'with single line comments' do
let(:description) do
<<~MARKDOWN
<!-- line comment -->
- [ ] only task item
<!-- another line comment -->
MARKDOWN
end
let(:expected_result) { [TaskList::Item.new('- [ ]', 'only task item')] }
it { is_expected.to match(expected_result) }
end
2022-04-04 11:22:00 +05:30
end
describe '#task_list_items' do
where(issuable_type: [:issue, :merge_request])
with_them do
let(:issuable) { build(issuable_type, description: description) }
subject(:result) { issuable.task_list_items }
context 'when description is present' do
let(:description) { 'markdown' }
it 'gets tasks from markdown' do
expect(described_class).to receive(:get_tasks)
result
end
end
context 'when description is blank' do
let(:description) { '' }
it 'returns empty array' do
expect(result).to be_empty
end
it 'does not try to get tasks from markdown' do
expect(described_class).not_to receive(:get_tasks)
result
end
end
end
end
end