github.com/freiheit-com/kuberpult@v1.24.2-0.20240328135542-315d5630abe6/services/frontend-service/src/ui/utils/LoadingStateSpinner.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 { render } from '@testing-library/react';
    17  import React from 'react';
    18  import { LoadingStateSpinner } from './LoadingStateSpinner';
    19  import { GlobalLoadingState } from './store';
    20  import { elementQuerySelectorSafe } from '../../setupTests';
    21  
    22  const cases: { name: string; inputState: GlobalLoadingState; expectedMessage: string }[] = [
    23      {
    24          name: 'Everything ready',
    25          inputState: {
    26              configReady: true,
    27              azureAuthEnabled: true,
    28              isAuthenticated: true,
    29              overviewLoaded: true,
    30          },
    31          expectedMessage: 'Loading...',
    32      },
    33      {
    34          name: 'Config not ready',
    35          inputState: {
    36              configReady: false,
    37              azureAuthEnabled: true,
    38              isAuthenticated: true,
    39              overviewLoaded: true,
    40          },
    41          expectedMessage: 'Loading Configuration...',
    42      },
    43      {
    44          name: 'Auth not ready',
    45          inputState: {
    46              configReady: true,
    47              azureAuthEnabled: true,
    48              isAuthenticated: false,
    49              overviewLoaded: true,
    50          },
    51          expectedMessage: 'Authenticating with Azure...',
    52      },
    53      {
    54          name: 'Auth not ready but also not enabled',
    55          inputState: {
    56              configReady: true,
    57              azureAuthEnabled: false,
    58              isAuthenticated: false,
    59              overviewLoaded: true,
    60          },
    61          expectedMessage: 'Loading...',
    62      },
    63      {
    64          name: 'Auth not ready',
    65          inputState: {
    66              configReady: true,
    67              azureAuthEnabled: true,
    68              isAuthenticated: true,
    69              overviewLoaded: false,
    70          },
    71          expectedMessage: 'Loading Overview...',
    72      },
    73  ];
    74  
    75  describe('LoadingStateSpinner', () => {
    76      const getWrapper = (loadingState: GlobalLoadingState) =>
    77          render(<LoadingStateSpinner loadingState={loadingState} />);
    78  
    79      describe.each(cases)('Renders the correct message', (testcase) => {
    80          it(testcase.name, () => {
    81              //given
    82              const { container } = getWrapper(testcase.inputState);
    83              // when
    84              const message = elementQuerySelectorSafe(container, '.spinner-message');
    85  
    86              // then
    87              expect(message?.textContent).toEqual(testcase.expectedMessage);
    88          });
    89      });
    90  });