Repository: manusa/electronim
Pull request #179 (2022-11-04 04:16:19)

✨ context-menu has separators for different groups

sonarcloud[bot]: Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=manusa_electronim&pullRequest=179)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=179&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=179&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=179&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=179&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=179&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=179&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=manusa_electronim&pullRequest=179&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=manusa_electronim&pullRequest=179&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=manusa_electronim&pullRequest=179&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=179&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=179&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=manusa_electronim&pullRequest=179&resolved=false&types=CODE_SMELL)

[![100.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/100-16px.png '100.0%')](https://sonarcloud.io/component_measures?id=manusa_electronim&pullRequest=179&metric=new_coverage&view=list) [100.0% Coverage](https://sonarcloud.io/component_measures?id=manusa_electronim&pullRequest=179&metric=new_coverage&view=list)  
[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=manusa_electronim&pullRequest=179&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=manusa_electronim&pullRequest=179&metric=new_duplicated_lines_density&view=list)



Patch:
diff --git a/package-lock.json b/package-lock.json
index 321b115..977ac29 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -47,7 +47,7 @@
         "css-loader": "6.7.1",
         "electron-builder": "23.6.0",
         "eslint": "8.26.0",
-        "eslint-plugin-jest": "27.0.4",
+        "eslint-plugin-jest": "27.1.3",
         "jest": "29.2.2",
         "jest-environment-jsdom": "29.2.2",
         "jest-environment-node": "29.2.2",
@@ -4015,9 +4015,9 @@
       }
     },
     "node_modules/eslint-plugin-jest": {
-      "version": "27.0.4",
-      "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-27.0.4.tgz",
-      "integrity": "sha512-BuvY78pHMpMJ6Cio7sKg6jrqEcnRYPUc4Nlihku4vKx3FjlmMINSX4vcYokZIe+8TKcyr1aI5Kq7vYwgJNdQSA==",
+      "version": "27.1.3",
+      "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-27.1.3.tgz",
+      "integrity": "sha512-7DrIfYRQPa7JQd1Le8G/BJsfYHVUKQdJQ/6vULSp/4NjKZmSMJ/605G2hhScEra++SiH68zPEjLnrO74nHrMLg==",
       "dev": true,
       "dependencies": {
         "@typescript-eslint/utils": "^5.10.0"
@@ -11759,9 +11759,9 @@
       }
     },
     "eslint-plugin-jest": {
-      "version": "27.0.4",
-      "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-27.0.4.tgz",
-      "integrity": "sha512-BuvY78pHMpMJ6Cio7sKg6jrqEcnRYPUc4Nlihku4vKx3FjlmMINSX4vcYokZIe+8TKcyr1aI5Kq7vYwgJNdQSA==",
+      "version": "27.1.3",
+      "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-27.1.3.tgz",
+      "integrity": "sha512-7DrIfYRQPa7JQd1Le8G/BJsfYHVUKQdJQ/6vULSp/4NjKZmSMJ/605G2hhScEra++SiH68zPEjLnrO74nHrMLg==",
       "dev": true,
       "requires": {
         "@typescript-eslint/utils": "^5.10.0"
diff --git a/package.json b/package.json
index e833180..9ca1bf0 100644
--- a/package.json
+++ b/package.json
@@ -169,7 +169,7 @@
     "css-loader": "6.7.1",
     "electron-builder": "23.6.0",
     "eslint": "8.26.0",
-    "eslint-plugin-jest": "27.0.4",
+    "eslint-plugin-jest": "27.1.3",
     "jest": "29.2.2",
     "jest-environment-jsdom": "29.2.2",
     "jest-environment-node": "29.2.2",
diff --git a/src/tab-manager/context-menu.js b/src/tab-manager/context-menu.js
index b5a95de..260bc64 100644
--- a/src/tab-manager/context-menu.js
+++ b/src/tab-manager/context-menu.js
@@ -65,10 +65,14 @@ const spellCheckContextMenu = async (event, params) => {
 
 const regularContextMenu = (event, params) => {
   const menu = new Menu();
-  entries(event, params).forEach(group => {
+  const isVisible = me => !Object.keys(me).includes('visible') || me.visible === true;
+  entries(event, params).forEach((group, idx, arr) => {
     for (const entry of group) {
       menu.append(new MenuItem({...entry}));
     }
+    if (group.filter(isVisible).length > 0 && idx < arr.length - 1) {
+      menu.append(new MenuItem({type: 'separator'}));
+    }
   });
   return menu;
 };


Test patch:
diff --git a/src/tab-manager/__tests__/context-menu.test.js b/src/tab-manager/__tests__/context-menu.test.js
index 1649fe3..05ce9f4 100644
--- a/src/tab-manager/__tests__/context-menu.test.js
+++ b/src/tab-manager/__tests__/context-menu.test.js
@@ -18,18 +18,18 @@ describe('Tab Manager context-menu test suite', () => {
   let event;
   let listeners;
   let mockMenu;
-  let mockMenuItem;
   let params;
   let tabManager;
   beforeEach(() => {
     jest.resetModules();
     mockMenu = {
-      append: jest.fn(),
+      entries: [],
+      append: jest.fn(e => mockMenu.entries.push(e)),
       popup: jest.fn()
     };
     jest.mock('electron', () => require('../../__tests__').mockElectronInstance({
       Menu: jest.fn(() => mockMenu),
-      MenuItem: jest.fn(() => mockMenuItem)
+      MenuItem: jest.fn(def => def)
     }));
     jest.mock('../../settings', () => ({
       loadSettings: jest.fn(() => ({
@@ -106,6 +106,15 @@ describe('Tab Manager context-menu test suite', () => {
       'adds MenuItem with label %s', async label => {
         expect(electron.MenuItem).toHaveBeenCalledWith(expect.objectContaining({label}));
       });
+    describe('separator', () => {
+      test('groups are separated by a separator', async () => {
+        // separator after Back and Reload
+        expect(mockMenu.entries[2].type).toBe('separator');
+      });
+      test('last item is not a separator', () => {
+        expect(mockMenu.entries[mockMenu.entries.length - 1].type).not.toBe('separator');
+      });
+    });
     describe('Back', () => {
       test('disabled when canGoBack returns false', async () => {
         expect(electron.MenuItem).toHaveBeenCalledWith(expect.objectContaining({