Skip to content

Commit

Permalink
Do not show cutoff mode indicator on newly created sections
Browse files Browse the repository at this point in the history
When no cutoff section has been set, new sections, which do not have a
perma id yet, were recognized as matching the cutoff section perma id.

REDMINE-20674
  • Loading branch information
tf committed Nov 8, 2024
1 parent d801aa8 commit d8a895d
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 d8a895d

Please sign in to comment.