From 0958c333838a9b5d1d1f853a3c75b693481e544e Mon Sep 17 00:00:00 2001 From: Rodley Orosa Date: Mon, 26 Feb 2024 12:37:21 +0100 Subject: [PATCH 1/3] fix: prevent overwriting display of main route if focus mode is true Refs: SHELL-188 --- .../module-version-settings.test.tsx | 146 ++++++++++++++++++ src/store/app/store.ts | 2 +- 2 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 src/settings/components/general-settings/module-version-settings.test.tsx diff --git a/src/settings/components/general-settings/module-version-settings.test.tsx b/src/settings/components/general-settings/module-version-settings.test.tsx new file mode 100644 index 00000000..36981df5 --- /dev/null +++ b/src/settings/components/general-settings/module-version-settings.test.tsx @@ -0,0 +1,146 @@ +/* + * SPDX-FileCopyrightText: 2024 Zextras + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import React from 'react'; + +import { act } from '@testing-library/react'; +import { produce } from 'immer'; + +import ModuleVersionSettings from './module-version-settings'; +import { useAppStore } from '../../../store/app'; +import { screen, setup } from '../../../test/utils'; + +describe('Module Version Settings', () => { + it('should render the application version section', () => { + const description = 'Mails module'; + const display = 'Mails'; + const version = '1.11.1'; + useAppStore.setState( + produce((state) => { + state.apps = [ + { + description, + display, + name: 'carbonio-mails-ui', + version + } + ]; + }) + ); + + setup(); + + expect(screen.getByText(/application versions/i)).toBeVisible(); + expect(screen.getByText(display)).toBeVisible(); + expect(screen.getByText(description)).toBeVisible(); + expect(screen.getByText(`Version: ${version}`)).toBeVisible(); + expect(screen.getByText(/active/i)).toBeVisible(); + }); + + it('should not render the carbonio shell application version', () => { + const description = 'The Zextras Carbonio web client'; + const display = 'Shell'; + const version = '5.1.0'; + setup(); + act(() => { + useAppStore.getState().setters.setApps([ + { + commit: '', + description, + display, + icon: 'CubeOutline', + js_entrypoint: '', + name: 'carbonio-shell-ui', + priority: -1, + type: 'shell', + version + } + ]); + expect(screen.getByText(/application versions/i)).toBeVisible(); + expect(screen.queryByText(display)).not.toBeInTheDocument(); + expect(screen.queryByText(description)).not.toBeInTheDocument(); + expect(screen.queryByText(`Version: ${version}`)).not.toBeInTheDocument(); + }); + }); + + it('should not overwrite display of "main" route if focus mode is true', () => { + setup(); + const display1 = 'Chats'; + const version1 = '1.8.1'; + const description1 = 'Chats module'; + const display2 = 'Meetings'; + const description2 = 'Chats Module for Zextras Carbonio'; + const version2 = '0.9.1'; + act(() => { + useAppStore.getState().setters.setApps([ + { + commit: '', + description: 'Chats module', + display: 'Chats', + icon: 'TeamOutline', + js_entrypoint: '', + name: 'carbonio-chats-ui', + priority: 8, + type: 'carbonio', + version: '1.8.1' + }, + { + commit: '', + description: 'Chats Module for Zextras Carbonio', + display: 'Chats', + icon: 'DriveOutline', + js_entrypoint: '', + name: 'carbonio-ws-collaboration-ui', + priority: 404, + type: 'carbonio', + version: '0.9.1' + } + ]); + + useAppStore.getState().setters.addRoute({ + app: 'carbonio-ws-collaboration-ui', + appView: jest.fn(), + badge: { + show: false + }, + focusMode: undefined, + id: 'chats', + label: 'Chats', + position: 404, + primaryBar: '', + route: 'chats', + secondaryBar: jest.fn(), + visible: true + }); + + useAppStore.getState().setters.addRoute({ + app: 'carbonio-ws-collaboration-ui', + appView: jest.fn(), + badge: { + show: false + }, + focusMode: true, + id: 'meetings', + label: 'Meetings', + position: 404, + primaryBar: 'TeamOutline', + route: 'meetings', + secondaryBar: jest.fn(), + visible: false + }); + }); + expect(screen.getByText(/application versions/i)).toBeVisible(); + const labels = screen.getAllByText(display1); + expect(labels).toHaveLength(2); + expect(labels[0]).toBeVisible(); + expect(labels[1]).toBeVisible(); + expect(screen.getByText(description1)).toBeVisible(); + expect(screen.getByText(`Version: ${version1}`)).toBeVisible(); + expect(screen.queryByText(display2)).not.toBeInTheDocument(); + expect(screen.getByText(description2)).toBeVisible(); + expect(screen.getByText(`Version: ${version2}`)).toBeVisible(); + }); +}); diff --git a/src/store/app/store.ts b/src/store/app/store.ts index c2f89eda..0fa80472 100644 --- a/src/store/app/store.ts +++ b/src/store/app/store.ts @@ -149,7 +149,7 @@ export const useAppStore = create()((set, get) => ({ component: routeData.appView }); } - if (routeData.app && state.apps[routeData.app]) { + if (routeData.app && state.apps[routeData.app] && routeData.focusMode !== true) { state.apps[routeData.app].display = routeData.label; } }) From 5635b459d25bbff0e43e3bf81494a736b9147600 Mon Sep 17 00:00:00 2001 From: Rodley Orosa Date: Tue, 27 Feb 2024 09:45:46 +0100 Subject: [PATCH 2/3] refactor: apply review hints Refs: SHELL-188 --- .../module-version-settings.test.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/settings/components/general-settings/module-version-settings.test.tsx b/src/settings/components/general-settings/module-version-settings.test.tsx index 36981df5..ccfb4685 100644 --- a/src/settings/components/general-settings/module-version-settings.test.tsx +++ b/src/settings/components/general-settings/module-version-settings.test.tsx @@ -44,7 +44,6 @@ describe('Module Version Settings', () => { const description = 'The Zextras Carbonio web client'; const display = 'Shell'; const version = '5.1.0'; - setup(); act(() => { useAppStore.getState().setters.setApps([ { @@ -59,6 +58,7 @@ describe('Module Version Settings', () => { version } ]); + setup(); expect(screen.getByText(/application versions/i)).toBeVisible(); expect(screen.queryByText(display)).not.toBeInTheDocument(); expect(screen.queryByText(description)).not.toBeInTheDocument(); @@ -67,7 +67,6 @@ describe('Module Version Settings', () => { }); it('should not overwrite display of "main" route if focus mode is true', () => { - setup(); const display1 = 'Chats'; const version1 = '1.8.1'; const description1 = 'Chats module'; @@ -78,25 +77,25 @@ describe('Module Version Settings', () => { useAppStore.getState().setters.setApps([ { commit: '', - description: 'Chats module', + description: description1, display: 'Chats', icon: 'TeamOutline', js_entrypoint: '', name: 'carbonio-chats-ui', priority: 8, type: 'carbonio', - version: '1.8.1' + version: version1 }, { commit: '', - description: 'Chats Module for Zextras Carbonio', + description: description2, display: 'Chats', icon: 'DriveOutline', js_entrypoint: '', name: 'carbonio-ws-collaboration-ui', priority: 404, type: 'carbonio', - version: '0.9.1' + version: version2 } ]); @@ -108,7 +107,7 @@ describe('Module Version Settings', () => { }, focusMode: undefined, id: 'chats', - label: 'Chats', + label: display1, position: 404, primaryBar: '', route: 'chats', @@ -124,7 +123,7 @@ describe('Module Version Settings', () => { }, focusMode: true, id: 'meetings', - label: 'Meetings', + label: display2, position: 404, primaryBar: 'TeamOutline', route: 'meetings', @@ -132,6 +131,7 @@ describe('Module Version Settings', () => { visible: false }); }); + setup(); expect(screen.getByText(/application versions/i)).toBeVisible(); const labels = screen.getAllByText(display1); expect(labels).toHaveLength(2); From 8cd2787dcf0c0b6e1213a2bd4f5094588fad6d29 Mon Sep 17 00:00:00 2001 From: Rodley Orosa Date: Tue, 27 Feb 2024 10:24:59 +0100 Subject: [PATCH 3/3] test: apply review hints Refs: SHELL-188 --- .../module-version-settings.test.tsx | 147 +++++++++--------- 1 file changed, 71 insertions(+), 76 deletions(-) diff --git a/src/settings/components/general-settings/module-version-settings.test.tsx b/src/settings/components/general-settings/module-version-settings.test.tsx index ccfb4685..bcaf3309 100644 --- a/src/settings/components/general-settings/module-version-settings.test.tsx +++ b/src/settings/components/general-settings/module-version-settings.test.tsx @@ -6,7 +6,6 @@ import React from 'react'; -import { act } from '@testing-library/react'; import { produce } from 'immer'; import ModuleVersionSettings from './module-version-settings'; @@ -44,26 +43,24 @@ describe('Module Version Settings', () => { const description = 'The Zextras Carbonio web client'; const display = 'Shell'; const version = '5.1.0'; - act(() => { - useAppStore.getState().setters.setApps([ - { - commit: '', - description, - display, - icon: 'CubeOutline', - js_entrypoint: '', - name: 'carbonio-shell-ui', - priority: -1, - type: 'shell', - version - } - ]); - setup(); - expect(screen.getByText(/application versions/i)).toBeVisible(); - expect(screen.queryByText(display)).not.toBeInTheDocument(); - expect(screen.queryByText(description)).not.toBeInTheDocument(); - expect(screen.queryByText(`Version: ${version}`)).not.toBeInTheDocument(); - }); + useAppStore.getState().setters.setApps([ + { + commit: '', + description, + display, + icon: 'CubeOutline', + js_entrypoint: '', + name: 'carbonio-shell-ui', + priority: -1, + type: 'shell', + version + } + ]); + setup(); + expect(screen.getByText(/application versions/i)).toBeVisible(); + expect(screen.queryByText(display)).not.toBeInTheDocument(); + expect(screen.queryByText(description)).not.toBeInTheDocument(); + expect(screen.queryByText(`Version: ${version}`)).not.toBeInTheDocument(); }); it('should not overwrite display of "main" route if focus mode is true', () => { @@ -73,63 +70,61 @@ describe('Module Version Settings', () => { const display2 = 'Meetings'; const description2 = 'Chats Module for Zextras Carbonio'; const version2 = '0.9.1'; - act(() => { - useAppStore.getState().setters.setApps([ - { - commit: '', - description: description1, - display: 'Chats', - icon: 'TeamOutline', - js_entrypoint: '', - name: 'carbonio-chats-ui', - priority: 8, - type: 'carbonio', - version: version1 - }, - { - commit: '', - description: description2, - display: 'Chats', - icon: 'DriveOutline', - js_entrypoint: '', - name: 'carbonio-ws-collaboration-ui', - priority: 404, - type: 'carbonio', - version: version2 - } - ]); + useAppStore.getState().setters.setApps([ + { + commit: '', + description: description1, + display: 'Chats', + icon: 'TeamOutline', + js_entrypoint: '', + name: 'carbonio-chats-ui', + priority: 8, + type: 'carbonio', + version: version1 + }, + { + commit: '', + description: description2, + display: 'Chats', + icon: 'DriveOutline', + js_entrypoint: '', + name: 'carbonio-ws-collaboration-ui', + priority: 404, + type: 'carbonio', + version: version2 + } + ]); - useAppStore.getState().setters.addRoute({ - app: 'carbonio-ws-collaboration-ui', - appView: jest.fn(), - badge: { - show: false - }, - focusMode: undefined, - id: 'chats', - label: display1, - position: 404, - primaryBar: '', - route: 'chats', - secondaryBar: jest.fn(), - visible: true - }); + useAppStore.getState().setters.addRoute({ + app: 'carbonio-ws-collaboration-ui', + appView: jest.fn(), + badge: { + show: false + }, + focusMode: undefined, + id: 'chats', + label: display1, + position: 404, + primaryBar: '', + route: 'chats', + secondaryBar: jest.fn(), + visible: true + }); - useAppStore.getState().setters.addRoute({ - app: 'carbonio-ws-collaboration-ui', - appView: jest.fn(), - badge: { - show: false - }, - focusMode: true, - id: 'meetings', - label: display2, - position: 404, - primaryBar: 'TeamOutline', - route: 'meetings', - secondaryBar: jest.fn(), - visible: false - }); + useAppStore.getState().setters.addRoute({ + app: 'carbonio-ws-collaboration-ui', + appView: jest.fn(), + badge: { + show: false + }, + focusMode: true, + id: 'meetings', + label: display2, + position: 404, + primaryBar: 'TeamOutline', + route: 'meetings', + secondaryBar: jest.fn(), + visible: false }); setup(); expect(screen.getByText(/application versions/i)).toBeVisible();