-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2115 from tf/cutoff
Cutoff modes
- Loading branch information
Showing
33 changed files
with
843 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Pageflow | ||
module Admin | ||
# @api private | ||
module CutoffModesHelper | ||
def cutoff_modes_collection(config) | ||
config.cutoff_modes.names.map do |name| | ||
[t(name, scope: 'pageflow.cutoff_modes'), name] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
json.(site, :cutoff_mode_name) | ||
json.pretty_url pretty_site_url(site) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
de: | ||
pageflow: | ||
cutoff_modes: | ||
none: "(Kein)" | ||
pageflow_scrolled: | ||
editor: | ||
section_item: | ||
set_cutoff: "Paywall Grenze oberhalb setzen" | ||
reset_cutoff: "Paywall Grenze entfernen" | ||
cutoff: "Paywall Grenze" | ||
activerecord: | ||
attributes: | ||
pageflow/site: | ||
cutoff_mode_name: "Cutoff-Modus" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
en: | ||
pageflow: | ||
cutoff_modes: | ||
none: "(None)" | ||
pageflow_scrolled: | ||
editor: | ||
section_item: | ||
set_cutoff: "Set paywall cutoff above" | ||
reset_cutoff: "Remove paywall cutoff" | ||
cutoff: "Paywall cutoff" | ||
activerecord: | ||
attributes: | ||
pageflow/site: | ||
cutoff_mode_name: "Cutoff mode" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddCutoffModeNameToSites < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :pageflow_sites, :cutoff_mode_name, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
entry_types/scrolled/package/spec/editor/models/Cutoff-spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {useEditorGlobals, useFakeXhr} from 'support'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
describe('Cutoff', () => { | ||
useFakeXhr(); | ||
|
||
const {createEntry} = useEditorGlobals(); | ||
|
||
it('resets metadata configuration when deleting the cutoff section', () => { | ||
const entry = createEntry({ | ||
metadata: {configuration: {cutoff_section_perma_id: 100}}, | ||
sections: [ | ||
{id: 1, permaId: 100}, | ||
{id: 2, permaId: 101}, | ||
] | ||
}); | ||
|
||
entry.sections.get(1).destroy(); | ||
|
||
expect(entry.metadata.configuration.get('cutoff_section_perma_id')).toBeUndefined(); | ||
}); | ||
}); |
159 changes: 159 additions & 0 deletions
159
entry_types/scrolled/package/spec/editor/views/SectionItemView-spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import {SectionItemView} from 'editor/views/SectionItemView'; | ||
|
||
import {useEditorGlobals, useFakeXhr, useReactBasedBackboneViews} from 'support'; | ||
import userEvent from '@testing-library/user-event'; | ||
import {useFakeTranslations} from 'pageflow/testHelpers'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
describe('SectionItemView', () => { | ||
useFakeXhr(); | ||
|
||
useFakeTranslations({ | ||
'pageflow_scrolled.editor.section_item.set_cutoff': 'Set cutoff point', | ||
'pageflow_scrolled.editor.section_item.reset_cutoff': 'Remove cutoff point', | ||
'pageflow_scrolled.editor.section_item.cutoff': 'Cutoff point', | ||
}); | ||
|
||
const {createEntry} = useEditorGlobals(); | ||
const {render} = useReactBasedBackboneViews(); | ||
|
||
it('does not offer menu item to set cutoff section by default', () => { | ||
const entry = createEntry({ | ||
sections: [ | ||
{id: 1, permaId: 100} | ||
] | ||
}); | ||
const view = new SectionItemView({ | ||
entry, | ||
model: entry.sections.get(1) | ||
}); | ||
|
||
const {queryByRole} = render(view); | ||
|
||
expect(queryByRole('link', {name: 'Set cutoff point'})).toBeNull(); | ||
}); | ||
|
||
it('offers menu item to set cutoff section if site has cutoff mode', async () => { | ||
const entry = createEntry({ | ||
site: { | ||
cutoff_mode_name: 'subscription_headers' | ||
}, | ||
sections: [ | ||
{id: 1, permaId: 100} | ||
] | ||
}); | ||
const view = new SectionItemView({ | ||
entry, | ||
model: entry.sections.get(1) | ||
}); | ||
|
||
const user = userEvent.setup(); | ||
const {getByRole} = render(view); | ||
await user.click(getByRole('link', {name: 'Set cutoff point'})); | ||
|
||
expect(entry.metadata.configuration.get('cutoff_section_perma_id')).toEqual(100); | ||
}); | ||
|
||
it('offers menu item to reset cutoff section if site has cutoff mode', async () => { | ||
const entry = createEntry({ | ||
site: { | ||
cutoff_mode_name: 'subscription_headers' | ||
}, | ||
metadata: {configuration: {cutoff_section_perma_id: 101}}, | ||
sections: [ | ||
{id: 1, permaId: 100}, | ||
{id: 2, permaId: 101} | ||
] | ||
}); | ||
const view = new SectionItemView({ | ||
entry, | ||
model: entry.sections.get(2) | ||
}); | ||
|
||
const user = userEvent.setup(); | ||
const {getByRole} = render(view); | ||
await user.click(getByRole('link', {name: 'Remove cutoff point'})); | ||
|
||
expect(entry.metadata.configuration.get('cutoff_section_perma_id')).toBeUndefined(); | ||
}); | ||
|
||
it('updates menu item when cutoff section changes', () => { | ||
const entry = createEntry({ | ||
site: { | ||
cutoff_mode_name: 'subscription_headers' | ||
}, | ||
sections: [ | ||
{id: 1, permaId: 100}, | ||
{id: 2, permaId: 101} | ||
] | ||
}); | ||
const view = new SectionItemView({ | ||
entry, | ||
model: entry.sections.get(2) | ||
}); | ||
|
||
const {queryByRole} = render(view); | ||
entry.metadata.configuration.set('cutoff_section_perma_id', 101) | ||
|
||
expect(queryByRole('link', {name: 'Remove cutoff point'})).not.toBeNull(); | ||
}); | ||
|
||
it('renders cutoff indicator', () => { | ||
const entry = createEntry({ | ||
site: { | ||
cutoff_mode_name: 'subscription_headers' | ||
}, | ||
sections: [ | ||
{id: 1, permaId: 100}, | ||
{id: 2, permaId: 101} | ||
] | ||
}); | ||
const view = new SectionItemView({ | ||
entry, | ||
model: entry.sections.get(2) | ||
}); | ||
|
||
const {queryByText} = render(view); | ||
entry.metadata.configuration.set('cutoff_section_perma_id', 101) | ||
|
||
expect(queryByText('Cutoff point')).toBeVisible(); | ||
}); | ||
|
||
it('does not render cutoff indicator if cutoff section not set', () => { | ||
const entry = createEntry({ | ||
site: { | ||
cutoff_mode_name: 'subscription_headers' | ||
}, | ||
sections: [ | ||
{id: 1, permaId: 100}, | ||
{id: 2, permaId: 101} | ||
] | ||
}); | ||
const view = new SectionItemView({ | ||
entry, | ||
model: entry.sections.get(2) | ||
}); | ||
|
||
const {queryByText} = render(view); | ||
|
||
expect(queryByText('Cutoff point')).not.toBeVisible(); | ||
}); | ||
|
||
it('does not render cutoff indicator if site does not have cutoff mode', () => { | ||
const entry = createEntry({ | ||
metadata: {configuration: {cutoff_section_perma_id: 101}}, | ||
sections: [ | ||
{id: 1, permaId: 100}, | ||
{id: 2, permaId: 101} | ||
] | ||
}); | ||
const view = new SectionItemView({ | ||
entry, | ||
model: entry.sections.get(2) | ||
}); | ||
|
||
const {queryByText} = render(view); | ||
|
||
expect(queryByText('Cutoff point')).not.toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.