mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 19:30:48 +08:00
DEV: Allow plugins to add wizard steps after specific steps (#9315)
This commit is contained in:

committed by
GitHub

parent
b2f30aa0b5
commit
689c61b462
@ -81,6 +81,56 @@ describe Wizard do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#append_step with after specified" do
|
||||
let(:user) { Fabricate.build(:moderator) }
|
||||
let(:wizard) { Wizard.new(user) }
|
||||
|
||||
it 'inserts steps after the proper step' do
|
||||
wizard.append_step('first') do |step|
|
||||
step.add_field(id: 'another_element', type: 'text')
|
||||
end
|
||||
wizard.append_step('second') do |step|
|
||||
step.add_field(id: 'another_element', type: 'text')
|
||||
end
|
||||
wizard.append_step('actually-second', after: 'first') do |step|
|
||||
step.add_field(id: 'another_element', type: 'text')
|
||||
end
|
||||
|
||||
expect(wizard.steps.sort_by(&:index).map(&:id)).to eq(["first", "actually-second", "second"])
|
||||
expect(wizard.steps.map(&:index).sort).to eq([0, 1, 2])
|
||||
end
|
||||
|
||||
it 'inserts steps at the end if the after value does not match an existing step' do
|
||||
wizard.append_step('first') do |step|
|
||||
step.add_field(id: 'another_element', type: 'text')
|
||||
end
|
||||
wizard.append_step('second') do |step|
|
||||
step.add_field(id: 'another_element', type: 'text')
|
||||
end
|
||||
wizard.append_step('should_be_last', after: 'abcdefghi') do |step|
|
||||
step.add_field(id: 'another_element', type: 'text')
|
||||
end
|
||||
|
||||
expect(wizard.steps.sort_by(&:index).map(&:id)).to eq(["first", "second", "should_be_last"])
|
||||
expect(wizard.steps.map(&:index).sort).to eq([0, 1, 2])
|
||||
end
|
||||
|
||||
it 'inserts steps at the end' do
|
||||
wizard.append_step('first') do |step|
|
||||
step.add_field(id: 'another_element', type: 'text')
|
||||
end
|
||||
wizard.append_step('second') do |step|
|
||||
step.add_field(id: 'another_element', type: 'text')
|
||||
end
|
||||
wizard.append_step('last', after: 'second') do |step|
|
||||
step.add_field(id: 'another_element', type: 'text')
|
||||
end
|
||||
|
||||
expect(wizard.steps.sort_by(&:index).map(&:id)).to eq(["first", "second", "last"])
|
||||
expect(wizard.steps.map(&:index).sort).to eq([0, 1, 2])
|
||||
end
|
||||
end
|
||||
|
||||
describe "completed?" do
|
||||
let(:user) { Fabricate.build(:moderator) }
|
||||
let(:wizard) { Wizard.new(user) }
|
||||
|
Reference in New Issue
Block a user