diff --git a/entry_types/scrolled/app/views/pageflow_scrolled/entry_json_seed/_entry.json.jbuilder b/entry_types/scrolled/app/views/pageflow_scrolled/entry_json_seed/_entry.json.jbuilder index 663dee7f1..4146e08c4 100644 --- a/entry_types/scrolled/app/views/pageflow_scrolled/entry_json_seed/_entry.json.jbuilder +++ b/entry_types/scrolled/app/views/pageflow_scrolled/entry_json_seed/_entry.json.jbuilder @@ -46,6 +46,8 @@ json.config do json.file_licenses( I18n.t('pageflow.file_licenses', default: {}).slice(*entry_config.available_file_licenses) ) + + json.cut_off entry.cutoff_mode_enabled_for?(request) end unless options[:skip_i18n] diff --git a/entry_types/scrolled/package/spec/entryState/cutoff-spec.js b/entry_types/scrolled/package/spec/entryState/cutoff-spec.js new file mode 100644 index 000000000..919c4462c --- /dev/null +++ b/entry_types/scrolled/package/spec/entryState/cutoff-spec.js @@ -0,0 +1,17 @@ +import {useCutOff} from 'entryState'; + +import {renderHookInEntry} from 'support'; + +describe('useCutOff', () => { + it('reads data from config', () => { + const {result} = renderHookInEntry( + () => useCutOff(), { + seed: { + cutOff: true + } + } + ); + + expect(result.current).toEqual(true); + }); +}); diff --git a/entry_types/scrolled/package/src/entryState/cutoff.js b/entry_types/scrolled/package/src/entryState/cutoff.js new file mode 100644 index 000000000..5cc9200dc --- /dev/null +++ b/entry_types/scrolled/package/src/entryState/cutoff.js @@ -0,0 +1,6 @@ +import {useEntryStateConfig} from "./EntryStateProvider"; + +export function useCutOff() { + const config = useEntryStateConfig(); + return config.cutOff; +} diff --git a/entry_types/scrolled/package/src/entryState/index.js b/entry_types/scrolled/package/src/entryState/index.js index 153a6bdc1..9a09a07b0 100644 --- a/entry_types/scrolled/package/src/entryState/index.js +++ b/entry_types/scrolled/package/src/entryState/index.js @@ -1,5 +1,6 @@ export {useAdditionalSeedData} from './additionalSeedData'; export {useContentElementConsentVendor} from './consentVendors'; +export {useCutOff} from './cutoff'; export {useShareProviders, useShareUrl} from './sharing'; export {useEntryTranslations} from './entryTranslations'; export {useEntryMetadata} from './metadata'; diff --git a/entry_types/scrolled/package/src/frontend/index.js b/entry_types/scrolled/package/src/frontend/index.js index f15c60091..6f6f87a38 100644 --- a/entry_types/scrolled/package/src/frontend/index.js +++ b/entry_types/scrolled/package/src/frontend/index.js @@ -63,6 +63,7 @@ export { useAdditionalSeedData, useChapters, useCredits, + useCutOff, useEntryMetadata, useEntryStateDispatch, useEntryTranslations, diff --git a/entry_types/scrolled/package/src/testHelpers/normalizeSeed.js b/entry_types/scrolled/package/src/testHelpers/normalizeSeed.js index 15171bb91..a4bbea58e 100644 --- a/entry_types/scrolled/package/src/testHelpers/normalizeSeed.js +++ b/entry_types/scrolled/package/src/testHelpers/normalizeSeed.js @@ -46,6 +46,7 @@ export function normalizeSeed({ additionalSeedData, consentVendors, contentElementConsentVendors, + cutOff, fileLicenses, entryTranslations } = {}) { @@ -90,6 +91,7 @@ export function normalizeSeed({ }, consentVendors: consentVendors || [], contentElementConsentVendors: contentElementConsentVendors || {}, + cutOff, fileLicenses: fileLicenses || {}, entryTranslations: entryTranslations || [] }, diff --git a/entry_types/scrolled/spec/helpers/pageflow_scrolled/entry_json_seed_helper_spec.rb b/entry_types/scrolled/spec/helpers/pageflow_scrolled/entry_json_seed_helper_spec.rb index b3b2e8e0c..867386fa1 100644 --- a/entry_types/scrolled/spec/helpers/pageflow_scrolled/entry_json_seed_helper_spec.rb +++ b/entry_types/scrolled/spec/helpers/pageflow_scrolled/entry_json_seed_helper_spec.rb @@ -1127,6 +1127,67 @@ def render(helper, entry, options = {}) }) end end + + context 'cutoff' do + it 'renders false by default' do + entry = create(:published_entry, + type_name: 'scrolled') + + result = render(helper, entry) + + expect(result).to include_json(config: {cutOff: false}) + end + + it 'renders cutoff mode result' do + pageflow_configure do |config| + config.cutoff_modes.register( + :test, + proc { true } + ) + end + + site = create(:site, cutoff_mode_name: 'test') + entry = create(:published_entry, + site:, + type_name: 'scrolled', + revision_attributes: { + configuration: { + cutoff_section_perma_id: 100 + } + }) + chapter = create(:scrolled_chapter, position: 2, revision: entry.revision) + create(:section, chapter:, position: 2, perma_id: 100) + + result = render(helper, entry) + + expect(result).to include_json(config: {cutOff: true}) + end + + it 'renders false for draft entry' do + pageflow_configure do |config| + config.cutoff_modes.register( + :test, + proc { true } + ) + end + + site = create(:site, cutoff_mode_name: 'test') + entry = create(:draft_entry, + site:, + type_name: 'scrolled', + revision_attributes: { + configuration: { + cutoff_section_perma_id: 100 + } + }) + chapter = create(:scrolled_chapter, position: 2, revision: entry.revision) + create(:section, chapter:, position: 2, perma_id: 100) + + result = render(helper, entry) + + expect(result).to include_json(config: {cutOff: false}) + end + end end describe '#scrolled_entry_json_seed_script_tag' do