Skip to content

Commit a0aede4

Browse files
committed
Add hook to access cutoff state
REDMINE-20674
1 parent fe00f38 commit a0aede4

File tree

7 files changed

+90
-0
lines changed

7 files changed

+90
-0
lines changed

entry_types/scrolled/app/views/pageflow_scrolled/entry_json_seed/_entry.json.jbuilder

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ json.config do
4646
json.file_licenses(
4747
I18n.t('pageflow.file_licenses', default: {}).slice(*entry_config.available_file_licenses)
4848
)
49+
50+
json.cut_off entry.cutoff_mode_enabled_for?(request)
4951
end
5052

5153
unless options[:skip_i18n]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {useCutOff} from 'entryState';
2+
3+
import {renderHookInEntry} from 'support';
4+
5+
describe('useCutOff', () => {
6+
it('reads data from config', () => {
7+
const {result} = renderHookInEntry(
8+
() => useCutOff(), {
9+
seed: {
10+
cutOff: true
11+
}
12+
}
13+
);
14+
15+
expect(result.current).toEqual(true);
16+
});
17+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {useEntryStateConfig} from "./EntryStateProvider";
2+
3+
export function useCutOff() {
4+
const config = useEntryStateConfig();
5+
return config.cutOff;
6+
}

entry_types/scrolled/package/src/entryState/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export {useAdditionalSeedData} from './additionalSeedData';
22
export {useContentElementConsentVendor} from './consentVendors';
3+
export {useCutOff} from './cutoff';
34
export {useShareProviders, useShareUrl} from './sharing';
45
export {useEntryTranslations} from './entryTranslations';
56
export {useEntryMetadata} from './metadata';

entry_types/scrolled/package/src/frontend/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export {
6363
useAdditionalSeedData,
6464
useChapters,
6565
useCredits,
66+
useCutOff,
6667
useEntryMetadata,
6768
useEntryStateDispatch,
6869
useEntryTranslations,

entry_types/scrolled/package/src/testHelpers/normalizeSeed.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function normalizeSeed({
4646
additionalSeedData,
4747
consentVendors,
4848
contentElementConsentVendors,
49+
cutOff,
4950
fileLicenses,
5051
entryTranslations
5152
} = {}) {
@@ -90,6 +91,7 @@ export function normalizeSeed({
9091
},
9192
consentVendors: consentVendors || [],
9293
contentElementConsentVendors: contentElementConsentVendors || {},
94+
cutOff,
9395
fileLicenses: fileLicenses || {},
9496
entryTranslations: entryTranslations || []
9597
},

entry_types/scrolled/spec/helpers/pageflow_scrolled/entry_json_seed_helper_spec.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,67 @@ def render(helper, entry, options = {})
11271127
})
11281128
end
11291129
end
1130+
1131+
context 'cutoff' do
1132+
it 'renders false by default' do
1133+
entry = create(:published_entry,
1134+
type_name: 'scrolled')
1135+
1136+
result = render(helper, entry)
1137+
1138+
expect(result).to include_json(config: {cutOff: false})
1139+
end
1140+
1141+
it 'renders cutoff mode result' do
1142+
pageflow_configure do |config|
1143+
config.cutoff_modes.register(
1144+
:test,
1145+
proc { true }
1146+
)
1147+
end
1148+
1149+
site = create(:site, cutoff_mode_name: 'test')
1150+
entry = create(:published_entry,
1151+
site:,
1152+
type_name: 'scrolled',
1153+
revision_attributes: {
1154+
configuration: {
1155+
cutoff_section_perma_id: 100
1156+
}
1157+
})
1158+
chapter = create(:scrolled_chapter, position: 2, revision: entry.revision)
1159+
create(:section, chapter:, position: 2, perma_id: 100)
1160+
1161+
result = render(helper, entry)
1162+
1163+
expect(result).to include_json(config: {cutOff: true})
1164+
end
1165+
1166+
it 'renders false for draft entry' do
1167+
pageflow_configure do |config|
1168+
config.cutoff_modes.register(
1169+
:test,
1170+
proc { true }
1171+
)
1172+
end
1173+
1174+
site = create(:site, cutoff_mode_name: 'test')
1175+
entry = create(:draft_entry,
1176+
site:,
1177+
type_name: 'scrolled',
1178+
revision_attributes: {
1179+
configuration: {
1180+
cutoff_section_perma_id: 100
1181+
}
1182+
})
1183+
chapter = create(:scrolled_chapter, position: 2, revision: entry.revision)
1184+
create(:section, chapter:, position: 2, perma_id: 100)
1185+
1186+
result = render(helper, entry)
1187+
1188+
expect(result).to include_json(config: {cutOff: false})
1189+
end
1190+
end
11301191
end
11311192

11321193
describe '#scrolled_entry_json_seed_script_tag' do

0 commit comments

Comments
 (0)