@@ -4,11 +4,61 @@ import Extension from "../src/extension";
44import { IAppConfigInitData , Region } from "../src/types" ;
55
66jest . mock ( "post-robot" , ( ) => ( {
7- sendToParent : jest . fn ( ) ,
8- on : jest . fn ( ) ,
7+ __esModule : true ,
8+ default : {
9+ on : jest . fn ( ) ,
10+ sendToParent : jest
11+ . fn ( )
12+ . mockReturnValue ( Promise . resolve ( { data : { version : 90 } } ) ) ,
13+ } ,
914} ) ) ;
1015
16+ const manifest = {
17+ created_by : {
18+ uid : "string" ,
19+ first_name : "string" ,
20+ last_name : "string" ,
21+ } ,
22+ icon : "string" ,
23+ name : "string" ,
24+ target_type : "string" ,
25+ uid : "string" ,
26+ updated_by : {
27+ uid : "string" ,
28+ first_name : "string" ,
29+ last_name : "string" ,
30+ } ,
31+ version : 5 ,
32+ visibility : "string" ,
33+ } ;
34+
1135const initData : IAppConfigInitData = {
36+ data : {
37+ type : "APP_CONFIG_WIDGET" ,
38+ app_id : "app_id" ,
39+ installation_uid : "installation_uid" ,
40+ extension_uid : "extension_uid" ,
41+ region : "NA" ,
42+ stack : {
43+ created_at : "created_at" ,
44+ updated_at : "updated_at" ,
45+ uid : "uid" ,
46+ org_uid : "org_uid" ,
47+ api_key : "api_key" ,
48+ master_locale : "master_locale" ,
49+ is_asset_download_public : true ,
50+ owner_uid : "owner_uid" ,
51+ user_uids : [ "user_uids" ] ,
52+ settings : { } ,
53+ name : "name" ,
54+ } ,
55+ user : { } ,
56+ currentBranch : "currentBranch" ,
57+ manifest : manifest ,
58+ } ,
59+ } ;
60+
61+ const initDataWithoutManifest : IAppConfigInitData = {
1262 data : {
1363 type : "APP_CONFIG_WIDGET" ,
1464 app_id : "app_id" ,
@@ -33,6 +83,27 @@ const initData: IAppConfigInitData = {
3383 } ,
3484} ;
3585
86+ const initDataJsonRte = {
87+ data : {
88+ type : "RTE" ,
89+ region : "NA" ,
90+ stack : {
91+ created_at : "created_at" ,
92+ updated_at : "updated_at" ,
93+ uid : "uid" ,
94+ org_uid : "org_uid" ,
95+ api_key : "api_key" ,
96+ master_locale : "master_locale" ,
97+ is_asset_download_public : true ,
98+ owner_uid : "owner_uid" ,
99+ user_uids : [ "user_uids" ] ,
100+ settings : { } ,
101+ name : "name" ,
102+ } ,
103+ user : { } ,
104+ } ,
105+ } ;
106+
36107describe ( "Extension" , ( ) => {
37108 afterEach ( ( ) => {
38109 window [ "postRobot" ] = undefined ;
@@ -83,4 +154,29 @@ describe("Extension", () => {
83154 expect ( region ) . toBe ( Region . NA ) ;
84155 } ) ;
85156 } ) ;
157+
158+ describe ( "getAppVersion" , ( ) => {
159+ it ( "should have getAppVersion method" , ( ) => {
160+ const extensionObj = new Extension ( initData ) ;
161+ expect ( extensionObj . getAppVersion ) . toBeDefined ( ) ;
162+ } ) ;
163+
164+ it ( "should return an app version when invoked" , async ( ) => {
165+ const extensionObj = new Extension ( initData ) ;
166+ const version = await extensionObj . getAppVersion ( ) ;
167+ expect ( version ) . toBe ( 5 ) ;
168+ } ) ;
169+
170+ it ( "should return null when installation uid is not present" , async ( ) => {
171+ const extensionObj = new Extension ( initDataJsonRte as any ) ;
172+ const version = await extensionObj . getAppVersion ( ) ;
173+ expect ( version ) . toBe ( null ) ;
174+ } ) ;
175+
176+ it ( "should fetch the app version for parent using post robot" , async ( ) => {
177+ const extensionObj = new Extension ( initDataWithoutManifest ) ;
178+ const version = await extensionObj . getAppVersion ( ) ;
179+ expect ( version ) . toBe ( 90 ) ;
180+ } ) ;
181+ } ) ;
86182} ) ;
0 commit comments