Skip to content

Commit 406d85d

Browse files
committed
move browser push support helpers to useragent detect
1 parent 0c3f5ac commit 406d85d

File tree

11 files changed

+98
-111
lines changed

11 files changed

+98
-111
lines changed

src/entries/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
*/
88

99
// NOTE: Careful if adding imports, ES5 targets can't clean up functions never called.
10-
import { start } from '../page/utils/OneSignalShimLoader';
10+
import { start } from '../page/utils/shimLoader';
1111

1212
start();

src/page/bell/Bell.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
BellSize,
1313
BellText,
1414
} from 'src/shared/prompts/types';
15-
import { wasPromptOfTypeDismissed } from '../../shared/helpers/DismissHelper';
15+
import { wasPromptOfTypeDismissed } from '../../shared/helpers/dismiss';
1616
import { getNotificationIcons } from '../../shared/helpers/main';
1717
import Log from '../../shared/libraries/Log';
1818
import OneSignalEvent from '../../shared/services/OneSignalEvent';

src/page/managers/PromptsManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
requiresUserInteraction,
2424
} from 'src/shared/useragent/detect';
2525
import { logMethodCall } from 'src/shared/utils/utils';
26-
import { markPromptDismissedWithType } from '../../shared/helpers/DismissHelper';
26+
import { markPromptDismissedWithType } from '../../shared/helpers/dismiss';
2727
import Log from '../../shared/libraries/Log';
2828
import OneSignalEvent from '../../shared/services/OneSignalEvent';
2929
import { DismissPrompt } from '../models/Dismiss';

src/page/managers/slidedownManager/SlidedownManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { CoreModuleDirector } from '../../../core/CoreModuleDirector';
2727
import {
2828
markPromptDismissedWithType,
2929
wasPromptOfTypeDismissed,
30-
} from '../../../shared/helpers/DismissHelper';
30+
} from '../../../shared/helpers/dismiss';
3131
import Log from '../../../shared/libraries/Log';
3232
import type { PushSubscriptionState } from '../../../shared/models/PushSubscriptionState';
3333
import { DismissPrompt } from '../../models/Dismiss';

src/page/utils/BrowserSupportsPush.test.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/page/utils/BrowserSupportsPush.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/page/utils/OneSignalShimLoader.test.ts renamed to src/page/utils/shimLoader.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import * as BrowserSupportsPush from './BrowserSupportsPush';
2-
import { start } from './OneSignalShimLoader';
1+
import * as useragentHelpers from 'src/shared/useragent/detect';
2+
import { start } from './shimLoader';
33

44
const supportsSpy = vi
5-
.spyOn(BrowserSupportsPush, 'isPushNotificationsSupported')
5+
.spyOn(useragentHelpers, 'isPushNotificationsSupported')
66
.mockReturnValue(true);
77
const isIosSafariSpy = vi
8-
.spyOn(BrowserSupportsPush, 'isIosSafari')
8+
.spyOn(useragentHelpers, 'isIosSafari')
99
.mockReturnValue(false);
1010

1111
describe('OneSignalShimLoader', () => {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import {
2+
isIosSafari,
3+
isPushNotificationsSupported,
4+
} from 'src/shared/useragent/detect';
15
import {
26
BUILD_ORIGIN,
37
BUILD_TYPE,
48
IS_HTTPS,
59
NO_DEV_PORT,
610
VERSION,
711
} from 'src/shared/utils/env';
8-
import {
9-
isIosSafari,
10-
isPushNotificationsSupported,
11-
} from './BrowserSupportsPush';
1212
// NOTE: Careful if adding imports, ES5 targets can't clean up functions never called.
1313

1414
// See sdk.ts for what entry points this handles

src/shared/useragent/detect.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { USER_AGENTS } from '__test__/constants';
2+
import { TestEnvironment } from '__test__/support/environment/TestEnvironment';
23
import { Browser } from './constants';
34
import {
45
getBrowserName,
56
getBrowserVersion,
7+
isIosSafari,
68
isMobileBrowser,
9+
isPushNotificationsSupported,
710
isTabletBrowser,
811
} from './detect';
912

@@ -425,3 +428,51 @@ describe('getBrowserVersion()', () => {
425428
});
426429
});
427430
});
431+
432+
describe('isPushNotificationsSupported()', () => {
433+
beforeEach(() => {
434+
Object.defineProperty(global, 'PushSubscriptionOptions', {
435+
value: {
436+
prototype: {
437+
applicationServerKey: 'test',
438+
},
439+
},
440+
writable: true,
441+
});
442+
TestEnvironment.initialize();
443+
});
444+
445+
test('can check if browser supports push notifications', () => {
446+
expect(isPushNotificationsSupported()).toBe(true);
447+
448+
Object.defineProperty(global, 'PushSubscriptionOptions', {
449+
value: undefined,
450+
writable: true,
451+
});
452+
expect(isPushNotificationsSupported()).toBe(false);
453+
454+
Object.defineProperty(window, 'safari', {
455+
value: {
456+
pushNotification: {},
457+
},
458+
writable: true,
459+
});
460+
expect(isPushNotificationsSupported()).toBe(true);
461+
});
462+
});
463+
464+
describe('isIosSafari()', () => {
465+
beforeEach(() => {
466+
TestEnvironment.initialize();
467+
});
468+
469+
test('can check if on ios safari browser', () => {
470+
expect(isIosSafari()).toBe(false);
471+
472+
Object.defineProperty(navigator, 'maxTouchPoints', {
473+
value: 1,
474+
writable: true,
475+
});
476+
expect(isIosSafari()).toBe(true);
477+
});
478+
});

0 commit comments

Comments
 (0)