Repository: manusa/electronim (js)

Issue:
Full screen mode
## Description

As a user I want to be able to set ElectronIM main window in full screen mode.

Full screen mode can be toggled by pressing `F11` (globally).

Pull request:
✨ Full screen mode can be toggled pressing F11
Fixes #181 

Patch:
diff --git a/docs/Keyboard-shortcuts.md b/docs/Keyboard-shortcuts.md
index 69c9bb8..a7ae2ec 100644
--- a/docs/Keyboard-shortcuts.md
+++ b/docs/Keyboard-shortcuts.md
@@ -2,6 +2,7 @@
 
 | Key combination                                            | Description                    |
 |------------------------------------------------------------|--------------------------------|
+| `F11`                                                      | Toggle full screen.            |
 | `Ctrl+r` `Cmd+r` `F5`                                      | Reload current tab.            |
 | `Ctrl++` `Cmd++` <br /> `Ctrl+ScrollUp` `Cmd+ScrollUp`     | Zoom in.                       |
 | `Ctrl+-` `Cmd+-` <br /> `Ctrl+ScrollDown` `Cmd+ScrollDown` | Zoom out.                      |
diff --git a/src/constants/index.js b/src/constants/index.js
index 8b90615..4b7428c 100644
--- a/src/constants/index.js
+++ b/src/constants/index.js
@@ -37,6 +37,7 @@ const APP_EVENTS = {
   dictionaryGetEnabled: 'dictionaryGetEnabled',
   dictionaryGetMisspelled: 'dictionaryGetMisspelled',
   electronimNewVersionAvailable: 'electronimNewVersionAvailable',
+  fullscreenToggle: 'fullscreenToggle',
   helpOpenDialog: 'helpOpenDialog',
   notificationClick: 'notificationClick',
   reload: 'reload',
diff --git a/src/main/index.js b/src/main/index.js
index c975321..4ca520f 100644
--- a/src/main/index.js
+++ b/src/main/index.js
@@ -168,6 +168,10 @@ const appMenuClose = () => {
   activateTab(tabManager.getActiveTab());
 };
 
+const fullscreenToggle = () => {
+  mainWindow.setFullScreen(!mainWindow.isFullScreen());
+};
+
 const closeDialog = () => {
   if (mainWindow.getBrowserViews().length > 1) {
     return;
@@ -196,6 +200,7 @@ const initGlobalListeners = () => {
   eventBus.handle(APP_EVENTS.dictionaryGetAvailable, getAvailableDictionaries);
   eventBus.handle(APP_EVENTS.dictionaryGetAvailableNative, getAvailableNativeDictionaries);
   eventBus.handle(APP_EVENTS.dictionaryGetEnabled, getEnabledDictionaries);
+  eventBus.on(APP_EVENTS.fullscreenToggle, fullscreenToggle);
   eventBus.on(APP_EVENTS.helpOpenDialog, openHelpDialog(mainWindow));
   eventBus.handle(APP_EVENTS.settingsLoad, loadSettings);
   eventBus.on(APP_EVENTS.settingsOpenDialog, openSettingsDialog(mainWindow));
diff --git a/src/main/keyboard-shortcuts.js b/src/main/keyboard-shortcuts.js
index b1a8bc9..be5b224 100644
--- a/src/main/keyboard-shortcuts.js
+++ b/src/main/keyboard-shortcuts.js
@@ -21,6 +21,7 @@ const registerGlobalShortcuts = () => {
     eventBus.emit(APP_EVENTS.appMenuClose);
     eventBus.emit(APP_EVENTS.closeDialog);
   });
+  globalShortcut.register('F11', () => eventBus.emit(APP_EVENTS.fullscreenToggle));
 };
 
 module.exports = {registerGlobalShortcuts};


Test patch:
diff --git a/src/__tests__/electron.js b/src/__tests__/electron.js
index 8cf05e1..7aefecb 100644
--- a/src/__tests__/electron.js
+++ b/src/__tests__/electron.js
@@ -16,10 +16,11 @@
 
 const mockBrowserWindowInstance = () => {
   const instance = {
+    listeners: {},
     addBrowserView: jest.fn(),
     destroy: jest.fn(),
     getContentBounds: jest.fn(() => ({})),
-    listeners: {},
+    isFullScreen: jest.fn(() => false),
     loadURL: jest.fn(),
     on: jest.fn((eventName, func) => {
       instance.listeners[eventName] = func;
@@ -29,6 +30,7 @@ const mockBrowserWindowInstance = () => {
     setAutoResize: jest.fn(),
     setBounds: jest.fn(),
     setBrowserView: jest.fn(),
+    setFullScreen: jest.fn(),
     webContents: {
       copy: jest.fn(),
       copyImageAt: jest.fn(),
diff --git a/src/main/__tests__/index.test.js b/src/main/__tests__/index.test.js
index 5513026..1c5e113 100644
--- a/src/main/__tests__/index.test.js
+++ b/src/main/__tests__/index.test.js
@@ -528,6 +528,26 @@ describe('Main module test suite', () => {
       expect(mockBrowserWindow.removeBrowserView).toHaveBeenCalledTimes(1);
       expect(mockBrowserWindow.removeBrowserView).toHaveBeenCalledWith(mockAppMenu);
     });
+    describe('fullscreenToggle', () => {
+      test('when not fullscreen, should enter fullscreen', () => {
+        // Given
+        mockBrowserWindow.isFullScreen.mockReturnValue(false);
+        main.init();
+        // When
+        mockIpc.listeners.fullscreenToggle();
+        // Then
+        expect(mockBrowserWindow.setFullScreen).toHaveBeenCalledWith(true);
+      });
+      test('when in fullscreen, should leave fullscreen', () => {
+        // Given
+        mockBrowserWindow.isFullScreen.mockReturnValue(true);
+        main.init();
+        // When
+        mockIpc.listeners.fullscreenToggle();
+        // Then
+        expect(mockBrowserWindow.setFullScreen).toHaveBeenCalledWith(false);
+      });
+    });
     test('settingsOpenDialog, should open settings dialog', () => {
       // Given
       main.init();
diff --git a/src/main/__tests__/keyboard-shortcuts.test.js b/src/main/__tests__/keyboard-shortcuts.test.js
index 83a9f67..08979c6 100644
--- a/src/main/__tests__/keyboard-shortcuts.test.js
+++ b/src/main/__tests__/keyboard-shortcuts.test.js
@@ -21,11 +21,11 @@ describe('Global Keyboard Shortcuts module test suite', () => {
     require('../').init();
     electron = require('electron');
   });
-  describe('Escape', () => {
-    test.each(['appMenuClose', 'closeDialog'])('callback triggers %s', appEvent => {
-      // eslint-disable-next-line new-cap
-      electron.globalShortcut.listeners.Escape();
-      expect(electron.ipcMain.emit).toHaveBeenCalledWith(appEvent);
-    });
+  test.each([
+    ['Escape', 'appMenuClose'], ['Escape', 'closeDialog'],
+    ['F11', 'fullscreenToggle']
+  ])('Accelerator "%s" triggers "%s" app event', (accelerator, appEvent) => {
+    electron.globalShortcut.listeners[accelerator]();
+    expect(electron.ipcMain.emit).toHaveBeenCalledWith(appEvent);
   });
 });