Skip to content

Commit

Permalink
Merge pull request #2117 from tf/cutoff-entry-state
Browse files Browse the repository at this point in the history
Add hook to access cutoff state
  • Loading branch information
tf authored Jun 21, 2024
2 parents fe00f38 + a0aede4 commit e8d8e2c
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 17 additions & 0 deletions entry_types/scrolled/package/spec/entryState/cutoff-spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
6 changes: 6 additions & 0 deletions entry_types/scrolled/package/src/entryState/cutoff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {useEntryStateConfig} from "./EntryStateProvider";

export function useCutOff() {
const config = useEntryStateConfig();
return config.cutOff;
}
1 change: 1 addition & 0 deletions entry_types/scrolled/package/src/entryState/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 1 addition & 0 deletions entry_types/scrolled/package/src/frontend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export {
useAdditionalSeedData,
useChapters,
useCredits,
useCutOff,
useEntryMetadata,
useEntryStateDispatch,
useEntryTranslations,
Expand Down
2 changes: 2 additions & 0 deletions entry_types/scrolled/package/src/testHelpers/normalizeSeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function normalizeSeed({
additionalSeedData,
consentVendors,
contentElementConsentVendors,
cutOff,
fileLicenses,
entryTranslations
} = {}) {
Expand Down Expand Up @@ -90,6 +91,7 @@ export function normalizeSeed({
},
consentVendors: consentVendors || [],
contentElementConsentVendors: contentElementConsentVendors || {},
cutOff,
fileLicenses: fileLicenses || {},
entryTranslations: entryTranslations || []
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e8d8e2c

Please sign in to comment.