go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/common/layouts/side_bar/pages.test.tsx (about)

     1  // Copyright 2023 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  import AccessTimeIcon from '@mui/icons-material/AccessTime';
    16  import BuildIcon from '@mui/icons-material/Build';
    17  import EngineeringIcon from '@mui/icons-material/Engineering';
    18  import GrainTwoToneIcon from '@mui/icons-material/GrainTwoTone';
    19  import HouseIcon from '@mui/icons-material/House';
    20  import LineAxisIcon from '@mui/icons-material/LineAxis';
    21  import LineStyleIcon from '@mui/icons-material/LineStyle';
    22  import ScheduleIcon from '@mui/icons-material/Schedule';
    23  import SearchIcon from '@mui/icons-material/Search';
    24  import SpeedIcon from '@mui/icons-material/Speed';
    25  import SpokeIcon from '@mui/icons-material/Spoke';
    26  import TableViewIcon from '@mui/icons-material/TableView';
    27  import VisibilityIcon from '@mui/icons-material/Visibility';
    28  
    29  import { UiPage } from '@/common/constants/view';
    30  
    31  import {
    32    SidebarSection,
    33    generateSidebarSections,
    34    getSomProject,
    35  } from './pages';
    36  
    37  describe('generateSidebarSections', () => {
    38    it('should generate list with only builders search if there is no project', () => {
    39      const sidebarItems = generateSidebarSections(undefined);
    40      expect(sidebarItems).toEqual<SidebarSection[]>([
    41        {
    42          title: `Builds`,
    43          pages: [
    44            {
    45              page: UiPage.BuilderSearch,
    46              url: '/ui/builder-search',
    47              icon: <SearchIcon />,
    48            },
    49          ],
    50        },
    51      ]);
    52    });
    53  
    54    it('should generate basic items for all projects', () => {
    55      const sidebarItems = generateSidebarSections('projecttest');
    56      expect(sidebarItems).toEqual<SidebarSection[]>([
    57        {
    58          title: `Builds`,
    59          pages: [
    60            {
    61              page: UiPage.BuilderSearch,
    62              url: '/ui/builder-search',
    63              icon: <SearchIcon />,
    64            },
    65            {
    66              page: UiPage.Builders,
    67              url: `/ui/p/projecttest/builders`,
    68              icon: <BuildIcon />,
    69            },
    70            {
    71              page: UiPage.BuilderGroups,
    72              url: '/ui/p/projecttest',
    73              icon: <TableViewIcon />,
    74            },
    75            {
    76              page: UiPage.Scheduler,
    77              url: `https://luci-scheduler.appspot.com/jobs/projecttest`,
    78              icon: <ScheduleIcon />,
    79              external: true,
    80            },
    81          ],
    82        },
    83        {
    84          title: `Tests`,
    85          pages: [
    86            {
    87              page: UiPage.TestHistory,
    88              url: `/ui/p/projecttest/test-search`,
    89              icon: <AccessTimeIcon />,
    90            },
    91            {
    92              page: UiPage.FailureClusters,
    93              url: `https://${SETTINGS.luciAnalysis.host}/p/projecttest/clusters`,
    94              icon: <SpokeIcon />,
    95              external: true,
    96            },
    97          ],
    98        },
    99      ]);
   100    });
   101  
   102    it('should generate correct links for chromium', () => {
   103      const sidebarItems = generateSidebarSections('chromium');
   104      expect(sidebarItems).toEqual<SidebarSection[]>([
   105        {
   106          title: `Builds`,
   107          pages: [
   108            {
   109              page: UiPage.BuilderSearch,
   110              url: '/ui/builder-search',
   111              icon: <SearchIcon />,
   112            },
   113            {
   114              page: UiPage.Builders,
   115              url: `/ui/p/chromium/builders`,
   116              icon: <BuildIcon />,
   117            },
   118            {
   119              page: UiPage.BuilderGroups,
   120              url: '/ui/p/chromium',
   121              icon: <TableViewIcon />,
   122            },
   123            {
   124              page: UiPage.Scheduler,
   125              url: `https://luci-scheduler.appspot.com/jobs/chromium`,
   126              icon: <ScheduleIcon />,
   127              external: true,
   128            },
   129            {
   130              page: UiPage.Bisection,
   131              url: `/ui/p/chromium/bisection`,
   132              icon: <GrainTwoToneIcon />,
   133            },
   134          ],
   135        },
   136        {
   137          title: `Tests`,
   138          pages: [
   139            {
   140              page: UiPage.TestHistory,
   141              url: `/ui/p/chromium/test-search`,
   142              icon: <AccessTimeIcon />,
   143            },
   144            {
   145              page: UiPage.FailureClusters,
   146              url: `https://${SETTINGS.luciAnalysis.host}/p/chromium/clusters`,
   147              icon: <SpokeIcon />,
   148              external: true,
   149            },
   150          ],
   151        },
   152        {
   153          title: 'Monitoring',
   154          pages: [
   155            {
   156              page: UiPage.SoM,
   157              url: 'https://sheriff-o-matic.appspot.com/chromium',
   158              icon: <EngineeringIcon />,
   159              external: true,
   160            },
   161          ],
   162        },
   163        {
   164          title: 'Releases',
   165          pages: [
   166            {
   167              page: UiPage.ChromiumDash,
   168              url: 'https://chromiumdash.appspot.com/',
   169              icon: <LineStyleIcon />,
   170              external: true,
   171            },
   172          ],
   173        },
   174      ]);
   175    });
   176  
   177    it('should generate correct links for chromeos', () => {
   178      const sidebarItems = generateSidebarSections('chromeos');
   179      expect(sidebarItems).toEqual<SidebarSection[]>([
   180        {
   181          title: `Builds`,
   182          pages: [
   183            {
   184              page: UiPage.BuilderSearch,
   185              url: '/ui/builder-search',
   186              icon: <SearchIcon />,
   187            },
   188            {
   189              page: UiPage.Builders,
   190              url: `/ui/p/chromeos/builders`,
   191              icon: <BuildIcon />,
   192            },
   193            {
   194              page: UiPage.BuilderGroups,
   195              url: '/ui/p/chromeos',
   196              icon: <TableViewIcon />,
   197            },
   198            {
   199              page: UiPage.Scheduler,
   200              url: `https://luci-scheduler.appspot.com/jobs/chromeos`,
   201              icon: <ScheduleIcon />,
   202              external: true,
   203            },
   204          ],
   205        },
   206        {
   207          title: `Tests`,
   208          pages: [
   209            {
   210              page: UiPage.TestHistory,
   211              url: `/ui/p/chromeos/test-search`,
   212              icon: <AccessTimeIcon />,
   213            },
   214            {
   215              page: UiPage.FailureClusters,
   216              url: `https://${SETTINGS.luciAnalysis.host}/p/chromeos/clusters`,
   217              icon: <SpokeIcon />,
   218              external: true,
   219            },
   220            {
   221              page: UiPage.Testhaus,
   222              url: `https://tests.chromeos.goog`,
   223              icon: <HouseIcon />,
   224              external: true,
   225            },
   226            {
   227              page: UiPage.Crosbolt,
   228              url: `https://healthmon.chromeos.goog/time_series`,
   229              icon: <SpeedIcon />,
   230              external: true,
   231            },
   232          ],
   233        },
   234        {
   235          title: 'Monitoring',
   236          pages: [
   237            {
   238              page: UiPage.SoM,
   239              url: 'https://sheriff-o-matic.appspot.com/chromeos',
   240              icon: <EngineeringIcon />,
   241              external: true,
   242            },
   243            {
   244              page: UiPage.CQStatus,
   245              url: `http://go/cros-cq-status`,
   246              icon: <LineAxisIcon />,
   247              external: true,
   248            },
   249          ],
   250        },
   251        {
   252          title: 'Releases',
   253          pages: [
   254            {
   255              page: UiPage.Goldeneye,
   256              url: 'https://cros-goldeneye.corp.google.com/',
   257              icon: <VisibilityIcon />,
   258              external: true,
   259            },
   260          ],
   261        },
   262      ]);
   263    });
   264  });
   265  
   266  describe('getSomProject', () => {
   267    it('given unknown project, should not generate item', () => {
   268      expect(getSomProject('unknown')).toBeNull();
   269    });
   270  
   271    it.each([
   272      ['chromeos', 'chromeos'],
   273      ['chrome', 'chromium'],
   274      ['chromium', 'chromium'],
   275      ['fuchsia', 'fuchsia'],
   276      ['turquoise', 'fuchsia'],
   277    ])(
   278      'given %p project, should generate matching link',
   279      (project: string, somProject: string) => {
   280        expect(getSomProject(project)).toStrictEqual(somProject);
   281      },
   282    );
   283  });