11import ContentstackAppSDK from "../src/index" ;
2- import Extension from "../src/extension " ;
2+ import UiLocation from "../src/uiLocation " ;
33import { version } from "../package.json" ;
44
5- jest . mock ( "../src/extension " ) ;
5+ jest . mock ( "../src/uiLocation " ) ;
66
77describe ( "ContentstackAppSDK" , ( ) => {
88 describe ( "init" , ( ) => {
@@ -11,36 +11,38 @@ describe("ContentstackAppSDK", () => {
1111 } ;
1212 beforeEach ( ( ) => {
1313 const mockInitialize = jest . fn ( ) . mockResolvedValue ( mockInitData ) ;
14- Extension . initialize = mockInitialize ;
14+ UiLocation . initialize = mockInitialize ;
1515 } ) ;
1616
1717 afterEach ( ( ) => {
1818 // Reset the static variable after every test
19- ( ContentstackAppSDK . _extension as any ) = undefined ;
19+ ( ContentstackAppSDK . _uiLocation as any ) = undefined ;
2020 jest . resetAllMocks ( ) ;
2121 } ) ;
2222
23- it ( "should initialize the extension and return an instance of Extension " , async ( ) => {
24- const extension = await ContentstackAppSDK . init ( ) ;
23+ it ( "should initialize the ui location and return an instance of Location " , async ( ) => {
24+ const uiLocation = await ContentstackAppSDK . init ( ) ;
2525
26- expect ( Extension . initialize ) . toHaveBeenCalledTimes ( 1 ) ;
27- expect ( Extension . initialize ) . toBeCalledWith ( version ) ;
28- expect ( Extension ) . toHaveBeenCalledWith ( mockInitData ) ;
29- expect ( extension ) . toBeInstanceOf ( Extension ) ;
26+ expect ( UiLocation . initialize ) . toHaveBeenCalledTimes ( 1 ) ;
27+ expect ( UiLocation . initialize ) . toBeCalledWith ( version ) ;
28+ expect ( UiLocation ) . toHaveBeenCalledWith ( mockInitData ) ;
29+ expect ( uiLocation ) . toBeInstanceOf ( UiLocation ) ;
3030 } ) ;
3131
32- it ( "should return the same instance of Extension if it has already been initialized" , async ( ) => {
33- ( Extension . initialize as jest . Mock ) . mockResolvedValue ( mockInitData ) ;
34- const extension = await ContentstackAppSDK . init ( ) ;
35- const extension2 = await ContentstackAppSDK . init ( ) ;
32+ it ( "should return the same instance of Location if it has already been initialized" , async ( ) => {
33+ ( UiLocation . initialize as jest . Mock ) . mockResolvedValue (
34+ mockInitData
35+ ) ;
36+ const uiLocation = await ContentstackAppSDK . init ( ) ;
37+ const uiLocation2 = await ContentstackAppSDK . init ( ) ;
3638
37- expect ( Extension . initialize ) . toHaveBeenCalledTimes ( 1 ) ;
38- expect ( extension ) . toBe ( extension2 ) ;
39+ expect ( UiLocation . initialize ) . toHaveBeenCalledTimes ( 1 ) ;
40+ expect ( uiLocation ) . toBe ( uiLocation2 ) ;
3941 } ) ;
4042
4143 it ( "should reject the promise if initialization fails" , async ( ) => {
4244 const error = new Error ( "Initialization failed" ) ;
43- ( Extension . initialize as jest . Mock ) . mockRejectedValue ( error ) ;
45+ ( UiLocation . initialize as jest . Mock ) . mockRejectedValue ( error ) ;
4446
4547 await expect ( ContentstackAppSDK . init ( ) ) . rejects . toThrow ( error ) ;
4648 } ) ;
0 commit comments