0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-27 11:20:28 +01:00
discourse-custom-wizard/spec/components/custom_wizard/field_spec.rb

47 Zeilen
1,3 KiB
Ruby

2021-03-11 07:30:15 +01:00
# frozen_string_literal: true
2020-11-03 01:24:20 +01:00
describe CustomWizard::Field do
2021-09-07 14:06:13 +02:00
let(:field_hash) { get_wizard_fixture("field/field") }
2021-03-11 07:30:15 +01:00
before do
2020-11-03 01:24:20 +01:00
CustomWizard::Field.register(
2024-10-16 13:52:03 +02:00
"location",
"discourse-locations",
%w[components helpers lib stylesheets templates],
2020-11-03 01:24:20 +01:00
type_opts: {
2024-10-16 13:52:03 +02:00
prefill: {
coordinates: [35.3082, 149.1244],
},
},
2020-11-03 01:24:20 +01:00
)
end
2021-03-11 07:30:15 +01:00
it "initialize custom field attributes" do
field = CustomWizard::Field.new(field_hash)
expect(field.id).to eq("field_id")
expect(field.index).to eq(0)
expect(field.label).to eq("<p>Field Label</p>")
expect(field.image).to eq("field_image_url.png")
expect(field.description).to eq("Field description")
expect(field.required).to eq(true)
expect(field.type).to eq("field_type")
expect(field.content).to eq([])
end
2021-03-11 07:30:15 +01:00
it "registers custom field types" do
2020-11-03 01:24:20 +01:00
expect(CustomWizard::Field.types[:location].present?).to eq(true)
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
it "allows custom field types to set default attributes" do
2024-10-16 13:52:03 +02:00
expect(CustomWizard::Field.types[:location][:prefill]).to eq(
{ coordinates: [35.3082, 149.1244] },
)
2020-11-03 01:24:20 +01:00
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
it "registers custom field assets" do
2024-10-16 13:52:03 +02:00
expect(CustomWizard::Field.require_assets["discourse-locations"]).to eq(
%w[components helpers lib stylesheets templates],
)
2020-11-03 01:24:20 +01:00
end
2021-03-11 07:30:15 +01:00
end