Skip to content
Draft
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
1 change: 1 addition & 0 deletions packages/teams-js/src/internal/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ function convertToResumeContext(context: LoadContext): ResumeContext {
return {
entityId: context.entityId,
contentUrl: new URL(context.contentUrl),
...(context.subEntityId !== undefined && { subPageId: context.subEntityId }),
};
}

Expand Down
13 changes: 13 additions & 0 deletions packages/teams-js/src/public/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,13 @@ export interface ResumeContext {
* The content URL that is requested to be loaded
*/
contentUrl: URL;

/**
* The developer-defined unique ID for the sub-page to navigate to within the entity. This field is
* populated from the `subEntityId` parameter of the deep link that triggered the app load/resume.
* It corresponds to {@link app.PageInfo.subPageId | app.Context.page.subPageId}.
*/
subPageId?: string;
}

/**
Expand All @@ -1054,6 +1061,12 @@ export interface LoadContext {
* The content URL that is requested to be loaded
*/
contentUrl: string;

/**
* The developer-defined unique ID for the sub-entity to navigate to within the entity.
* Since {@link LoadContext} is deprecated, please use {@link ResumeContext.subPageId} instead.
*/
subEntityId?: string;
}

/** Represents information about a frame within a tab or dialog module. */
Expand Down
54 changes: 54 additions & 0 deletions packages/teams-js/test/public/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
FileOpenPreference,
LoadContext,
M365ContentAction,
ResumeContext,
SecondaryM365ContentIdName,
} from '../../src/public/interfaces';
import {
Expand Down Expand Up @@ -1114,6 +1115,36 @@ describe('Testing app capability', () => {
await utils.sendMessage('load', loadContext);
expect(handlerInvoked).toBe(true);
});

it(`app.lifecycle.registerOnResumeHandler should pass subPageId from load context subEntityId. context: ${context}`, async () => {
await utils.initializeWithContext(context);

const loadContextWithSubEntityId: LoadContext = {
entityId: 'testEntityId',
contentUrl: 'https://localhost:4000',
subEntityId: 'testSubPageId',
};

let receivedResumeContext: ResumeContext | undefined;
app.lifecycle.registerOnResumeHandler((ctx: ResumeContext) => {
receivedResumeContext = ctx;
});
await utils.sendMessage('load', loadContextWithSubEntityId);
expect(receivedResumeContext).toBeDefined();
expect(receivedResumeContext?.subPageId).toBe('testSubPageId');
});

it(`app.lifecycle.registerOnResumeHandler should have undefined subPageId when load context has no subEntityId. context: ${context}`, async () => {
await utils.initializeWithContext(context);

let receivedResumeContext: ResumeContext | undefined;
app.lifecycle.registerOnResumeHandler((ctx: ResumeContext) => {
receivedResumeContext = ctx;
});
await utils.sendMessage('load', loadContext);
expect(receivedResumeContext).toBeDefined();
expect(receivedResumeContext?.subPageId).toBeUndefined();
});
});
});
});
Expand Down Expand Up @@ -2104,6 +2135,29 @@ describe('Testing app capability', () => {
} as DOMMessageEvent);
expect(handlerInvoked).toBe(true);
});

it(`app.lifecycle.registerOnResumeHandler should pass subPageId from load context subEntityId. context: ${context}`, async () => {
await utils.initializeWithContext(context);

const loadContextWithSubEntityId: LoadContext = {
entityId: 'testEntityId',
contentUrl: 'https://localhost:4000',
subEntityId: 'testSubPageId',
};

let receivedResumeContext: ResumeContext | undefined;
app.lifecycle.registerOnResumeHandler((ctx: ResumeContext) => {
receivedResumeContext = ctx;
});
await utils.respondToFramelessMessage({
data: {
func: 'load',
args: [loadContextWithSubEntityId],
},
} as DOMMessageEvent);
expect(receivedResumeContext).toBeDefined();
expect(receivedResumeContext?.subPageId).toBe('testSubPageId');
});
});
});
});
Expand Down
21 changes: 21 additions & 0 deletions packages/teams-js/test/public/teamsAPIs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@ describe('Testing TeamsCore Capability', () => {

expect(handlerInvoked).toBe(true);
});

it(`teamsCore.registerOnLoadHandler should pass subEntityId from load context. context: ${context}`, async () => {
await utils.initializeWithContext(context);

const loadContextWithSubEntityId: LoadContext = {
entityId: 'testEntityId',
contentUrl: 'https://localhost:4000',
subEntityId: 'testSubEntityId',
};

let receivedContext: LoadContext | undefined;
teamsCore.registerOnLoadHandler((ctx: LoadContext) => {
receivedContext = ctx;
return false;
});

await utils.sendMessage('load', loadContextWithSubEntityId);

expect(receivedContext).toBeDefined();
expect(receivedContext?.subEntityId).toBe('testSubEntityId');
});
});
});

Expand Down
Loading