Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export const hasListDefinition = (editor, numId, ilvl) => {
*/
export const changeNumIdSameAbstract = (numId, level, listType, editor) => {
const newId = getNewListId(editor, 'definitions');
const { abstract } = ListHelpers.getListDefinitionDetails({ numId, level, listType, editor });
const { abstract } = ListHelpers.getListDefinitionDetails({ numId, level, listType, editor }) || {};

const numbering = editor.converter.numbering;
const newNumbering = { ...numbering };
Expand Down Expand Up @@ -243,7 +243,7 @@ export const getNewListId = (editor, grouping = 'definitions') => {
* @param {import("prosemirror-model").NodeType} [params.listType] - The type of the list (e.g., 'orderedList', 'bulletList'). Required when generating new definitions
* @param {Object} params.editor - The editor instance containing converter and numbering data
* @param {number} [params.tries=0] - The number of recursion attempts to avoid infinite loops (max 1)
* @returns {Object} The list definition details
* @returns {Object | null} The list definition details or null if not found
*/
export const getListDefinitionDetails = ({ numId, level, listType, editor, tries = 0 }) => {
const { definitions, abstracts } = editor.converter.numbering;
Expand All @@ -263,17 +263,7 @@ export const getListDefinitionDetails = ({ numId, level, listType, editor, tries

const abstract = abstracts[abstractId];
if (!abstract) {
return {
start: null,
numFmt: null,
lvlText: null,
listNumberingType: null,
suffix: null,
justification: null,
customFormat: null,
abstract: null,
abstractId,
};
return null;
}

// Handle style link recursion (max 1 retry)
Expand Down Expand Up @@ -304,17 +294,7 @@ export const getListDefinitionDetails = ({ numId, level, listType, editor, tries
);

if (!listDefinition) {
return {
start: null,
numFmt: null,
lvlText: null,
suffix: null,
justification: null,
listNumberingType: null,
customFormat: null,
abstract,
abstractId,
};
return null;
}

// Extract level properties safely
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,20 +290,10 @@ describe('getListDefinitionDetails', () => {
editor: mockEditor,
});

expect(result).toEqual({
start: null,
numFmt: null,
lvlText: null,
listNumberingType: null,
customFormat: null,
justification: null,
suffix: null,
abstract: null,
abstractId: 'nonexistent', // The function correctly returns the abstractId even when abstract is not found
});
expect(result).toBeNull();
});

it('should return partial data when abstract exists but level definition is missing', () => {
it('should return null when abstract exists but level definition is missing', () => {
mockDefinitions[1] = {
elements: [
{
Expand All @@ -329,17 +319,7 @@ describe('getListDefinitionDetails', () => {
editor: mockEditor,
});

expect(result).toEqual({
start: null,
numFmt: null,
lvlText: null,
suffix: null,
justification: null,
listNumberingType: null,
customFormat: null,
abstract: mockAbstracts['abstract1'],
abstractId: 'abstract1',
});
expect(result).toBeNull();
});
});

Expand Down Expand Up @@ -464,8 +444,7 @@ describe('getListDefinitionDetails', () => {
});

// Should not recurse, should return null values since no level definition exists
expect(result.abstract).toBe(mockAbstracts['abstract1']);
expect(result.start).toBe(null);
expect(result).toBeNull();
});

it('should handle missing style definition gracefully', () => {
Expand Down Expand Up @@ -495,8 +474,7 @@ describe('getListDefinitionDetails', () => {
editor: mockEditor,
});

expect(result.abstract).toBe(mockAbstracts['abstract1']);
expect(result.start).toBe(null);
expect(result).toBeNull();
});

it('should handle incomplete style definition chain', () => {
Expand Down Expand Up @@ -539,8 +517,7 @@ describe('getListDefinitionDetails', () => {
editor: mockEditor,
});

expect(result.abstract).toBe(mockAbstracts['abstract1']);
expect(result.start).toBe(null);
expect(result).toBeNull();
});

it('should handle style definition with missing nested elements', () => {
Expand Down Expand Up @@ -582,8 +559,7 @@ describe('getListDefinitionDetails', () => {
editor: mockEditor,
});

expect(result.abstract).toBe(mockAbstracts['abstract1']);
expect(result.start).toBe(null);
expect(result).toBeNull();
});
});

Expand Down Expand Up @@ -643,8 +619,7 @@ describe('getListDefinitionDetails', () => {
editor: mockEditor,
});

expect(result.abstract).toBe(mockAbstracts['abstract1']);
expect(result.start).toBe(null);
expect(result).toBeNull();
});

it('should handle undefined editor or numbering data', () => {
Expand All @@ -663,17 +638,7 @@ describe('getListDefinitionDetails', () => {
editor: emptyEditor,
});

expect(result).toEqual({
start: null,
numFmt: null,
lvlText: null,
justification: null,
suffix: null,
listNumberingType: null,
customFormat: null,
abstract: null,
abstractId: undefined,
});
expect(result).toBeNull();
});
});

Expand Down Expand Up @@ -865,7 +830,13 @@ describe('getListDefinitionDetails', () => {
};
mockEditor.converter.numbering.abstracts['10'] = {
attributes: { 'w:abstractNumId': '10' },
elements: [],
elements: [
{
name: 'w:lvl',
attributes: { 'w:ilvl': '0' },
elements: [{ name: 'w:numFmt', attributes: { 'w:val': 'decimal' } }],
},
],
};

const newNumId = ListHelpers.changeNumIdSameAbstract(1, 0, 'orderedList', mockEditor);
Expand Down
Loading