Skip to content

Commit 428ae0a

Browse files
Surface topical event hint text and label from schema
We want to show a bit of hint text under the document type, which should come from the schema description, in the same way it does for other "single" document (sub)types such as news stories. The label should also come from the schema title. Topical events do not have subtypes so there is no additional choose type screen. Calling `ConfigurableDocumentType.find` with a "real" document type key put us in a position where we needed to either build a test type with that key or stub the call. I opted to do the latter, since we have generally kept our tests agnostic to any real types. I stubbed inside the test, in the "base" and "new document" controller tests, but opted for a test helper for the feature tests. This is because for unit tests we have a lot of granular scenarios where the "schema" needs to be built in place. Tests will break if I try to stub the `find` first with a generic document type instance. Nonetheless, for the feature tests, because all of them use the same json fixture, we can set up the document types and stub our find method for all tests. There are some "group" tests that use a different json where additional stubbing was required. Because the setup is now done in the helper, I was able to remove a lot of feature test steps that were ensuring the document type is set up.
1 parent 85c280e commit 428ae0a

File tree

9 files changed

+21
-63
lines changed

9 files changed

+21
-63
lines changed

app/controllers/admin/new_document_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def types_hash
8484
}
8585
types["topical_event"] = {
8686
"klass" => StandardEdition,
87-
"hint_text" => "Use this to create config-driven topical events.",
88-
"label" => "Topical Event (experimental)",
87+
"hint_text" => ConfigurableDocumentType.find("topical_event").description,
88+
"label" => "#{ConfigurableDocumentType.find('topical_event').label} (experimental)",
8989
"redirect" => new_admin_standard_edition_path(configurable_document_type: "topical_event"),
9090
}
9191

features/edition-images.feature

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ Feature: Images tab on edit edition
4444

4545
Scenario: User uploads a header image
4646
And the configurable document types feature flag is enabled
47-
And the test configurable document type is defined
4847
And I draft a new "Test configurable document type" configurable document titled "The history of GOV.UK"
4948
When I visit the images tab of the document "The history of GOV.UK"
5049
Then I should see a card associated with the header image usage
@@ -55,7 +54,6 @@ Scenario: User uploads a header image
5554

5655
Scenario: User uploads multiple images for a usage
5756
Given the configurable document types feature flag is enabled
58-
And the test configurable document type is defined
5957
And I draft a new "Test configurable document type" configurable document titled "The history of GOV.UK"
6058
When I visit the images tab of the document "The history of GOV.UK"
6159
When I upload multiple images including a 960x960 image

