Skip to content

Commit

Permalink
Merge pull request #2174 from tf/cutoff-indicator-fix
Browse files Browse the repository at this point in the history
Do not show cutoff mode indicator on newly created sections
  • Loading branch information
tf authored Nov 11, 2024
2 parents d801aa8 + d8a895d commit 51dd0dd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
34 changes: 34 additions & 0 deletions entry_types/scrolled/package/spec/editor/models/Cutoff-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,38 @@ describe('Cutoff', () => {

expect(entry.metadata.configuration.get('cutoff_section_perma_id')).toBeUndefined();
});

it('reports cutoff to be at section with matching perma id', () => {
const entry = createEntry({
metadata: {configuration: {cutoff_section_perma_id: 100}},
sections: [
{id: 1, permaId: 100},
{id: 2, permaId: 101},
]
});

expect(entry.cutoff.isAtSection(entry.sections.get(1))).toEqual(true);
});

it('does not report cutoff to be at section with other perma id', () => {
const entry = createEntry({
metadata: {configuration: {cutoff_section_perma_id: 100}},
sections: [
{id: 1, permaId: 100},
{id: 2, permaId: 101},
]
});

expect(entry.cutoff.isAtSection(entry.sections.get(2))).toEqual(false);
});

it('does not report cutoff to be at unsafed section when not set', () => {
const entry = createEntry({
sections: [
{id: undefined , permaId: undefined}
]
});

expect(entry.cutoff.isAtSection(entry.sections.first())).toEqual(false);
});
});
5 changes: 4 additions & 1 deletion entry_types/scrolled/package/src/editor/models/Cutoff.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export const Cutoff = Object.extend({
},

isAtSection(section) {
return this.entry.metadata.configuration.get('cutoff_section_perma_id') === section.get('permaId');
const cutoffSectionPermaId =
this.entry.metadata.configuration.get('cutoff_section_perma_id');

return !!cutoffSectionPermaId && cutoffSectionPermaId === section.get('permaId');
},

reset() {
Expand Down

0 comments on commit 51dd0dd

Please sign in to comment.