From a7181e8878c4b063603ad0c011e1dcb3c913478c Mon Sep 17 00:00:00 2001 From: Charlie Wang Date: Tue, 12 Apr 2022 18:39:28 -0700 Subject: [PATCH 1/2] update locale export --- __tests__/utils/locale.spec.ts | 10 +++++----- src/index.ts | 20 +++++++++++++------- src/utils/locale.ts | 7 ++++--- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/__tests__/utils/locale.spec.ts b/__tests__/utils/locale.spec.ts index e96ce99..a6221b1 100644 --- a/__tests__/utils/locale.spec.ts +++ b/__tests__/utils/locale.spec.ts @@ -4,16 +4,16 @@ const locale = require('../../src/utils/locale'); describe('Locales', () => { it('locale.getLocaleStringFromId() should return correctly', () => { expect(locale.getLocaleStringFromId("1033")).toBe("en-us"); - expect(locale.getLocaleStringFromId(1033)).toBe(""); - expect(locale.getLocaleStringFromId("1133")).toBe(""); + expect(locale.getLocaleStringFromId(1033)).toBe("en-us"); + expect(locale.getLocaleStringFromId("1133")).toBe("en-us"); expect(locale.getLocaleStringFromId("1058")).toBe("uk-ua"); - expect(locale.getLocaleStringFromId("")).toBe(""); + expect(locale.getLocaleStringFromId("")).toBe("en-us"); }); it('locale.getLocaleIdFromString() should return correctly', () => { expect(locale.getLocaleIdFromString("en-us")).toBe("1033"); - expect(locale.getLocaleIdFromString("en-uus")).toBe(""); - expect(locale.getLocaleIdFromString("")).toBe(""); + expect(locale.getLocaleIdFromString("en-uus")).toBe("1033"); + expect(locale.getLocaleIdFromString("")).toBe("1033"); expect(locale.getLocaleIdFromString("zh-cn")).toBe("2052"); }); }); \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 32fe5f4..627e0e2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,14 +1,16 @@ -import {SDKProvider as OCSDKProvider, uuidv4 } from "@microsoft/ocsdk"; -import {SDKProvider as IC3SDKProvider} from '@microsoft/omnichannel-ic3core'; -import OmnichannelChatSDK from "./OmnichannelChatSDK"; +import {SDKProvider as OCSDKProvider, uuidv4} from "@microsoft/ocsdk"; +import { defaultLocaleId, defaultLocaleString, getLocaleIdFromString, getLocaleStringFromId } from "./utils/locale"; +import { isCustomerMessage, isSystemMessage } from "./utils/utilities"; + import ChatSDKMessage from "./core/messaging/ChatSDKMessage"; +import DeliveryMode from "@microsoft/omnichannel-ic3core/lib/model/DeliveryMode"; +import {SDKProvider as IC3SDKProvider} from '@microsoft/omnichannel-ic3core'; +import IFileInfo from "@microsoft/omnichannel-ic3core/lib/interfaces/IFileInfo"; import IRawMessage from "@microsoft/omnichannel-ic3core/lib/model/IRawMessage"; import MessageContentType from "@microsoft/omnichannel-ic3core/lib/model/MessageContentType"; -import DeliveryMode from "@microsoft/omnichannel-ic3core/lib/model/DeliveryMode"; import MessageType from "@microsoft/omnichannel-ic3core/lib/model/MessageType"; +import OmnichannelChatSDK from "./OmnichannelChatSDK"; import PersonType from "@microsoft/omnichannel-ic3core/lib/model/PersonType"; -import IFileInfo from "@microsoft/omnichannel-ic3core/lib/interfaces/IFileInfo"; -import { isSystemMessage, isCustomerMessage } from "./utils/utilities"; export { OmnichannelChatSDK, @@ -23,7 +25,11 @@ export { PersonType, IFileInfo, isSystemMessage, - isCustomerMessage + isCustomerMessage, + getLocaleStringFromId, + getLocaleIdFromString, + defaultLocaleId, + defaultLocaleString } export default { diff --git a/src/utils/locale.ts b/src/utils/locale.ts index 4213001..eaa81a7 100644 --- a/src/utils/locale.ts +++ b/src/utils/locale.ts @@ -49,13 +49,14 @@ const localeList: any = { // eslint-disable-line @typescript-eslint/no-explicit- export const getLocaleStringFromId = (id: string): string => { const localeId = Object.keys(localeList).find(key => key === id); - return localeId ? localeList[localeId] : ""; + return localeId ? localeList[localeId] : defaultLocaleString; } export const getLocaleIdFromString = (value: string): string => { const localeId = Object.keys(localeList).find(key => localeList[key] === value); - return localeId ?? ""; + return localeId ?? defaultLocaleId; } -export const defaultLocaleId = getLocaleIdFromString("en-us"); \ No newline at end of file +export const defaultLocaleId = "1033"; +export const defaultLocaleString = getLocaleStringFromId(defaultLocaleId); \ No newline at end of file From 97641b2a105da818dfb2ad3027f088b6d22829a1 Mon Sep 17 00:00:00 2001 From: Charlie Wang Date: Tue, 12 Apr 2022 18:45:15 -0700 Subject: [PATCH 2/2] update UT --- src/utils/locale.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/locale.ts b/src/utils/locale.ts index eaa81a7..9f85649 100644 --- a/src/utils/locale.ts +++ b/src/utils/locale.ts @@ -59,4 +59,4 @@ export const getLocaleIdFromString = (value: string): string => { } export const defaultLocaleId = "1033"; -export const defaultLocaleString = getLocaleStringFromId(defaultLocaleId); \ No newline at end of file +export const defaultLocaleString = "en-us"; \ No newline at end of file