Skip to content

Commit

Permalink
[MOBILEAPPS-1701] Custom URL schema issues fixed (#2998)
Browse files Browse the repository at this point in the history
* Custom URL schema issues

* code implementation changes for checkForMobileAppFlag

* updated test cases

* requested changed addressed

* requested changed addressed

* cspell changes

* review comments addressed
  • Loading branch information
jatin2008 committed Feb 20, 2023
1 parent 472a19b commit 04907df
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 105 deletions.
124 changes: 63 additions & 61 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,84 @@
"version": "0.1",
"language": "en",
"words": [
"Kerberos",
"succes",
"sharedlinks",
"Redistributable",
"fullscreen",
"LGPL",
"mincount",
"QNAME",
"PNAME",
"ADDFEATURES",
"CHECKIN",
"thumbnailed",
"superadmin",
"SUPERADMIN",
"hruser",
"salesuser",
"networkidle",
"domcontentloaded",
"mimetype",

"ngrx",
"ngstack",
"sidenav",
"injectable",
"iosamw",
"truthy",
"cryptodoc",
"mysites",
"afts",
"androidamw",
"cardview",
"CHECKIN",
"classlist",
"folderlink",
"filelink",
"formcontrolname",
"datetimepicker",
"cryptodoc",
"datatable",
"repo",
"snackbar",
"promisify",
"xdescribe",
"unfavorite",
"dateitem",
"datetimepicker",
"denysvuika",
"devtools",
"docx",
"domcontentloaded",
"errored",
"erroredSpy",
"exif",
"filelink",
"folderlink",
"formcontrolname",
"fullscreen",
"gitter",
"guid",
"hruser",
"injectable",
"iosamw",
"jira",
"jsonp",
"Kerberos",
"keycodes",
"LGPL",
"markdownlint",
"uploader",
"mimetype",
"mincount",
"mobileapps",
"mysites",
"networkidle",
"nginx",
"docx",
"SOLR",
"simpletask",
"titlecase",

"unshare",
"qshare",
"validators",
"guid",
"ngrx",
"ngstack",
"noderef",
"pdfjs",
"PNAME",
"polyfill",
"polyfills",
"jsonp",
"pdfjs",
"xpath",
"promisify",
"QNAME",
"qshare",
"Redistributable",
"repo",
"salesuser",
"sharedlinks",
"sidenav",
"simpletask",
"snackbar",
"SOLR",
"submenu",
"submenus",
"succes",
"superadmin",
"thumbnailed",
"titlecase",
"tooltip",
"tooltips",
"truthy",
"unfavorite",
"unindent",
"exif",
"cardview",
"webm",
"keycodes",
"denysvuika",
"submenu",
"submenus",
"dateitem",
"unshare",
"uploader",
"validators",
"versionable",
"erroredSpy",
"errored",
"noderef"
"webm",
"xdescribe",
"xpath"
],
"dictionaries": ["html", "en-gb", "en_US"]
"dictionaries": [
"html",
"en-gb",
"en_US"
]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="container">
<button mat-button (click)="openInApp()" data-automation-id="open-in-app-button">
<span>{{ 'APP.DIALOGS.MOBILE_APP.MOBILE_APP_BUTTON_LABEL' }}</span>
<button mat-button (click)="openInApp()" data-automation-id="open-in-app-button" class="open-in-app">
<span>{{ 'APP.DIALOGS.MOBILE_APP.MOBILE_APP_BUTTON_LABEL' | translate }}</span>
</button>
<button mat-button mat-dialog-close>
<button mat-button (click)="onCloseDialog()">
<mat-icon>close</mat-icon>
</button>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
}

.mat-dialog-container{
padding: 12px;
padding: 5px;
border-radius: 36px;
background-color: var(--theme-blue-button-color);
color: var(--theme-about-panel-background-color);
}

