2020-11-03 01:24:20 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-11-30 22:20:10 +01:00
|
|
|
require_relative '../../plugin_helper'
|
2020-11-03 01:24:20 +01:00
|
|
|
|
|
|
|
describe CustomWizard::FieldSerializer do
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
CustomWizard::Template.save(
|
|
|
|
JSON.parse(File.open(
|
|
|
|
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json"
|
|
|
|
).read),
|
|
|
|
skip_jobs: true)
|
|
|
|
@wizard = CustomWizard::Builder.new("super_mega_fun_wizard", user).build
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-03 01:24:20 +01:00
|
|
|
it "should return basic field attributes" do
|
|
|
|
json_array = ActiveModel::ArraySerializer.new(
|
|
|
|
@wizard.steps.first.fields,
|
|
|
|
each_serializer: CustomWizard::FieldSerializer,
|
|
|
|
scope: Guardian.new(user)
|
|
|
|
).as_json
|
2021-04-20 19:58:19 +02:00
|
|
|
|
2022-01-31 10:41:14 +01:00
|
|
|
expect(json_array.size).to eq(@wizard.steps.first.fields.size)
|
2020-11-03 01:24:20 +01:00
|
|
|
expect(json_array[0][:label]).to eq("<p>Text</p>")
|
|
|
|
expect(json_array[0][:description]).to eq("Text field description.")
|
2021-04-20 19:58:19 +02:00
|
|
|
expect(json_array[3][:index]).to eq(3)
|
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 "should return optional field attributes" do
|
|
|
|
json_array = ActiveModel::ArraySerializer.new(
|
|
|
|
@wizard.steps.second.fields,
|
|
|
|
each_serializer: CustomWizard::FieldSerializer,
|
|
|
|
scope: Guardian.new(user)
|
|
|
|
).as_json
|
|
|
|
expect(json_array[0][:format]).to eq("YYYY-MM-DD")
|
2021-03-12 11:12:26 +01:00
|
|
|
expect(json_array[6][:file_types]).to eq(".jpg,.jpeg,.png")
|
2020-11-03 01:24:20 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
end
|