Skip to content

Commit

Permalink
Reset cutoff when cutoff section is destroyed
Browse files Browse the repository at this point in the history
REDMINE-20674
  • Loading branch information
tf committed Jun 20, 2024
1 parent b426ff8 commit 2e4ac93
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
22 changes: 22 additions & 0 deletions entry_types/scrolled/package/spec/editor/models/Cutoff-spec.js
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();
});
});
6 changes: 6 additions & 0 deletions entry_types/scrolled/package/src/editor/models/Cutoff.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export const Cutoff = Object.extend({
this.listenTo(this.entry.metadata.configuration,
'change:cutoff_section_perma_id',
() => this.trigger('change'));

this.listenTo(this.entry.sections, 'destroy', (section) => {
if (this.isAtSection(section)) {
this.reset();
}
});
},

isEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {deleteContentElement} from './deleteContentElement';
export const ScrolledEntry = Entry.extend({
setupFromEntryTypeSeed(seed) {
this.consentVendors = new ConsentVendors({hostMatchers: seed.consentVendorHostMatchers});
this.cutoff = new Cutoff({entry: this});

this.contentElements = new ContentElementsCollection(seed.collections.contentElements);
this.sections = new SectionsCollection(seed.collections.sections,
Expand All @@ -25,6 +24,8 @@ export const ScrolledEntry = Entry.extend({

this.sections.sort();

this.cutoff = new Cutoff({entry: this});

editor.failures.watch(this.contentElements);
editor.failures.watch(this.sections);
editor.failures.watch(this.chapters);
Expand Down

0 comments on commit 2e4ac93

Please sign in to comment.