diff --git a/src/m365/spo/commands/page/canvasContent.ts b/src/m365/spo/commands/page/canvasContent.ts index d040b794ae..24b3d853e8 100644 --- a/src/m365/spo/commands/page/canvasContent.ts +++ b/src/m365/spo/commands/page/canvasContent.ts @@ -1,9 +1,11 @@ +import { ClientSideControlPosition, ZoneGroupMetadata } from "./clientsidepages"; + export interface Control { controlType?: number; displayMode: number; emphasis?: { zoneEmphasis?: number }; id?: string; - position: ControlPosition; + position: ClientSideControlPosition; reservedHeight?: number; reservedWidth?: number; webPartData?: any; @@ -44,22 +46,4 @@ export interface BackgroundControl { }, dataVersion: string; } -} - -interface ControlPosition { - controlIndex?: number; - layoutIndex: number; - sectionFactor: number; - sectionIndex: number; - zoneIndex: number; - isLayoutReflowOnTop?: boolean; - zoneId?: string; -} - -interface ZoneGroupMetadata { - type: number; - isExpanded: boolean; - showDividerLine: boolean; - iconAlignment: string; - displayName?: string; } \ No newline at end of file diff --git a/src/m365/spo/commands/page/clientsidepages.ts b/src/m365/spo/commands/page/clientsidepages.ts index 032a448b90..1467884268 100644 --- a/src/m365/spo/commands/page/clientsidepages.ts +++ b/src/m365/spo/commands/page/clientsidepages.ts @@ -114,7 +114,7 @@ function getGUID(): string { /** * Column size factor. Max value is 12 (= one column), other options are 8,6,4 or 0 */ -type CanvasColumnFactorType = 0 | 2 | 4 | 6 | 8 | 12; +export type CanvasColumnFactorType = 0 | 2 | 4 | 6 | 8 | 12; /** * Gets the next order value 1 based for the provided collection @@ -265,7 +265,8 @@ function reindex(collection?: { order: number, columns?: { order: number }[], co */ export class ClientSidePage { public sections: CanvasSection[] = []; - + public pageSettings?: PageSettings; + public backgroundSettings?: BackgroundSettings; /** * Converts a json object to an escaped string appropriate for use in attributes when storing client-side controls * @@ -324,8 +325,15 @@ export class ClientSidePage { html.push(this.sections[i].toHtml()); } - html.push(""); + if (this.pageSettings) { + html.push(this.pageSettings.toHtml()); + } + if (this.backgroundSettings) { + html.push(this.backgroundSettings.toHtml()); + } + + html.push(""); return html.join(""); } @@ -344,20 +352,26 @@ export class ClientSidePage { getBoundedDivMarkup(html, /
test
","emphasis":{"zoneEmphasis":0},"zoneGroupMetadata":{"type":1,"isExpanded":true,"showDividerLine":false,"iconAlignment":"left","displayName":"Test"}},{"controlType":0,"pageSettingsSlice":{"isDefaultDescription":true,"isDefaultThumbnail":true,"isSpellCheckEnabled":true,"globalRichTextStylingVersion":1,"rtePageSettings":{"contentVersion":5,"indentationVersion":2},"isEmailReady":false,"webPartsPageSettings":{"isTitleHeadingLevelsEnabled":false}}}]` + }; + } + + if (opts.url === `https://contoso.sharepoint.com/sites/team-a/_api/web/getclientsidewebparts()`) { + return clientSideWebParts; + } + + throw 'Invalid request'; + }); + + const postStub = sinon.stub(request, 'post').callsFake(async (opts) => { + if (opts.url === `https://contoso.sharepoint.com/sites/team-a/_api/sitepages/pages/GetByUrl('sitepages/page.aspx')/SavePageAsDraft`) { + return; + } + + throw 'Invalid request'; + }); + + await command.action(logger, + { + options: { + pageName: 'page.aspx', + webUrl: 'https://contoso.sharepoint.com/sites/team-a', + webPartId: 'e377ea37-9047-43b9-8cdb-a761be2f8e09', + order: 1 + } + }); + assert.strictEqual(replaceId(JSON.stringify(postStub.lastCall.args[0].data)), '{"CanvasContent1":"[{\\"controlType\\":3,\\"displayMode\\":2,\\"id\\":\\"89c644b3-f69c-4e84-85d7-dfa04c6163b5\\",\\"position\\":{\\"controlIndex\\":1,\\"sectionFactor\\":12,\\"sectionIndex\\":1,\\"zoneIndex\\":1,\\"zoneId\\":\\"e524fc79-e526-4da5-82e6-361018dedc67\\"},\\"webPartId\\":\\"e377ea37-9047-43b9-8cdb-a761be2f8e09\\",\\"emphasis\\":{},\\"zoneGroupMetadata\\":{\\"type\\":1,\\"isExpanded\\":true,\\"showDividerLine\\":false,\\"iconAlignment\\":\\"left\\",\\"displayName\\":\\"Test\\"},\\"webPartData\\":{\\"dataVersion\\":\\"1.0\\",\\"description\\":\\"Display a key location on a map\\",\\"id\\":\\"e377ea37-9047-43b9-8cdb-a761be2f8e09\\",\\"instanceId\\":\\"89c644b3-f69c-4e84-85d7-dfa04c6163b5\\",\\"properties\\":{\\"pushPins\\":[],\\"maxNumberOfPushPins\\":1,\\"shouldShowPushPinTitle\\":true,\\"zoomLevel\\":12,\\"mapType\\":\\"road\\"},\\"title\\":\\"Bing maps\\"}},{\\"controlType\\":4,\\"editorType\\":\\"CKEditor\\",\\"id\\":\\"24cebf73-d376-48e5-9b76-39b967c8dfd9\\",\\"position\\":{\\"controlIndex\\":2,\\"sectionFactor\\":12,\\"sectionIndex\\":1,\\"zoneIndex\\":1,\\"zoneId\\":\\"e524fc79-e526-4da5-82e6-361018dedc67\\"},\\"addedFromPersistedData\\":true,\\"innerHTML\\":\\"test
\\",\\"emphasis\\":{\\"zoneEmphasis\\":0},\\"zoneGroupMetadata\\":{\\"type\\":1,\\"isExpanded\\":true,\\"showDividerLine\\":false,\\"iconAlignment\\":\\"left\\",\\"displayName\\":\\"Test\\"}},{\\"controlType\\":0,\\"pageSettingsSlice\\":{\\"isDefaultDescription\\":true,\\"isDefaultThumbnail\\":true,\\"isSpellCheckEnabled\\":true,\\"globalRichTextStylingVersion\\":1,\\"rtePageSettings\\":{\\"contentVersion\\":5,\\"indentationVersion\\":2},\\"isEmailReady\\":false,\\"webPartsPageSettings\\":{\\"isTitleHeadingLevelsEnabled\\":false}}}]"}'); + }); + + it('adds web part to a column with background settings order 1 specified', async () => { + sinon.stub(request, 'get').callsFake(async (opts) => { + if (opts.url === `https://contoso.sharepoint.com/sites/team-a/_api/sitepages/pages/GetByUrl('sitepages/page.aspx')`) { + return { + "IsPageCheckedOutToCurrentUser": true, + "CanvasContent1": `[{"controlType":4,"editorType":"CKEditor","id":"24cebf73-d376-48e5-9b76-39b967c8dfd9","position":{"controlIndex":1,"sectionFactor":12,"sectionIndex":1,"zoneIndex":1,"zoneId":"e524fc79-e526-4da5-82e6-361018dedc67"},"addedFromPersistedData":true,"zoneGroupMetadata":{"type":0,"isExpanded":true,"showDividerLine":false,"iconAlignment":"left","displayName":"Test"},"innerHTML":"test
"},{"controlType":0,"pageSettingsSlice":{"isDefaultDescription":true,"isDefaultThumbnail":true,"isSpellCheckEnabled":true,"globalRichTextStylingVersion":1,"rtePageSettings":{"contentVersion":5,"indentationVersion":2},"isEmailReady":false,"webPartsPageSettings":{"isTitleHeadingLevelsEnabled":false}}},{"controlType":14,"webPartData":{"properties":{"zoneBackground":{"e524fc79-e526-4da5-82e6-361018dedc67":{"type":"gradient","gradient":"radial-gradient(55.05% 96.28% at -5.05% -8.89%, #585984 0%, rgba(88, 89, 132, 0) 100%),linear-gradient(72.98deg, #AD8D8E 0.02%, #2A2A56 102.53%)","useLightText":true,"overlay":{"color":"#000000","opacity":60}}}},"serverProcessedContent":{"htmlStrings":{},"searchablePlainTexts":{},"imageSources":{},"links":{}},"dataVersion":"1.0"}}]` + }; + } + + if (opts.url === `https://contoso.sharepoint.com/sites/team-a/_api/web/getclientsidewebparts()`) { + return clientSideWebParts; + } + + throw 'Invalid request'; + }); + + const postStub = sinon.stub(request, 'post').callsFake(async (opts) => { + if (opts.url === `https://contoso.sharepoint.com/sites/team-a/_api/sitepages/pages/GetByUrl('sitepages/page.aspx')/SavePageAsDraft`) { + return; + } + + throw 'Invalid request'; + }); + + await command.action(logger, + { + options: { + pageName: 'page.aspx', + webUrl: 'https://contoso.sharepoint.com/sites/team-a', + webPartId: 'e377ea37-9047-43b9-8cdb-a761be2f8e09', + order: 1 + } + }); + assert.strictEqual(replaceId(JSON.stringify(postStub.lastCall.args[0].data)), '{"CanvasContent1":"[{\\"controlType\\":3,\\"displayMode\\":2,\\"id\\":\\"89c644b3-f69c-4e84-85d7-dfa04c6163b5\\",\\"position\\":{\\"controlIndex\\":1,\\"sectionFactor\\":12,\\"sectionIndex\\":1,\\"zoneIndex\\":1,\\"zoneId\\":\\"e524fc79-e526-4da5-82e6-361018dedc67\\"},\\"webPartId\\":\\"e377ea37-9047-43b9-8cdb-a761be2f8e09\\",\\"emphasis\\":{},\\"zoneGroupMetadata\\":{\\"type\\":0,\\"isExpanded\\":true,\\"showDividerLine\\":false,\\"iconAlignment\\":\\"left\\",\\"displayName\\":\\"Test\\"},\\"webPartData\\":{\\"dataVersion\\":\\"1.0\\",\\"description\\":\\"Display a key location on a map\\",\\"id\\":\\"e377ea37-9047-43b9-8cdb-a761be2f8e09\\",\\"instanceId\\":\\"89c644b3-f69c-4e84-85d7-dfa04c6163b5\\",\\"properties\\":{\\"pushPins\\":[],\\"maxNumberOfPushPins\\":1,\\"shouldShowPushPinTitle\\":true,\\"zoomLevel\\":12,\\"mapType\\":\\"road\\"},\\"title\\":\\"Bing maps\\"}},{\\"controlType\\":4,\\"editorType\\":\\"CKEditor\\",\\"id\\":\\"24cebf73-d376-48e5-9b76-39b967c8dfd9\\",\\"position\\":{\\"controlIndex\\":2,\\"sectionFactor\\":12,\\"sectionIndex\\":1,\\"zoneIndex\\":1,\\"zoneId\\":\\"e524fc79-e526-4da5-82e6-361018dedc67\\"},\\"addedFromPersistedData\\":true,\\"zoneGroupMetadata\\":{\\"type\\":0,\\"isExpanded\\":true,\\"showDividerLine\\":false,\\"iconAlignment\\":\\"left\\",\\"displayName\\":\\"Test\\"},\\"innerHTML\\":\\"test
\\"},{\\"controlType\\":0,\\"pageSettingsSlice\\":{\\"isDefaultDescription\\":true,\\"isDefaultThumbnail\\":true,\\"isSpellCheckEnabled\\":true,\\"globalRichTextStylingVersion\\":1,\\"rtePageSettings\\":{\\"contentVersion\\":5,\\"indentationVersion\\":2},\\"isEmailReady\\":false,\\"webPartsPageSettings\\":{\\"isTitleHeadingLevelsEnabled\\":false}}},{\\"controlType\\":14,\\"webPartData\\":{\\"properties\\":{\\"zoneBackground\\":{\\"e524fc79-e526-4da5-82e6-361018dedc67\\":{\\"type\\":\\"gradient\\",\\"gradient\\":\\"radial-gradient(55.05% 96.28% at -5.05% -8.89%, #585984 0%, rgba(88, 89, 132, 0) 100%),linear-gradient(72.98deg, #AD8D8E 0.02%, #2A2A56 102.53%)\\",\\"useLightText\\":true,\\"overlay\\":{\\"color\\":\\"#000000\\",\\"opacity\\":60}}}},\\"serverProcessedContent\\":{\\"htmlStrings\\":{},\\"searchablePlainTexts\\":{},\\"imageSources\\":{},\\"links\\":{}},\\"dataVersion\\":\\"1.0\\"}}]"}'); + }); + + it('adds web part to a column with background settings and collapsible section', async () => { + sinon.stub(request, 'get').callsFake(async (opts) => { + if (opts.url === `https://contoso.sharepoint.com/sites/team-a/_api/sitepages/pages/GetByUrl('sitepages/page.aspx')`) { + return { + "IsPageCheckedOutToCurrentUser": true, + "CanvasContent1": `[{"controlType":4,"editorType":"CKEditor","id":"24cebf73-d376-48e5-9b76-39b967c8dfd9","position":{"controlIndex":1,"sectionFactor":12,"sectionIndex":1,"zoneIndex":1,"zoneId":"e524fc79-e526-4da5-82e6-361018dedc67"},"addedFromPersistedData":true,"zoneGroupMetadata":{"type":1,"isExpanded":true,"showDividerLine":false,"iconAlignment":"left","displayName":"Test"},"innerHTML":"test
"},{"controlType":0,"pageSettingsSlice":{"isDefaultDescription":true,"isDefaultThumbnail":true,"isSpellCheckEnabled":true,"globalRichTextStylingVersion":1,"rtePageSettings":{"contentVersion":5,"indentationVersion":2},"isEmailReady":false,"webPartsPageSettings":{"isTitleHeadingLevelsEnabled":false}}},{"controlType":14,"webPartData":{"properties":{"zoneBackground":{"e524fc79-e526-4da5-82e6-361018dedc67":{"type":"gradient","gradient":"radial-gradient(55.05% 96.28% at -5.05% -8.89%, #585984 0%, rgba(88, 89, 132, 0) 100%), linear-gradient(72.98deg, #AD8D8E 0.02%, #2A2A56 102.53%)","useLightText":true,"overlay":{"color":"#000000","opacity":60}}}},"serverProcessedContent":{"htmlStrings":{},"searchablePlainTexts":{},"imageSources":{},"links":{}},"dataVersion":"1.0"}}]` + }; + } + + if (opts.url === `https://contoso.sharepoint.com/sites/team-a/_api/web/getclientsidewebparts()`) { + return clientSideWebParts; + } + + throw 'Invalid request'; + }); + + const postStub = sinon.stub(request, 'post').callsFake(async (opts) => { + if (opts.url === `https://contoso.sharepoint.com/sites/team-a/_api/sitepages/pages/GetByUrl('sitepages/page.aspx')/SavePageAsDraft`) { + return; + } + + throw 'Invalid request'; + }); + + await command.action(logger, + { + options: { + pageName: 'page.aspx', + webUrl: 'https://contoso.sharepoint.com/sites/team-a', + webPartId: 'e377ea37-9047-43b9-8cdb-a761be2f8e09' + } + }); + assert.strictEqual(replaceId(JSON.stringify(postStub.lastCall.args[0].data)), '{"CanvasContent1":"[{\\"controlType\\":4,\\"editorType\\":\\"CKEditor\\",\\"id\\":\\"24cebf73-d376-48e5-9b76-39b967c8dfd9\\",\\"position\\":{\\"controlIndex\\":1,\\"sectionFactor\\":12,\\"sectionIndex\\":1,\\"zoneIndex\\":1,\\"zoneId\\":\\"e524fc79-e526-4da5-82e6-361018dedc67\\"},\\"addedFromPersistedData\\":true,\\"zoneGroupMetadata\\":{\\"type\\":1,\\"isExpanded\\":true,\\"showDividerLine\\":false,\\"iconAlignment\\":\\"left\\",\\"displayName\\":\\"Test\\"},\\"innerHTML\\":\\"test
\\"},{\\"controlType\\":3,\\"displayMode\\":2,\\"id\\":\\"89c644b3-f69c-4e84-85d7-dfa04c6163b5\\",\\"position\\":{\\"controlIndex\\":2,\\"sectionFactor\\":12,\\"sectionIndex\\":1,\\"zoneIndex\\":1,\\"zoneId\\":\\"e524fc79-e526-4da5-82e6-361018dedc67\\"},\\"webPartId\\":\\"e377ea37-9047-43b9-8cdb-a761be2f8e09\\",\\"emphasis\\":{},\\"zoneGroupMetadata\\":{\\"type\\":1,\\"isExpanded\\":true,\\"showDividerLine\\":false,\\"iconAlignment\\":\\"left\\",\\"displayName\\":\\"Test\\"},\\"webPartData\\":{\\"dataVersion\\":\\"1.0\\",\\"description\\":\\"Display a key location on a map\\",\\"id\\":\\"e377ea37-9047-43b9-8cdb-a761be2f8e09\\",\\"instanceId\\":\\"89c644b3-f69c-4e84-85d7-dfa04c6163b5\\",\\"properties\\":{\\"pushPins\\":[],\\"maxNumberOfPushPins\\":1,\\"shouldShowPushPinTitle\\":true,\\"zoomLevel\\":12,\\"mapType\\":\\"road\\"},\\"title\\":\\"Bing maps\\"}},{\\"controlType\\":0,\\"pageSettingsSlice\\":{\\"isDefaultDescription\\":true,\\"isDefaultThumbnail\\":true,\\"isSpellCheckEnabled\\":true,\\"globalRichTextStylingVersion\\":1,\\"rtePageSettings\\":{\\"contentVersion\\":5,\\"indentationVersion\\":2},\\"isEmailReady\\":false,\\"webPartsPageSettings\\":{\\"isTitleHeadingLevelsEnabled\\":false}}},{\\"controlType\\":14,\\"webPartData\\":{\\"properties\\":{\\"zoneBackground\\":{\\"e524fc79-e526-4da5-82e6-361018dedc67\\":{\\"type\\":\\"gradient\\",\\"gradient\\":\\"radial-gradient(55.05% 96.28% at -5.05% -8.89%, #585984 0%, rgba(88, 89, 132, 0) 100%), linear-gradient(72.98deg, #AD8D8E 0.02%, #2A2A56 102.53%)\\",\\"useLightText\\":true,\\"overlay\\":{\\"color\\":\\"#000000\\",\\"opacity\\":60}}}},\\"serverProcessedContent\\":{\\"htmlStrings\\":{},\\"searchablePlainTexts\\":{},\\"imageSources\\":{},\\"links\\":{}},\\"dataVersion\\":\\"1.0\\"}}]"}'); + }); + it('correctly handles sections in reverse order', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { if ((opts.url as string).indexOf(`/_api/sitepages/pages/GetByUrl('sitepages/page.aspx')`) > -1) { diff --git a/src/m365/spo/commands/page/page-clientsidewebpart-add.ts b/src/m365/spo/commands/page/page-clientsidewebpart-add.ts index 3327358892..5c6b94e7aa 100644 --- a/src/m365/spo/commands/page/page-clientsidewebpart-add.ts +++ b/src/m365/spo/commands/page/page-clientsidewebpart-add.ts @@ -270,7 +270,8 @@ class SpoPageClientSideWebPartAddCommand extends SpoCommand { id: webPart.id, position: Object.assign({}, control.position), webPartId: webPart.webPartId, - emphasis: {} + emphasis: {}, + zoneGroupMetadata: control.zoneGroupMetadata }, webPart); if (!control.controlType) { diff --git a/src/m365/spo/commands/page/page-section-add.ts b/src/m365/spo/commands/page/page-section-add.ts index 8aa2909615..de4eb61771 100644 --- a/src/m365/spo/commands/page/page-section-add.ts +++ b/src/m365/spo/commands/page/page-section-add.ts @@ -7,7 +7,7 @@ import { validation } from '../../../../utils/validation.js'; import SpoCommand from '../../../base/SpoCommand.js'; import commands from '../../commands.js'; import { BackgroundControl, Control } from './canvasContent.js'; -import { CanvasSectionTemplate } from './clientsidepages.js'; +import { CanvasColumnFactorType, CanvasSectionTemplate } from './clientsidepages.js'; interface CommandArgs { options: Options; @@ -372,7 +372,7 @@ class SpoPageSectionAddCommand extends SpoCommand { return columns; } - private getColumn(zoneIndex: number, sectionIndex: number, sectionFactor: number, args: CommandArgs, zoneId?: string): Control { + private getColumn(zoneIndex: number, sectionIndex: number, sectionFactor: CanvasColumnFactorType, args: CommandArgs, zoneId?: string): Control { const { zoneEmphasis, isCollapsibleSection, isExpanded, showDivider, iconAlignment, collapsibleTitle } = args.options; const columnValue: Control = { displayMode: 2, diff --git a/src/m365/spo/commands/page/page-text-add.spec.ts b/src/m365/spo/commands/page/page-text-add.spec.ts index a1d3192fa4..f58bd556ef 100644 --- a/src/m365/spo/commands/page/page-text-add.spec.ts +++ b/src/m365/spo/commands/page/page-text-add.spec.ts @@ -17,7 +17,6 @@ import command from './page-text-add.js'; describe(commands.PAGE_TEXT_ADD, () => { let log: string[]; let logger: Logger; - let loggerLogSpy: sinon.SinonSpy; let commandInfo: CommandInfo; let loggerLogToStderrSpy: sinon.SinonSpy; @@ -49,7 +48,6 @@ describe(commands.PAGE_TEXT_ADD, () => { log.push(msg); } }; - loggerLogSpy = sinon.spy(logger, 'log'); loggerLogToStderrSpy = sinon.spy(logger, 'logToStderr'); }); @@ -75,7 +73,7 @@ describe(commands.PAGE_TEXT_ADD, () => { it('adds text to an empty modern page', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if ((opts.url as string).indexOf(`/_api/web/GetFileByServerRelativePath(DecodedUrl='/sites/team-a/SitePages/page.aspx')?$expand=ListItemAllFields/ClientSideApplicationId`) > -1) { + if (opts.url === `https://contoso.sharepoint.com/sites/team-a/_api/web/GetFileByServerRelativePath(DecodedUrl='/sites/team-a/SitePages/page.aspx')?$expand=ListItemAllFields/ClientSideApplicationId`) { return { ListItemAllFields: { CommentsDisabled: false, @@ -140,9 +138,9 @@ describe(commands.PAGE_TEXT_ADD, () => { throw 'Invalid request'; }); - sinon.stub(request, 'post').callsFake(async (opts) => { + const postStub = sinon.stub(request, 'post').callsFake(async (opts) => { if (opts.url === "https://contoso.sharepoint.com/sites/team-a/_api/web/GetFileByServerRelativePath(DecodedUrl='/sites/team-a/sitepages/page.aspx')/ListItemAllFields") { - return {}; + return; } throw 'Invalid request'; @@ -156,12 +154,15 @@ describe(commands.PAGE_TEXT_ADD, () => { text: 'Hello world' } }); - assert(loggerLogSpy.notCalled); + + const regex = /Hello world<\/p><\/div><\/div>
Hello world
Hello world
Hello world<\/p><\/div><\/div>
Hello world<\/p><\/div><\/div><\/div>/; + + assert.match(postStub.lastCall.args[0].data.CanvasContent1, regex); }); it('adds text in the specified order to a modern page which already had some text', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if ( - (opts.url as string).indexOf( - `/_api/web/GetFileByServerRelativePath(DecodedUrl='/sites/team-a/SitePages/page.aspx')?$expand=ListItemAllFields/ClientSideApplicationId` - ) > -1 + if (opts.url === + `https://contoso.sharepoint.com/sites/team-a/_api/web/GetFileByServerRelativePath(DecodedUrl='/sites/team-a/SitePages/page.aspx')?$expand=ListItemAllFields/ClientSideApplicationId` ) { return { ListItemAllFields: { @@ -496,9 +494,9 @@ describe(commands.PAGE_TEXT_ADD, () => { throw 'Invalid request'; }); - sinon.stub(request, 'post').callsFake(async (opts) => { + const postStub = sinon.stub(request, 'post').callsFake(async (opts) => { if (opts.url === "https://contoso.sharepoint.com/sites/team-a/_api/web/GetFileByServerRelativePath(DecodedUrl='/sites/team-a/sitepages/page.aspx')/ListItemAllFields") { - return {}; + return; } throw 'Invalid request'; @@ -513,16 +511,16 @@ describe(commands.PAGE_TEXT_ADD, () => { order: 2 } }); - assert(loggerLogSpy.notCalled); + + const regex = /
Hello world<\/p><\/div><\/div>
Hello world 1.1<\/p><\/div><\/div>
Hello world 2<\/p><\/div><\/div><\/div>/; + + assert.match(postStub.lastCall.args[0].data.CanvasContent1, regex); }); it('adds text to a modern page without specifying the page file extension', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if ( - (opts.url as string).indexOf( - `/_api/web/GetFileByServerRelativePath(DecodedUrl='/sites/team-a/SitePages/page.aspx')?$expand=ListItemAllFields/ClientSideApplicationId` - ) > -1 - ) { + if (opts.url === + `https://contoso.sharepoint.com/sites/team-a/_api/web/GetFileByServerRelativePath(DecodedUrl='/sites/team-a/SitePages/page.aspx')?$expand=ListItemAllFields/ClientSideApplicationId`) { return { ListItemAllFields: { CommentsDisabled: false, @@ -587,9 +585,9 @@ describe(commands.PAGE_TEXT_ADD, () => { throw 'Invalid request'; }); - sinon.stub(request, 'post').callsFake(async (opts) => { + const postStub = sinon.stub(request, 'post').callsFake(async (opts) => { if (opts.url === "https://contoso.sharepoint.com/sites/team-a/_api/web/GetFileByServerRelativePath(DecodedUrl='/sites/team-a/sitepages/page.aspx')/ListItemAllFields") { - return {}; + return; } throw 'Invalid request'; @@ -603,12 +601,460 @@ describe(commands.PAGE_TEXT_ADD, () => { text: 'Hello world' } }); - assert(loggerLogSpy.notCalled); + + const regex = /
Hello world<\/p><\/div><\/div>
Hello world<\/p><\/div><\/div>
text
text<\/p><\/div><\/div>
Hello world<\/p><\/div><\/div>
test
test<\/p><\/div><\/div>
Hello world<\/p><\/div><\/div>
test
test<\/p><\/div><\/div>
Hello world<\/p><\/div><\/div>
test
test<\/p><\/div><\/div>
Hello world<\/p><\/div><\/div>