Skip to content

Commit e1cffad

Browse files
authored
Add gis diagnostic check (#4030)
1 parent 2409652 commit e1cffad

File tree

4 files changed

+125
-2
lines changed

4 files changed

+125
-2
lines changed

demos/public/qual/subscriptions/gis-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
17+
const clientId =
18+
'365425805315-ulc9hop6lvq3blgc7ubvtcu5322t3fcn.apps.googleusercontent.com';
1819
const sessionId = 'test-session-123';
1920

2021

src/api/basic-subscriptions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ export interface BasicSubscriptions {
8383
* purposes.
8484
*/
8585
dismissSwgUI(): void;
86+
87+
/**
88+
* Returns diagnostic information about the setup.
89+
*/
90+
getDiagnostics(): {isGisReady: boolean};
8691
}
8792

8893
/**

src/runtime/basic-runtime-test.js

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ describes.realWin('installBasicRuntime', (env) => {
109109
expect(getBasicRuntime()).to.equal(runtime1);
110110
});
111111

112+
it('should expose getDiagnostics on global SWG_BASIC', () => {
113+
installBasicRuntime(win);
114+
expect(win.SWG_BASIC.getDiagnostics).to.be.a('function');
115+
const diagnostics = win.SWG_BASIC.getDiagnostics();
116+
expect(diagnostics).to.have.property('isGisReady');
117+
});
118+
112119
it('handles recursive calls after installation', async () => {
113120
installBasicRuntime(win);
114121
let progress = '';
@@ -483,9 +490,54 @@ describes.realWin('BasicRuntime', (env) => {
483490
});
484491

485492
const configuredRuntime = await basicRuntime.configured_(true);
486-
487493
expect(configuredRuntime.gisInteropManager()).to.not.exist;
488494
});
495+
496+
it('should return getDiagnostics().isGisReady true when all params are present', () => {
497+
basicRuntime.init({
498+
...DEFAULT_INIT_PARAMS,
499+
gisInterop: true,
500+
clientOptions: {
501+
clientId: 'test-client-id',
502+
onGisOptIn: () => {},
503+
},
504+
});
505+
expect(basicRuntime.getDiagnostics().isGisReady).to.be.true;
506+
});
507+
508+
it('should return getDiagnostics().isGisReady false when gisInterop is false', () => {
509+
basicRuntime.init({
510+
...DEFAULT_INIT_PARAMS,
511+
gisInterop: false,
512+
clientOptions: {
513+
clientId: 'test-client-id',
514+
onGisOptIn: () => {},
515+
},
516+
});
517+
expect(basicRuntime.getDiagnostics().isGisReady).to.be.false;
518+
});
519+
520+
it('should return getDiagnostics().isGisReady false when clientId is missing', () => {
521+
basicRuntime.init({
522+
...DEFAULT_INIT_PARAMS,
523+
gisInterop: true,
524+
clientOptions: {
525+
onGisOptIn: () => {},
526+
},
527+
});
528+
expect(basicRuntime.getDiagnostics().isGisReady).to.be.false;
529+
});
530+
531+
it('should return getDiagnostics().isGisReady false when onGisOptIn is missing', () => {
532+
basicRuntime.init({
533+
...DEFAULT_INIT_PARAMS,
534+
gisInterop: true,
535+
clientOptions: {
536+
clientId: 'test-client-id',
537+
},
538+
});
539+
expect(basicRuntime.getDiagnostics().isGisReady).to.be.false;
540+
});
489541
});
490542

491543
describe('configured', () => {
@@ -815,6 +867,51 @@ describes.realWin('BasicRuntime', (env) => {
815867

816868
await basicRuntime.setupInlineCta();
817869
});
870+
871+
it('should return getDiagnostics().isGisReady true when all params are present in ConfiguredBasicRuntime', () => {
872+
sandbox
873+
.stub(configuredBasicRuntime, 'config')
874+
.returns({gisInterop: true});
875+
clientConfigManagerMock
876+
.expects('getClientId')
877+
.returns('test-client-id')
878+
.once();
879+
clientConfigManagerMock
880+
.expects('getOnGisOptIn')
881+
.returns(() => {})
882+
.once();
883+
expect(configuredBasicRuntime.getDiagnostics().isGisReady).to.be.true;
884+
});
885+
886+
it('should return getDiagnostics().isGisReady false when gisInterop is false in ConfiguredBasicRuntime', () => {
887+
sandbox
888+
.stub(configuredBasicRuntime, 'config')
889+
.returns({gisInterop: false});
890+
expect(configuredBasicRuntime.getDiagnostics().isGisReady).to.be.false;
891+
});
892+
893+
it('should return getDiagnostics().isGisReady false when clientId is missing in ConfiguredBasicRuntime', () => {
894+
sandbox
895+
.stub(configuredBasicRuntime, 'config')
896+
.returns({gisInterop: true});
897+
clientConfigManagerMock.expects('getClientId').returns(undefined).once();
898+
expect(configuredBasicRuntime.getDiagnostics().isGisReady).to.be.false;
899+
});
900+
901+
it('should return getDiagnostics().isGisReady false when onGisOptIn is missing in ConfiguredBasicRuntime', () => {
902+
sandbox
903+
.stub(configuredBasicRuntime, 'config')
904+
.returns({gisInterop: true});
905+
clientConfigManagerMock
906+
.expects('getClientId')
907+
.returns('test-client-id')
908+
.once();
909+
clientConfigManagerMock
910+
.expects('getOnGisOptIn')
911+
.returns(undefined)
912+
.once();
913+
expect(configuredBasicRuntime.getDiagnostics().isGisReady).to.be.false;
914+
});
818915
});
819916
});
820917

src/runtime/basic-runtime.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export function installBasicRuntime(win: Window): void {
117117
// they'll be queued up to receive the SwG Basic runtime when it's ready.
118118
(win[BASIC_RUNTIME_PROP] as {}) = {
119119
push: callWhenRuntimeIsReady,
120+
getDiagnostics: () => publicBasicRuntime.getDiagnostics(),
120121
};
121122

122123
// Set variable for testing.
@@ -308,6 +309,15 @@ export class BasicRuntime implements BasicSubscriptions {
308309
runtime.dismissSwgUI();
309310
}
310311

312+
getDiagnostics(): {isGisReady: boolean} {
313+
return {
314+
isGisReady:
315+
!!this.gisInterop &&
316+
!!this.clientOptions_?.clientId &&
317+
!!this.clientOptions_?.onGisOptIn,
318+
};
319+
}
320+
311321
/**
312322
* Sets up all the buttons on the page with attribute
313323
* 'swg-standard-button:subscription' or 'swg-standard-button:contribution'.
@@ -651,6 +661,15 @@ export class ConfiguredBasicRuntime implements Deps, BasicSubscriptions {
651661
this.dialogManager().completeAll();
652662
}
653663

664+
getDiagnostics(): {isGisReady: boolean} {
665+
return {
666+
isGisReady:
667+
!!this.config().gisInterop &&
668+
!!this.clientConfigManager().getClientId() &&
669+
!!this.clientConfigManager().getOnGisOptIn(),
670+
};
671+
}
672+
654673
/**
655674
* Sets up all the buttons on the page with attribute
656675
* 'swg-standard-button:subscription' or 'swg-standard-button:contribution'.
@@ -720,5 +739,6 @@ function createPublicBasicRuntime(
720739
setupAndShowAutoPrompt:
721740
basicRuntime.setupAndShowAutoPrompt.bind(basicRuntime),
722741
dismissSwgUI: basicRuntime.dismissSwgUI.bind(basicRuntime),
742+
getDiagnostics: basicRuntime.getDiagnostics.bind(basicRuntime),
723743
};
724744
}

0 commit comments

Comments
 (0)