diff --git a/index.html b/index.html index cec5d6ca6e..9dac9d0087 100644 --- a/index.html +++ b/index.html @@ -1,8 +1,8 @@ - + - + Greenbone Security Assistant @@ -11,5 +11,24 @@
+ diff --git a/src/web/components/layout/__tests__/__snapshots__/pagetitle.jsx.snap b/src/web/components/layout/__tests__/__snapshots__/pagetitle.jsx.snap deleted file mode 100644 index 2805c1d908..0000000000 --- a/src/web/components/layout/__tests__/__snapshots__/pagetitle.jsx.snap +++ /dev/null @@ -1,3 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`PageTitle tests > should render 1`] = `null`; diff --git a/src/web/components/layout/__tests__/pagetitle.jsx b/src/web/components/layout/__tests__/pagetitle.jsx index 3c9fc0419d..997fcc3449 100644 --- a/src/web/components/layout/__tests__/pagetitle.jsx +++ b/src/web/components/layout/__tests__/pagetitle.jsx @@ -3,20 +3,22 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ - import {describe, test, expect} from '@gsa/testing'; import PageTitle from 'web/components/layout/pagetitle'; -import {render} from 'web/utils/testing'; +import {rendererWith} from 'web/utils/testing'; -describe('PageTitle tests', () => { - test('should render', () => { - const {element} = render(); - expect(element).toMatchSnapshot(); - }); +const gmp = { + settings: { + vendorLabel: 'someVendorLabel', + }, +}; +describe('PageTitle tests', () => { test('Should render default title', () => { + const {render} = rendererWith({gmp}); + const defaultTitle = 'Greenbone Security Assistant'; render(); @@ -24,6 +26,8 @@ describe('PageTitle tests', () => { }); test('Should render custom title', () => { + const {render} = rendererWith({gmp}); + const title = 'foo'; const defaultTitle = 'Greenbone Security Assistant'; render(); @@ -32,6 +36,8 @@ describe('PageTitle tests', () => { }); test('should update value', () => { + const {render} = rendererWith({gmp}); + const title1 = 'foo'; const title2 = 'bar'; const defaultTitle = 'Greenbone Security Assistant'; @@ -43,4 +49,16 @@ describe('PageTitle tests', () => { expect(global.window.document.title).toBe(defaultTitle + ' - ' + title2); }); + test('should render appliance model title', () => { + const {render} = rendererWith({ + gmp: { + settings: { + vendorLabel: 'gsm-150_label.svg', + }, + }, + }); + render(); + + expect(global.window.document.title).toBe('Greenbone - 150'); + }); }); diff --git a/src/web/components/layout/pagetitle.jsx b/src/web/components/layout/pagetitle.jsx index b1382eacd0..a66ad27012 100644 --- a/src/web/components/layout/pagetitle.jsx +++ b/src/web/components/layout/pagetitle.jsx @@ -6,10 +6,15 @@ import {useEffect} from 'react'; import {isDefined} from 'gmp/utils/identity'; import PropTypes from 'web/utils/proptypes'; - -const defaultTitle = 'Greenbone Security Assistant'; +import useGmp from 'web/hooks/useGmp'; +import {applianceTitle} from 'web/utils/applianceData'; const PageTitle = ({title}) => { + const gmp = useGmp(); + const vendorLabel = gmp?.settings?.vendorLabel || 'defaultVendorLabel'; + const defaultTitle = + applianceTitle[vendorLabel] || 'Greenbone Security Assistant'; + useEffect(() => { if (isDefined(title)) { document.title = defaultTitle + ' - ' + title; @@ -20,7 +25,8 @@ const PageTitle = ({title}) => { return () => { document.title = defaultTitle; }; - }, [title]); + }, [defaultTitle, title]); + return null; }; diff --git a/src/web/utils/applianceData.js b/src/web/utils/applianceData.js new file mode 100644 index 0000000000..46de6bf3b9 --- /dev/null +++ b/src/web/utils/applianceData.js @@ -0,0 +1,62 @@ +/* SPDX-FileCopyrightText: 2024 Greenbone AG + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +const APPLIANCE_DATA = { + 'gsm-150_label.svg': { + title: 'Greenbone - 150', + }, + 'gsm-400_label.svg': { + title: 'Greenbone - 400', + }, + 'gsm-400r2_label.svg': { + title: 'Greenbone - 400', + }, + 'gsm-450_label.svg': { + title: 'Greenbone - 450', + }, + 'gsm-450r2_label.svg': { + title: 'Greenbone - 450', + }, + 'gsm-600_label.svg': { + title: 'Greenbone - 600', + }, + 'gsm-600r2_label.svg': { + title: 'Greenbone - 600', + }, + 'gsm-650_label.svg': { + title: 'Greenbone - 650', + }, + 'gsm-650r2_label.svg': { + title: 'Greenbone - 650', + }, + 'gsm-5400_label.svg': { + title: 'Greenbone - 5400', + }, + 'gsm-6500_label.svg': { + title: 'Greenbone - 6500', + }, + 'gsm-ceno_label.svg': { + title: 'Greenbone - CENO', + }, + 'gsm-deca_label.svg': { + title: 'Greenbone - DECA', + }, + 'gsm-exa_label.svg': { + title: 'Greenbone - EXA', + }, + 'gsm-peta_label.svg': { + title: 'Greenbone - PETA', + }, + 'gsm-tera_label.svg': { + title: 'Greenbone - TERA', + }, +}; + +export const applianceTitle = Object.fromEntries( + Object.entries(APPLIANCE_DATA).map(([vendorLabel, {title}]) => [ + vendorLabel, + title, + ]), +);