.open-in-app.mat-button {
overflow-x: hidden;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { By } from '@angular/platform-browser';
import { OpenInAppComponent } from './open-in-app.component';
import { initialState, LibTestingModule } from '../../testing/lib-testing-module';
import { provideMockStore } from '@ngrx/store/testing';
import { TranslateModule } from '@ngx-translate/core';

describe('OpenInAppComponent', () => {
let fixture: ComponentFixture<OpenInAppComponent>;
let component: OpenInAppComponent;

const mockDialogRef = {
close: jasmine.createSpy('close'),
open: jasmine.createSpy('open')
};

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [OpenInAppComponent],
providers: [{ provide: MAT_DIALOG_DATA, useValue: { redirectUrl: 'mockRedirectUrl' } }]
imports: [LibTestingModule, TranslateModule],
providers: [
provideMockStore({ initialState }),
{ provide: MAT_DIALOG_DATA, useValue: { redirectUrl: 'mockRedirectUrl' } },
{ provide: MatDialogRef, useValue: mockDialogRef }
]
}).compileComponents();

fixture = TestBed.createComponent(OpenInAppComponent);
Expand All @@ -35,4 +48,11 @@ describe('OpenInAppComponent', () => {

expect(currentLocation).toBe('mockRedirectUrl');
});

it('should set the value `mobile_notification_expires_in` in session storage on dialog close', async () => {
sessionStorage.clear();
component.onCloseDialog();
expect(sessionStorage.getItem('mobile_notification_expires_in')).not.toBeNull();
expect(mockDialogRef.close).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

import { Component, Inject, ViewEncapsulation } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';

export interface OpenInAppDialogOptions {
redirectUrl: string;
Expand All @@ -41,7 +41,8 @@ export class OpenInAppComponent {

constructor(
@Inject(MAT_DIALOG_DATA)
public data: OpenInAppDialogOptions
public data: OpenInAppDialogOptions,
private dialog: MatDialogRef<OpenInAppComponent>
) {
if (data) {
this.redirectUrl = data.redirectUrl;
Expand All @@ -51,4 +52,10 @@ export class OpenInAppComponent {
openInApp(): void {
this.window.location.href = this.redirectUrl;
}

onCloseDialog(): void {
const time: number = new Date().getTime();
sessionStorage.setItem('mobile_notification_expires_in', time.toString());
this.dialog.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,46 +60,57 @@ describe('AcaMobileAppSwitcherService', () => {
spyOnProperty(window.navigator, 'userAgent').and.returnValue('iphone');
const url: string = window.location.href;
const iphoneUrl: string = appConfig.config.mobileAppSwitch.iphoneUrl + url;
service.showAppNotification();
service.identifyBrowserAndSetRedirectURL();
expect(service.redirectUrl).toEqual(iphoneUrl);
});

it('should set the redirectUrl to `androidUrl`', () => {
spyOnProperty(window.navigator, 'userAgent').and.returnValue('android');
const url: string = window.location.href;
const androidUrl: string = appConfig.config.mobileAppSwitch.androidUrlPart1 + url + appConfig.config.mobileAppSwitch.androidUrlPart2;
service.showAppNotification();
service.identifyBrowserAndSetRedirectURL();
expect(service.redirectUrl).toEqual(androidUrl);
});

it('should check if `showAppNotification` function is called', () => {
const showAppNotificationSpy: jasmine.Spy<() => void> = spyOn(service, 'showAppNotification');
service.checkForMobileApp();
expect(showAppNotificationSpy).toHaveBeenCalled();
it('should check if `identifyBrowserAndSetRedirectURL` function is called', () => {
const identifyBrowserAndSetRedirectURLSpy: jasmine.Spy<() => void> = spyOn(service, 'identifyBrowserAndSetRedirectURL');
service.resolveExistenceOfDialog();
expect(identifyBrowserAndSetRedirectURLSpy).toHaveBeenCalled();
});

it('should not display `openInApp` dialog box when timeDifference is less than the session time', () => {
service.checkForMobileApp();
const showAppNotificationSpy: jasmine.Spy<() => void> = spyOn(service, 'showAppNotification');
service.checkForMobileApp();
expect(showAppNotificationSpy).not.toHaveBeenCalled();
it('should not display `openInApp` dialog box after closing the same and time difference less than session time', () => {
const time: number = new Date().getTime();
sessionStorage.setItem('mobile_notification_expires_in', time.toString());
const identifyBrowserAndSetRedirectURLSpy: jasmine.Spy<() => void> = spyOn(service, 'identifyBrowserAndSetRedirectURL');
service.verifySessionExistsForDialog();
expect(identifyBrowserAndSetRedirectURLSpy).not.toHaveBeenCalled();
});

it('should check if `openInApp` dialog box is getting opened with `iphone` url', () => {
const openInAppSpy: jasmine.Spy<(redirectUrl: string) => void> = spyOn(service, 'openInApp');
const url: string = window.location.href;
service.redirectUrl = appConfig.config.mobileAppSwitch.iphoneUrl + url;
service.showAppNotification();
expect(openInAppSpy).toHaveBeenCalled();
service.identifyBrowserAndSetRedirectURL();
expect(mockDialogRef.open).toHaveBeenCalled();
});

it('should check if `openInApp` dialog box is getting opened with `android` url', () => {
const openInAppSpy: jasmine.Spy<(redirectUrl: string) => void> = spyOn(service, 'openInApp');
const url: string = window.location.href;
service.redirectUrl = appConfig.config.mobileAppSwitch.androidUrlPart1 + url + appConfig.config.mobileAppSwitch.androidUrlPart2;
service.showAppNotification();
expect(openInAppSpy).toHaveBeenCalled();
service.identifyBrowserAndSetRedirectURL();
expect(mockDialogRef.open).toHaveBeenCalled();
});

it('should not display Open in app dialog when the web application is opened within mobile application', () => {
spyOn(service, 'getCurrentUrl').and.returnValue('localhost?mobileapps=true');
const verifySessionExistsForDialogSpy: jasmine.Spy<() => void> = spyOn(service, 'verifySessionExistsForDialog');
service.resolveExistenceOfDialog();
expect(verifySessionExistsForDialogSpy).not.toHaveBeenCalled();
});

it('should display Open in app dialog when the web application is opened in mobile browser', () => {
spyOn(service, 'getCurrentUrl').and.returnValue('localhost');
const verifySessionExistsForDialogSpy: jasmine.Spy<() => void> = spyOn(service, 'verifySessionExistsForDialog');
service.resolveExistenceOfDialog();
expect(verifySessionExistsForDialogSpy).toHaveBeenCalled();
});
});

0 comments on commit 04907df

Please sign in to comment.