|
1 | 1 | RSpec.describe Edition::Show::EmbeddedObject::SubschemaItemComponent, type: :component do |
2 | | - let(:schema) { double("schema: time period") } |
3 | | - let(:subschema) { double("subschema: date_range") } |
4 | | - |
5 | 2 | let(:details) do |
6 | 3 | { |
7 | 4 | "date_range" => { |
|
13 | 10 | } |
14 | 11 | end |
15 | 12 |
|
16 | | - let(:edition) { build(:edition, :pension, details: details) } |
17 | | - let(:object_type) { "date_range" } |
18 | | - let(:schema_name) { "date_range" } |
| 13 | + let(:edition_with_sole_date_range_object) { build(:edition, :time_period, details: details) } |
19 | 14 |
|
20 | 15 | let(:component) do |
21 | 16 | described_class.new( |
22 | | - edition:, |
23 | | - object_type:, |
24 | | - schema_name:, |
| 17 | + edition: edition_with_sole_date_range_object, |
| 18 | + object_type: "date_range", |
| 19 | + schema_name: "date_range", |
25 | 20 | ) |
26 | 21 | end |
27 | 22 |
|
28 | 23 | let(:metadata_response) { "METADATA" } |
29 | 24 | let(:block_response) { "BLOCKS" } |
30 | 25 |
|
31 | 26 | before do |
32 | | - allow(edition.document).to receive(:schema).and_return(schema) |
33 | | - allow(schema).to receive(:subschema).with(object_type).and_return(subschema) |
34 | | - allow(subschema).to receive(:id).and_return(object_type) |
35 | | - allow(subschema).to receive(:block_display_fields).and_return(%w[start end]) |
36 | | - allow(subschema).to receive(:field_ordering_rule).with("start").and_return(1) |
37 | | - allow(subschema).to receive(:field_ordering_rule).with("end").and_return(2) |
38 | | - allow(subschema).to receive(:field_ordering_rule).with("title").and_return(3) |
39 | | - |
40 | 27 | expect(component).to receive(:render).with(metadata_response).and_return(metadata_response) |
41 | 28 | allow(component).to receive(:render).with(block_response).and_return(block_response) |
42 | 29 | end |
43 | 30 |
|
44 | 31 | it "renders non-blank fields apart from 'block_display_fields' with the MetadataComponent" do |
| 32 | + expected_subschema = edition_with_sole_date_range_object.schema.subschema("date_range") |
| 33 | + |
45 | 34 | allow(Edition::Show::EmbeddedObjects::BlocksComponent).to receive(:new).and_return(block_response) |
46 | 35 |
|
47 | 36 | expect(Edition::Show::EmbeddedObjects::MetadataComponent).to receive(:new).with( |
48 | 37 | items: { "other_field" => "Other value" }, |
49 | | - schema: subschema, |
| 38 | + schema: expected_subschema, |
50 | 39 | ).and_return(metadata_response) |
51 | 40 |
|
52 | 41 | render_inline component |
|
63 | 52 | object_type: "date_range", |
64 | 53 | object_title: nil, |
65 | 54 | schema_name: "date_range", |
66 | | - edition: edition, |
| 55 | + edition: edition_with_sole_date_range_object, |
67 | 56 | ).and_return(block_response) |
68 | 57 |
|
69 | 58 | render_inline component |
|
0 commit comments