summaryrefslogtreecommitdiffhomepage
path: root/gui/test
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2023-04-13 08:57:54 +0200
committerOskar Nyberg <oskar@mullvad.net>2023-04-17 14:14:07 +0200
commit124e7774c82d8b6ec80be2af5d973b350698bb9c (patch)
tree5c088bbe618cb5c3a876c26bd3275183e2cb985f /gui/test
parent025a88ecd26d85a1ab8fcedf421ce774de361a0a (diff)
downloadmullvadvpn-124e7774c82d8b6ec80be2af5d973b350698bb9c.tar.xz
mullvadvpn-124e7774c82d8b6ec80be2af5d973b350698bb9c.zip
Add tests for notification evaluation
Diffstat (limited to 'gui/test')
-rw-r--r--gui/test/unit/notification-evaluation.spec.ts142
1 files changed, 142 insertions, 0 deletions
diff --git a/gui/test/unit/notification-evaluation.spec.ts b/gui/test/unit/notification-evaluation.spec.ts
new file mode 100644
index 0000000000..33a86328bd
--- /dev/null
+++ b/gui/test/unit/notification-evaluation.spec.ts
@@ -0,0 +1,142 @@
+import { expect } from 'chai';
+import { it, describe } from 'mocha';
+import sinon from 'sinon';
+
+import {
+ UnsupportedVersionNotificationProvider, UpdateAvailableNotificationProvider,
+ // UpdateAvailableNotificationProvider,
+} from '../../src/shared/notifications/notification';
+import NotificationController from '../../src/main/notification-controller';
+import { TunnelState } from '../../src/shared/daemon-rpc-types';
+import { ErrorStateCause } from '../../src/shared/daemon-rpc-types';
+import { FirewallPolicyErrorType } from '../../src/shared/daemon-rpc-types';
+
+function createController() {
+ return new NotificationController({
+ openApp: () => { /* no-op */ },
+ openLink: (_url: string, _withAuth?: boolean) => Promise.resolve(),
+ showNotificationIcon: (_value: boolean) => { /* no-op */ },
+ });
+}
+
+describe('System notifications', () => {
+ let sandbox: sinon.SinonSandbox;
+
+ before(() => {
+ sandbox = sinon.createSandbox();
+ // @ts-ignore
+ sandbox.stub(NotificationController.prototype, 'createElectronNotification').returns({
+ show: () => { /* no-op */ },
+ close: () => { /* no-op */ },
+ on: () => { /* no-op */ },
+ removeAllListeners: () => { /* no-op */ },
+ });
+ });
+
+ it('should evaluate unspupported version notification to show', () => {
+ const controller1 = createController();
+ const controller2 = createController();
+ const notification = new UnsupportedVersionNotificationProvider({
+ supported: false,
+ consistent: true,
+ suggestedUpgrade: '2100.1',
+ suggestedIsBeta: false,
+ });
+
+ expect(notification.mayDisplay()).to.be.true;
+
+ const systemNotification = notification.getSystemNotification();
+ const result1 = controller1.notify(systemNotification, false, true);
+ const result2 = controller2.notify(systemNotification, false, false);
+
+ expect(result1).to.be.true;
+ expect(result2).to.be.true;
+ });
+
+ it('should evaluate update available notification to show', () => {
+ const controller1 = createController();
+ const controller2 = createController();
+ const notification = new UpdateAvailableNotificationProvider({
+ suggestedUpgrade: '2100.1',
+ suggestedIsBeta: false,
+ });
+
+ expect(notification.mayDisplay()).to.be.true;
+
+ const systemNotification = notification.getSystemNotification();
+ const result1 = controller1.notify(systemNotification, false, true);
+ const result2 = controller2.notify(systemNotification, false, false);
+
+ expect(result1).to.be.true;
+ expect(result2).to.be.true;
+ });
+
+ it('should show unsupported version notification only once', () => {
+ const controller = createController();
+ const notification = new UnsupportedVersionNotificationProvider({
+ supported: false,
+ consistent: true,
+ suggestedUpgrade: '2100.1',
+ suggestedIsBeta: false,
+ });
+
+ const systemNotification = notification.getSystemNotification();
+ const result1 = controller.notify(systemNotification, false, true);
+ const result2 = controller.notify(systemNotification, false, true);
+
+ expect(result1).to.be.true;
+ expect(result2).to.be.false;
+ });
+
+ it('should not show notification when window is open', () => {
+ const controller = createController();
+ const notification = new UnsupportedVersionNotificationProvider({
+ supported: false,
+ consistent: true,
+ suggestedUpgrade: '2100.1',
+ suggestedIsBeta: false,
+ });
+
+ const systemNotification = notification.getSystemNotification();
+ const result = controller.notify(systemNotification, true, true);
+
+ expect(result).to.be.false;
+ });
+
+ it('Tunnel state notifications should respect notification setting', () => {
+ const controller = createController();
+
+ const disconnectedState: TunnelState = { state: 'disconnected' };
+ const connectingState: TunnelState = { state: 'connecting' };
+ const result1 = controller.notifyTunnelState(disconnectedState, false, false, false, true);
+ const result2 = controller.notifyTunnelState(disconnectedState, false, false, false, false);
+ const result3 = controller.notifyTunnelState(connectingState, false, false, false, true);
+ const result4 = controller.notifyTunnelState(connectingState, false, false, false, false);
+
+ expect(result1).to.be.true;
+ expect(result2).to.be.false;
+ expect(result3).to.be.true;
+ expect(result4).to.be.false;
+
+ const blockingErrorState: TunnelState = {
+ state: 'error',
+ details: {
+ cause: ErrorStateCause.isOffline,
+ },
+ };
+ const result5 = controller.notifyTunnelState(blockingErrorState, false, false, false, false);
+ expect(result5).to.be.false;
+
+ const nonBlockingErrorState: TunnelState = {
+ state: 'error',
+ details: {
+ cause: ErrorStateCause.isOffline,
+ blockingError: {
+ type: FirewallPolicyErrorType.generic,
+ }
+ },
+ };
+ const result6 = controller.notifyTunnelState(nonBlockingErrorState, false, false, false, false);
+ expect(result6).to.be.true;
+ });
+});