@@ -241,6 +241,99 @@ module PageflowScrolled
241241
242242 expect ( result ) . not_to include ( 'pageflow-scrolled/widgets/test' )
243243 end
244+
245+ it 'includes packs of a present pack-contributing widget outside of editor' do
246+ pageflow_configure do |config |
247+ config . widget_types . register (
248+ pack_widget_type ( name : 'analyticsish' ,
249+ roles : [ 'analytics' ] ,
250+ insert_point : :bottom_of_entry ,
251+ packs : [ 'some/analytics-pack' ] ) ,
252+ default : true
253+ )
254+ end
255+
256+ entry = create ( :published_entry , type_name : 'scrolled' )
257+
258+ result = helper . scrolled_frontend_packs ( entry , entry_mode : :published )
259+
260+ expect ( result ) . to include ( 'some/analytics-pack' )
261+ end
262+
263+ it 'passes the entry to the widget packs method' do
264+ received = nil
265+ pageflow_configure do |config |
266+ config . widget_types . register (
267+ pack_widget_type ( name : 'analyticsish' ,
268+ roles : [ 'analytics' ] ,
269+ insert_point : :bottom_of_entry ,
270+ packs : lambda { |entry |
271+ received = entry
272+ [ ]
273+ } ) ,
274+ default : true
275+ )
276+ end
277+
278+ entry = create ( :published_entry , type_name : 'scrolled' )
279+
280+ helper . scrolled_frontend_packs ( entry , entry_mode : :published )
281+
282+ expect ( received ) . to eq ( entry )
283+ end
284+
285+ it 'passes the request to the widget packs method' do
286+ received = :not_passed
287+ widget_type = Class . new ( Pageflow ::TestWidgetType ) {
288+ define_method ( :packs ) do |request : :not_passed , **|
289+ received = request
290+ [ ]
291+ end
292+ } . new ( name : 'analyticsish' , roles : [ 'analytics' ] , insert_point : :bottom_of_entry )
293+
294+ pageflow_configure do |config |
295+ config . widget_types . register ( widget_type , default : true )
296+ end
297+
298+ entry = create ( :published_entry , type_name : 'scrolled' )
299+
300+ helper . scrolled_frontend_packs ( entry , entry_mode : :published )
301+
302+ expect ( received ) . to eq ( helper . request )
303+ end
304+
305+ it 'includes packs of a pack-contributing widget in editor' do
306+ pageflow_configure do |config |
307+ config . widget_types . register (
308+ pack_widget_type ( name : 'analyticsish' ,
309+ roles : [ 'analytics' ] ,
310+ packs : [ 'some/analytics-pack' ] )
311+ )
312+ end
313+
314+ entry = create ( :published_entry , type_name : 'scrolled' )
315+
316+ result = helper . scrolled_frontend_packs ( entry , entry_mode : :editor )
317+
318+ expect ( result ) . to include ( 'some/analytics-pack' )
319+ end
320+
321+ it 'does not include packs of an editor-disabled pack-contributing widget in editor' do
322+ pageflow_configure do |config |
323+ config . widget_types . register (
324+ pack_widget_type ( name : 'analyticsish' ,
325+ roles : [ 'analytics' ] ,
326+ enabled_in_editor : false ,
327+ packs : [ 'some/analytics-pack' ] )
328+ )
329+ end
330+
331+ entry = create ( :published_entry , type_name : 'scrolled' )
332+
333+ result = helper . scrolled_frontend_packs ( entry , entry_mode : :editor )
334+
335+ expect ( result ) . not_to include ( 'some/analytics-pack' )
336+ end
244337 end
245338
246339 describe 'scrolled_frontend_stylesheet_packs' do
@@ -532,5 +625,13 @@ module PageflowScrolled
532625 expect ( result ) . not_to include ( 'some/script/unless-true' )
533626 end
534627 end
628+
629+ def pack_widget_type ( packs :, **options )
630+ Class . new ( Pageflow ::TestWidgetType ) {
631+ define_method ( :packs ) do |entry :, **|
632+ packs . respond_to? ( :call ) ? packs . call ( entry ) : packs
633+ end
634+ } . new ( **options )
635+ end
535636 end
536637end
0 commit comments