features/fixtures/test_configurable_document_type.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"key": "test",
2+
"key": "test_type",
33
"title": "Test configurable document type",
44
"description": "A test configurable document on GOV.UK",
55
"forms": {
@@ -100,6 +100,7 @@
100100
"organisations": null,
101101
"backdating_enabled": false,
102102
"translations_enabled": true,
103+
"features_enabled": true,
103104
"images": {
104105
"enabled": true,
105106
"usages": {

features/standard-edition.feature

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Feature: Standard Editions
33
Scenario: Creating a new draft configurable document
44
Given I am a writer
55
And the configurable document types feature flag is enabled
6-
And the test configurable document type is defined
76
When I draft a new "Test configurable document type" configurable document titled "The history of GOV.UK"
87
Then I am on the summary page of the draft titled "The history of GOV.UK"
98
And when I switch to the Images tab to fill in the other configurable fields
@@ -13,15 +12,13 @@ Feature: Standard Editions
1312
Scenario: Force publishing an existing draft configurable document
1413
Given I am an editor
1514
And the configurable document types feature flag is enabled
16-
And the test configurable document type is defined
1715
When I publish a submitted draft of a test configurable document titled "The history of GOV.UK"
1816
Then I can see that the draft edition of "The history of GOV.UK" was published successfully
1917
And a new draft of "The history of GOV.UK" is created with the correct field values
2018

2119
Scenario: Adding translations with all content block types
2220
Given I am a writer
2321
And the configurable document types feature flag is enabled
24-
And the test configurable document type is defined with translations enabled
2522
And I have drafted an English configurable document titled "Digital transformation report"
2623
When I go to add a Welsh translation
2724
Then configured content blocks should appear on the translation page
@@ -34,15 +31,13 @@ Feature: Standard Editions
3431
Scenario: Editing translations on a persisted edition
3532
Given I am a writer
3633
And the configurable document types feature flag is enabled
37-
And the test configurable document type is defined with translations enabled
3834
And I have published an English document with a Welsh translation
3935
When I create a new draft and visit the Welsh translation
4036
Then the Welsh translations should have persisted
4137

4238
Scenario: Creating a non-English primary locale configurable document
4339
Given I am a writer
4440
And the configurable document types feature flag is enabled
45-
And the test configurable document type is defined with translations enabled
4641
When I create a new "Test configurable document type" with Welsh as the primary locale titled "Strategaeth Ddigidol Cymru"
4742
Then I am on the summary page of the draft titled "Strategaeth Ddigidol Cymru"
4843
And the language of the document should be Welsh

features/step_definitions/standard_edition_featurings_steps.rb

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,5 @@
11
And(/^a featurable standard edition called "([^"]*)" exists$/) do |title|
2-
ConfigurableDocumentType.setup_test_types({ "test_type" => {
3-
"key" => "test_type",
4-
"title" => "Test Type",
5-
"forms" => {
6-
"documents" => {
7-
"fields" => {
8-
"body" => {
9-
"title" => "Body",
10-
"description" => "The main content of the page",
11-
"block" => "govspeak",
12-
},
13-
},
14-
},
15-
},
16-
"schema" => {
17-
"properties" => {
18-
"test_attribute" => {
19-
"title" => "Test Attribute",
20-
"type" => "string",
21-
},
22-
},
23-
},
24-
"presenters" => {
25-
"publishing_api" => {
26-
"details" => {},
27-
"links" => [],
28-
},
29-
},
30-
"associations" => [],
31-
"settings" => {
32-
"edit_screens" => {
33-
"document" => %w[test_attribute],
34-
},
35-
"base_path_prefix" => "/government/test",
36-
"publishing_api_schema_name" => "test_article",
37-
"publishing_api_document_type" => "test_story",
38-
"rendering_app" => "frontend",
39-
"images" => {
40-
"enabled" => false,
41-
},
42-
"organisations" => nil,
43-
"backdating_enabled" => false,
44-
"history_mode_enabled" => false,
45-
"translations_enabled" => false,
46-
"features_enabled" => true,
47-
},
48-
} })
49-
@featurable_edition = create(:standard_edition, configurable_document_type: "test_type", title:)
2+
@featurable_edition = create(:standard_edition, title:)
503
end
514

525
Given(/^the featurable standard edition is linked to an edition with the title "([^"]*)"$/) do |title|
@@ -57,8 +10,8 @@
5710
end
5811

5912
And(/^two featurings exist for the edition$/) do
60-
featured_edition_1 = create(:published_standard_edition, configurable_document_type: "test_type", title: "Featured Edition 1")
61-
featured_edition_2 = create(:published_standard_edition, configurable_document_type: "test_type", title: "Featured Edition 2")
13+
featured_edition_1 = create(:published_standard_edition, title: "Featured Edition 1")
14+
featured_edition_2 = create(:published_standard_edition, title: "Featured Edition 2")
6215
feature_list = @featurable_edition.feature_lists.create!(locale: @featurable_edition.primary_locale)
6316
create(:feature, feature_list:, document: featured_edition_1.document)
6417
create(:feature, feature_list:, document: featured_edition_2.document)

features/step_definitions/standard_edition_steps.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ def create_configurable_document(title:, locale: "en", summary: nil, body: nil,
88
create(
99
:draft_standard_edition,
1010
{
11-
configurable_document_type: "test",
1211
images:,
1312
title: title,
1413
summary: summary || defaults[:summary],
@@ -158,7 +157,6 @@ def default_content_for_locale(locale)
158157
standard_edition = create(
159158
:submitted_standard_edition,
160159
{
161-
configurable_document_type: "test",
162160
images: [image],
163161
title: title,
164162
block_content: default_block_content_for_locale("en").merge("lead_image" => image.image_data.id.to_s),
@@ -291,7 +289,6 @@ def default_content_for_locale(locale)
291289
@standard_edition = create(
292290
:published_standard_edition,
293291
{
294-
configurable_document_type: "test",
295292
title: default_content_for_locale("en")[:title],
296293
summary: default_content_for_locale("en")[:summary],
297294
block_content: default_block_content_for_locale("en"),
@@ -325,6 +322,7 @@ def default_content_for_locale(locale)
325322
types = {}
326323
type_definitions.each do |type_definition|
327324
types[type_definition["key"]] = type_definition
325+
ConfigurableDocumentType.stubs(:find).returns(ConfigurableDocumentType.new(type_definition))
328326
end
329327
ConfigurableDocumentType.setup_test_types(types)
330328
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require_relative "mocha"
2+
3+
Before do
4+
type_definition = JSON.parse(File.read(Rails.root.join("features/fixtures/test_configurable_document_type.json")))
5+
ConfigurableDocumentType.setup_test_types({ "test_type" => type_definition })
6+
ConfigurableDocumentType.stubs(:find).returns(ConfigurableDocumentType.new(type_definition))
7+
end

test/functional/admin/base_controller_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
class Admin::BaseControllerTest < ActionController::TestCase
44
include GdsApi::TestHelpers::PublishingApi
55

6+
setup do
7+
ConfigurableDocumentType.stubs(:find).returns(ConfigurableDocumentType.new({}))
8+
end
9+
610
view_test "renders header component with correct links" do
711
login_as :gds_editor, create(:organisation, name: "my-test-org")
812
@controller = Admin::NewDocumentController.new

test/functional/admin/new_document_controller_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
class Admin::NewDocumentControllerTest < ActionController::TestCase
44
setup do
55
login_as :writer
6+
7+
ConfigurableDocumentType.stubs(:find).returns(ConfigurableDocumentType.new({}))
68
end
79

810
view_test "GET #index renders the 'New Document' page with the header, all permitted radio selection options and inset text" do

0 commit comments

Comments
 (0)