Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong committed Nov 21, 2024
1 parent 8268e4d commit 9943d12
Show file tree
Hide file tree
Showing 3 changed files with 327 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ describe('formatContentModel', () => {
it('Has pending format, callback returns true, preserve pending format', () => {
core.format.pendingFormat = {
format: mockedFormat1,
paragraphFormat: mockedFormat2,
insertPoint: {
node: mockedStartContainer1,
offset: mockedStartOffset1,
Expand All @@ -679,9 +680,61 @@ describe('formatContentModel', () => {
} as any);
});

it('Has pending format, callback returns false, preserve pending format', () => {
it('Has pending format, callback returns true, preserve paragraph pending format', () => {
core.format.pendingFormat = {
format: mockedFormat1,
paragraphFormat: mockedFormat2,
insertPoint: {
node: mockedStartContainer1,
offset: mockedStartOffset1,
},
};

formatContentModel(core, (model, context) => {
context.newPendingParagraphFormat = 'preserve';
return true;
});

expect(core.format.pendingFormat).toEqual({
format: undefined,
paragraphFormat: mockedFormat2,
insertPoint: {
node: mockedStartContainer2,
offset: mockedStartOffset2,
},
} as any);
});

it('Has pending format, callback returns true, preserve both pending format', () => {
core.format.pendingFormat = {
format: mockedFormat1,
paragraphFormat: mockedFormat2,
insertPoint: {
node: mockedStartContainer1,
offset: mockedStartOffset1,
},
};

formatContentModel(core, (model, context) => {
context.newPendingFormat = 'preserve';
context.newPendingParagraphFormat = 'preserve';
return true;
});

expect(core.format.pendingFormat).toEqual({
format: mockedFormat1,
paragraphFormat: mockedFormat2,
insertPoint: {
node: mockedStartContainer2,
offset: mockedStartOffset2,
},
} as any);
});

it('Has pending format, callback returns false, preserve both pending format', () => {
core.format.pendingFormat = {
format: mockedFormat1,
paragraphFormat: mockedFormat2,
insertPoint: {
node: mockedStartContainer1,
offset: mockedStartOffset1,
Expand All @@ -690,12 +743,13 @@ describe('formatContentModel', () => {

formatContentModel(core, (model, context) => {
context.newPendingFormat = 'preserve';
context.newPendingParagraphFormat = 'preserve';
return false;
});

expect(core.format.pendingFormat).toEqual({
format: mockedFormat1,
paragraphFormat: undefined,
paragraphFormat: mockedFormat2,
insertPoint: {
node: mockedStartContainer2,
offset: mockedStartOffset2,
Expand All @@ -719,6 +773,22 @@ describe('formatContentModel', () => {
});
});

it('No pending format, callback returns true, new paragraph format', () => {
formatContentModel(core, (model, context) => {
context.newPendingParagraphFormat = mockedFormat2;
return true;
});

expect(core.format.pendingFormat).toEqual({
format: undefined,
paragraphFormat: mockedFormat2,
insertPoint: {
node: mockedStartContainer2,
offset: mockedStartOffset2,
},
});
});

it('No pending format, callback returns false, new format', () => {
formatContentModel(core, (model, context) => {
context.newPendingFormat = mockedFormat2;
Expand Down Expand Up @@ -783,6 +853,30 @@ describe('formatContentModel', () => {
});
});

it('Has pending format, callback returns false, new paragraph format', () => {
core.format.pendingFormat = {
paragraphFormat: mockedFormat1,
insertPoint: {
node: mockedStartContainer1,
offset: mockedStartOffset1,
},
};

formatContentModel(core, (model, context) => {
context.newPendingParagraphFormat = mockedFormat2;
return false;
});

expect(core.format.pendingFormat).toEqual({
format: undefined,
paragraphFormat: mockedFormat2,
insertPoint: {
node: mockedStartContainer2,
offset: mockedStartOffset2,
},
});
});

it('Has pending format, callback returns false, preserve format, selection is not collapsed', () => {
core.format.pendingFormat = {
format: mockedFormat1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ describe('FormatPlugin', () => {
const mockedFormat = {
fontSize: '10px',
};
const mockedFormat2 = {
lineSpace: 2,
};
let applyPendingFormatSpy: jasmine.Spy;

beforeEach(() => {
Expand Down Expand Up @@ -49,6 +52,7 @@ describe('FormatPlugin', () => {

(state.pendingFormat = {
format: mockedFormat,
paragraphFormat: mockedFormat2,
} as any),
plugin.initialize(editor);

Expand All @@ -60,7 +64,12 @@ describe('FormatPlugin', () => {
plugin.dispose();

expect(applyPendingFormatSpy).toHaveBeenCalledTimes(1);
expect(applyPendingFormatSpy).toHaveBeenCalledWith(editor, 'a', mockedFormat, undefined);
expect(applyPendingFormatSpy).toHaveBeenCalledWith(
editor,
'a',
mockedFormat,
mockedFormat2
);
expect(state.pendingFormat).toBeNull();
});

Expand Down Expand Up @@ -111,7 +120,7 @@ describe('FormatPlugin', () => {
const state = plugin.getState();

state.pendingFormat = {
format: mockedFormat,
paragraphFormat: mockedFormat2,
} as any;

plugin.onPluginEvent({
Expand All @@ -122,7 +131,7 @@ describe('FormatPlugin', () => {

expect(applyPendingFormatSpy).not.toHaveBeenCalled();
expect(state.pendingFormat).toEqual({
format: mockedFormat,
paragraphFormat: mockedFormat2,
} as any);
});

Expand Down
Loading

0 comments on commit 9943d12

Please sign in to comment.