-
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.
Display and manage cutoff section in entry outline
REDMINE-20674
- Loading branch information
Showing
16 changed files
with
315 additions
and
50 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
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
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
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
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,27 @@ | ||
import {Object} from 'pageflow/ui'; | ||
|
||
export const Cutoff = Object.extend({ | ||
initialize({entry}) { | ||
this.entry = entry; | ||
|
||
this.listenTo(this.entry.metadata.configuration, | ||
'change:cutoff_section_perma_id', | ||
() => this.trigger('change')); | ||
}, | ||
|
||
isEnabled() { | ||
return !!this.entry.site.get('cutoff_mode_name'); | ||
}, | ||
|
||
isAtSection(section) { | ||
return this.entry.metadata.configuration.get('cutoff_section_perma_id') === section.get('permaId'); | ||
}, | ||
|
||
reset() { | ||
this.entry.metadata.configuration.unset('cutoff_section_perma_id'); | ||
}, | ||
|
||
setSection(section) { | ||
this.entry.metadata.configuration.set('cutoff_section_perma_id', section.get('permaId')); | ||
} | ||
}); |
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
Oops, something went wrong.