github.com/freiheit-com/kuberpult@v1.24.2-0.20240328135542-315d5630abe6/services/frontend-service/src/ui/components/Releases/Releases.test.tsx (about)

     1  /*This file is part of kuberpult.
     2  
     3  Kuberpult is free software: you can redistribute it and/or modify
     4  it under the terms of the Expat(MIT) License as published by
     5  the Free Software Foundation.
     6  
     7  Kuberpult is distributed in the hope that it will be useful,
     8  but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    10  MIT License for more details.
    11  
    12  You should have received a copy of the MIT License
    13  along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>.
    14  
    15  Copyright 2023 freiheit.com*/
    16  import { Releases } from './Releases';
    17  import { render } from '@testing-library/react';
    18  import { UpdateOverview } from '../../utils/store';
    19  import { Release, UndeploySummary } from '../../../api/api';
    20  import { MemoryRouter } from 'react-router-dom';
    21  
    22  describe('Release Dialog', () => {
    23      type TestData = {
    24          name: string;
    25          dates: number;
    26          releases: Release[];
    27      };
    28  
    29      const data: TestData[] = [
    30          {
    31              name: '3 releases in 3 days',
    32              dates: 3,
    33              releases: [
    34                  {
    35                      version: 1,
    36                      sourceMessage: 'test1',
    37                      sourceAuthor: 'test',
    38                      sourceCommitId: 'commit',
    39                      createdAt: new Date('2022-12-04T12:30:12'),
    40                      undeployVersion: false,
    41                      prNumber: '666',
    42                      displayVersion: '1',
    43                  },
    44                  {
    45                      version: 2,
    46                      sourceMessage: 'test1',
    47                      sourceAuthor: 'test',
    48                      sourceCommitId: 'commit',
    49                      createdAt: new Date('2022-12-05T12:30:12'),
    50                      undeployVersion: false,
    51                      prNumber: '666',
    52                      displayVersion: '2',
    53                  },
    54                  {
    55                      version: 3,
    56                      sourceMessage: 'test1',
    57                      sourceAuthor: 'test',
    58                      sourceCommitId: 'commit',
    59                      createdAt: new Date('2022-12-06T12:30:12'),
    60                      undeployVersion: false,
    61                      prNumber: '666',
    62                      displayVersion: '3',
    63                  },
    64              ],
    65          },
    66          {
    67              name: '3 releases in 2 days',
    68              dates: 2,
    69              releases: [
    70                  {
    71                      version: 1,
    72                      sourceMessage: 'test1',
    73                      sourceAuthor: 'test',
    74                      sourceCommitId: 'commit',
    75                      createdAt: new Date('2022-12-04T12:30:12'),
    76                      undeployVersion: false,
    77                      prNumber: '666',
    78                      displayVersion: '1',
    79                  },
    80                  {
    81                      version: 2,
    82                      sourceMessage: 'test1',
    83                      sourceAuthor: 'test',
    84                      sourceCommitId: 'commit',
    85                      createdAt: new Date('2022-12-04T15:30:12'),
    86                      undeployVersion: false,
    87                      prNumber: '666',
    88                      displayVersion: '2',
    89                  },
    90                  {
    91                      version: 3,
    92                      sourceMessage: 'test1',
    93                      sourceAuthor: 'test',
    94                      sourceCommitId: 'commit',
    95                      createdAt: new Date('2022-12-06T12:30:12'),
    96                      undeployVersion: false,
    97                      prNumber: '666',
    98                      displayVersion: '3',
    99                  },
   100              ],
   101          },
   102      ];
   103  
   104      describe.each(data)(`Renders releases for an app`, (testcase) => {
   105          it(testcase.name, () => {
   106              // when
   107              UpdateOverview.set({
   108                  applications: {
   109                      test: {
   110                          releases: testcase.releases,
   111                          name: 'test',
   112                          sourceRepoUrl: 'url',
   113                          undeploySummary: UndeploySummary.NORMAL,
   114                          team: 'no-team',
   115                          warnings: [],
   116                      },
   117                  },
   118              });
   119              render(
   120                  <MemoryRouter>
   121                      <Releases app="test" />
   122                  </MemoryRouter>
   123              );
   124  
   125              expect(document.querySelectorAll('.release_date')).toHaveLength(testcase.dates);
   126              expect(document.querySelectorAll('.content')).toHaveLength(testcase.releases.length);
   127          });
   128      });
   129  });