Repository: manusa/electronim (js)

Issue:
Add "Refresh" button for each tab
I'm experiencing regular hangs, or bad view renders for several apps inside ElectronIM.  Would be very helpful if there was a "Refresh" button to force an app url to reload and hopefully resolve the problems.   Currently the only way to do that is to restart the app.

Pull request:
Refresh button for each tab
- Added reload option in the context menu

Relates to #114 

Patch:
diff --git a/src/tab-manager/index.js b/src/tab-manager/index.js
index c4b4cfa..cdc784c 100644
--- a/src/tab-manager/index.js
+++ b/src/tab-manager/index.js
@@ -68,6 +68,8 @@ const handleContextMenu = browserView => async (event, params) => {
     spellingSuggestions.forEach(mi => menu.append(mi));
     menu.append(new MenuItem({type: 'separator'}));
   }
+  menu.append(new MenuItem({label: 'Reload', click: () => webContents.reload()}));
+  menu.append(new MenuItem({type: 'separator'}));
   menu.append(new MenuItem({label: 'DevTools', click: () => webContents.openDevTools()}));
   const {x, y} = params;
   menu.popup({x, y});


Test patch:
diff --git a/src/tab-manager/__tests__/index.test.js b/src/tab-manager/__tests__/index.test.js
index 90557c7..a3275fd 100644
--- a/src/tab-manager/__tests__/index.test.js
+++ b/src/tab-manager/__tests__/index.test.js
@@ -252,9 +252,16 @@ describe('Tab Manager module test suite', () => {
           await events['context-menu'](new Event(''), {x: 13, y: 37});
           // Then
           expect(electron.Menu).toHaveBeenCalledTimes(1);
-          expect(electron.MenuItem).toHaveBeenCalledTimes(1);
           expect(electron.MenuItem).toHaveBeenCalledWith(expect.objectContaining({label: 'DevTools'}));
-          expect(mockMenu.append).toHaveBeenCalledTimes(1);
+        });
+        test('should open a Menu with Reload entry', async () => {
+          // Given
+          spellChecker.contextMenuHandler.mockImplementationOnce(() => []);
+          // When
+          await events['context-menu'](new Event(''), {x: 13, y: 37});
+          // Then
+          expect(electron.Menu).toHaveBeenCalledTimes(1);
+          expect(electron.MenuItem).toHaveBeenCalledWith(expect.objectContaining({label: 'Reload'}));
         });
         test('should open a Menu at the specified location', async () => {
           // Given
@@ -279,10 +286,10 @@ describe('Tab Manager module test suite', () => {
             await events['context-menu'](new Event(''), {x: 13, y: 37});
             // Then
             expect(electron.Menu).toHaveBeenCalledTimes(1);
-            expect(electron.MenuItem).toHaveBeenCalledTimes(4);
+            expect(electron.MenuItem).toHaveBeenCalledWith({label: 'suggestion 1'});
+            expect(electron.MenuItem).toHaveBeenCalledWith({label: 'suggestion 2'});
             expect(electron.MenuItem).toHaveBeenCalledWith({type: 'separator'});
             expect(electron.MenuItem).toHaveBeenCalledWith(expect.objectContaining({label: 'DevTools'}));
-            expect(mockMenu.append).toHaveBeenCalledTimes(4);
           });
         });
         describe('with native spellcheck enabled', () => {
@@ -292,16 +299,16 @@ describe('Tab Manager module test suite', () => {
           test('Spelling suggestions, should open a Menu with all suggestions, a separator and DevTools entry', async () => {
             // Given
             spellChecker.contextMenuNativeHandler.mockImplementationOnce(() => [
-              new electron.MenuItem({label: 'suggestion 1'})
+              new electron.MenuItem({label: 'native suggestion 1'})
             ]);
             // When
             await events['context-menu'](new Event(''), {x: 13, y: 37});
             // Then
             expect(electron.Menu).toHaveBeenCalledTimes(1);
-            expect(electron.MenuItem).toHaveBeenCalledTimes(3);
+            expect(electron.MenuItem).toHaveBeenCalledWith({label: 'native suggestion 1'});
+            expect(electron.MenuItem).toHaveBeenCalledWith({type: 'separator'});
             expect(electron.MenuItem).toHaveBeenCalledWith({type: 'separator'});
             expect(electron.MenuItem).toHaveBeenCalledWith(expect.objectContaining({label: 'DevTools'}));
-            expect(mockMenu.append).toHaveBeenCalledTimes(3);
           });
         });
       });