go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/frontend/ui/src/components/cl_list/cl_list.test.tsx (about)

     1  // Copyright 2022 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 '@testing-library/jest-dom';
    16  import {
    17    fireEvent,
    18    render,
    19    screen,
    20    waitForElementToBeRemoved,
    21  } from '@testing-library/react';
    22  
    23  import { Changelist, ChangelistOwnerKind } from '@/proto/go.chromium.org/luci/analysis/proto/v1/sources.pb';
    24  
    25  import CLList from './cl_list';
    26  
    27  describe('Test CLList component', () => {
    28    it('given no CLs', async () => {
    29      const { container } = render(
    30          <CLList changelists={[]}/>,
    31      );
    32      expect(container).toBeEmptyDOMElement();
    33    });
    34  
    35    it('given a single CL', async () => {
    36      const changelist: Changelist = {
    37        host: 'chromium-review.googlesource.com',
    38        change: '12345678901234',
    39        patchset: 543,
    40        ownerKind: ChangelistOwnerKind.HUMAN,
    41      };
    42      render(
    43          <CLList changelists={[changelist]}/>,
    44      );
    45  
    46      await screen.findByText('12345678901234 #543');
    47  
    48      expect(screen.getByText('12345678901234 #543')).toBeInTheDocument();
    49      expect(screen.queryByText('...')).toBeNull();
    50    });
    51  
    52    it('given a multiple CLs', async () => {
    53      const changelists: Changelist[] = [{
    54        host: 'chromium-review.googlesource.com',
    55        change: '12345678901234',
    56        patchset: 543,
    57        ownerKind: ChangelistOwnerKind.HUMAN,
    58      }, {
    59        host: 'chromium-internal-review.googlesource.com',
    60        change: '85132217',
    61        patchset: 432,
    62        ownerKind: ChangelistOwnerKind.HUMAN,
    63      }];
    64      render(
    65          <CLList changelists={changelists}/>,
    66      );
    67  
    68      expect(await screen.findByText('12345678901234 #543')).toBeInTheDocument();
    69      expect(screen.getByText('...')).toBeInTheDocument();
    70      expect(screen.queryByText('85132217 #432')).toBeNull();
    71  
    72      fireEvent.click(screen.getByText('...'));
    73  
    74      expect(await screen.findByText('85132217 #432')).toBeInTheDocument();
    75  
    76      fireEvent.click(screen.getByText('...'));
    77  
    78      await waitForElementToBeRemoved(() => screen.queryByText('85132217 #432'));
    79      expect(screen.queryByText('85132217 #432')).toBeNull();
    80    });
    81  });