From f19f87259bdcd28e9fba890f249de16b150e45c4 Mon Sep 17 00:00:00 2001 From: Niharika Date: Tue, 10 Dec 2024 14:08:41 +0530 Subject: [PATCH] Adding test --- .../components/privateApis/CopilotAPIs.tsx | 33 ++++++++++++++++--- .../teams-js/src/private/copilot/copilot.ts | 3 +- .../src/private/copilot/customTelemetry.ts | 2 +- packages/teams-js/src/public/runtime.ts | 1 + .../teams-js/test/private/copilot.spec.ts | 2 +- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/apps/teams-test-app/src/components/privateApis/CopilotAPIs.tsx b/apps/teams-test-app/src/components/privateApis/CopilotAPIs.tsx index fd9a86aba2..fe645e6c33 100644 --- a/apps/teams-test-app/src/components/privateApis/CopilotAPIs.tsx +++ b/apps/teams-test-app/src/components/privateApis/CopilotAPIs.tsx @@ -1,7 +1,7 @@ import { copilot } from '@microsoft/teams-js'; import React, { ReactElement } from 'react'; -import { ApiWithoutInput } from '../utils'; +import { ApiWithoutInput, ApiWithTextInput } from '../utils'; import { ModuleWrapper } from '../utils/ModuleWrapper'; const CopilotAPIs = (): ReactElement => { @@ -23,11 +23,34 @@ const CopilotAPIs = (): ReactElement => { }, }); + const SendCustomTelemetryData = (): ReactElement => + ApiWithTextInput<{ + name: copilot.Stage; + timestamp: number; + }>({ + name: 'sendCustomTelemetryData', + title: 'sendCustomTelemetryData', + onClick: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + validateInput: (_input) => {}, + submit: async (input) => { + const result = await copilot.customTelemetry.sendCustomTelemetryData(input.name, input.timestamp); + return JSON.stringify(result); + }, + }, + defaultInput: JSON.stringify({ name: copilot.Stage.STAGE_E, timestamp: Date.now() }), + }); + return ( - - - - + <> + + + + + + + + ); }; diff --git a/packages/teams-js/src/private/copilot/copilot.ts b/packages/teams-js/src/private/copilot/copilot.ts index e19d1708a7..90cd7f9831 100644 --- a/packages/teams-js/src/private/copilot/copilot.ts +++ b/packages/teams-js/src/private/copilot/copilot.ts @@ -1,4 +1,5 @@ import * as customTelemetry from './customTelemetry'; +import { Stage } from './customTelemetry'; import * as eligibility from './eligibility'; -export { customTelemetry, eligibility }; +export { customTelemetry, Stage, eligibility }; diff --git a/packages/teams-js/src/private/copilot/customTelemetry.ts b/packages/teams-js/src/private/copilot/customTelemetry.ts index 89da63fbc6..967b0bd07e 100644 --- a/packages/teams-js/src/private/copilot/customTelemetry.ts +++ b/packages/teams-js/src/private/copilot/customTelemetry.ts @@ -16,7 +16,7 @@ import { runtime } from '../../public/runtime'; const copilotTelemetryVersionNumber: ApiVersionNumber = ApiVersionNumber.V_2; const copilotLogger = getLogger('copilot'); -enum Stage { +export enum Stage { STAGE_E = 'E', } /** diff --git a/packages/teams-js/src/public/runtime.ts b/packages/teams-js/src/public/runtime.ts index 88c183b7ae..684d3ac2ac 100644 --- a/packages/teams-js/src/public/runtime.ts +++ b/packages/teams-js/src/public/runtime.ts @@ -236,6 +236,7 @@ interface IRuntimeV4 extends IBaseRuntime { readonly conversations?: {}; readonly copilot?: { readonly eligibility?: {}; + readonly customTelemetry?: {}; }; readonly dialog?: { readonly card?: { diff --git a/packages/teams-js/test/private/copilot.spec.ts b/packages/teams-js/test/private/copilot.spec.ts index b779058871..3bbb411cce 100644 --- a/packages/teams-js/test/private/copilot.spec.ts +++ b/packages/teams-js/test/private/copilot.spec.ts @@ -396,7 +396,7 @@ describe('copilot', () => { }); it('sendCustomTelemetryData should throw if called before initialization', async () => { expect.assertions(1); - copilot.customTelemetry.sendCustomTelemetryData(); + copilot.customTelemetry.sendCustomTelemetryData(copilot.Stage.STAGE_E); const message = utils.findMessageByFunc('copilot.customTelemetry.sendCustomTelemetryData'); expect(message).not.toBeNull(); });