0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-26 11:00:28 +01:00

Merge branch 'main' into frontend_updates

Dieser Commit ist enthalten in:
Marcos 2023-03-29 08:10:51 -05:00 committet von GitHub
Commit 978aaf89b0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 33 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -84,6 +84,10 @@ class CustomWizard::Submission
data data
end end
def submitted?
!!submitted_at
end
def self.get(wizard) def self.get(wizard)
data = PluginStore.get("#{wizard.id}_#{KEY}", wizard.actor_id).last data = PluginStore.get("#{wizard.id}_#{KEY}", wizard.actor_id).last
new(wizard, data) new(wizard, data)

Datei anzeigen

@ -176,6 +176,7 @@ class CustomWizard::Wizard
def unfinished? def unfinished?
return nil unless actor_id return nil unless actor_id
return false if last_submission&.submitted?
most_recent = CustomWizard::UserHistory.where( most_recent = CustomWizard::UserHistory.where(
actor_id: actor_id, actor_id: actor_id,
@ -194,6 +195,7 @@ class CustomWizard::Wizard
def completed? def completed?
return nil unless actor_id return nil unless actor_id
return true if last_submission&.submitted?
history = CustomWizard::UserHistory.where( history = CustomWizard::UserHistory.where(
actor_id: actor_id, actor_id: actor_id,
@ -282,6 +284,10 @@ class CustomWizard::Wizard
@submissions ||= CustomWizard::Submission.list(self).submissions @submissions ||= CustomWizard::Submission.list(self).submissions
end end
def last_submission
@last_submission ||= submissions&.last
end
def current_submission def current_submission
@current_submission ||= begin @current_submission ||= begin
if submissions.present? if submissions.present?

Datei anzeigen

@ -7,6 +7,7 @@ describe CustomWizard::Wizard do
let(:template_json) { get_wizard_fixture("wizard") } let(:template_json) { get_wizard_fixture("wizard") }
let(:permitted_json) { get_wizard_fixture("wizard/permitted") } let(:permitted_json) { get_wizard_fixture("wizard/permitted") }
let(:guests_permitted_json) { get_wizard_fixture("wizard/guests_permitted") } let(:guests_permitted_json) { get_wizard_fixture("wizard/guests_permitted") }
let(:step_json) { get_wizard_fixture("step/step") }
before do before do
Group.refresh_automatic_group!(:trust_level_3) Group.refresh_automatic_group!(:trust_level_3)
@ -75,6 +76,28 @@ describe CustomWizard::Wizard do
expect(@wizard.start).to eq('step_2') expect(@wizard.start).to eq('step_2')
end end
it "determines the user's current step if steps are added" do
append_steps
progress_step('step_1')
progress_step('step_2')
progress_step("step_3")
fourth_step = step_json.dup
fourth_step['id'] = "step_4"
template = template_json.dup
template['steps'] << fourth_step
CustomWizard::Template.save(template, skip_jobs: true)
wizard = CustomWizard::Wizard.new(template, user)
template['steps'].each do |step_template|
wizard.append_step(step_template['id'])
end
expect(wizard.steps.size).to eq(4)
expect(wizard.start).to eq(nil)
end
it "creates a step updater" do it "creates a step updater" do
expect( expect(
@wizard.create_updater('step_1', step_1_field_1: "Text input") @wizard.create_updater('step_1', step_1_field_1: "Text input")