go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/monitoring/components/alert_table/alert_table.test.tsx (about)

     1  // Copyright 2024 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 { act, fireEvent, render, screen } from '@testing-library/react';
    16  
    17  import { configuredTrees } from '@/monitoring/util/config';
    18  import { AlertJson, RevisionJson } from '@/monitoring/util/server_json';
    19  import { FakeContextProvider } from '@/testing_tools/fakes/fake_context_provider';
    20  
    21  import { AlertTable } from './alert_table';
    22  
    23  it('displays an alert', async () => {
    24    render(
    25      <FakeContextProvider>
    26        <AlertTable
    27          tree={configuredTrees[0]}
    28          alerts={[alert]}
    29          bugs={[]}
    30          alertBugs={{}}
    31        />
    32      </FakeContextProvider>,
    33    );
    34    expect(screen.getByText('linux-rel')).toBeInTheDocument();
    35    expect(screen.getByText('compile')).toBeInTheDocument();
    36  });
    37  
    38  it('expands an alert on click', async () => {
    39    render(
    40      <FakeContextProvider>
    41        <AlertTable
    42          tree={configuredTrees[0]}
    43          alerts={[alert]}
    44          bugs={[]}
    45          alertBugs={{}}
    46        />
    47      </FakeContextProvider>,
    48    );
    49    expect(screen.getByText('compile')).toBeInTheDocument();
    50    expect(screen.queryByText('test.Example')).toBeNull();
    51    await act(() => fireEvent.click(screen.getByText('compile')));
    52    expect(screen.getByText('test.Example')).toBeInTheDocument();
    53  });
    54  
    55  const revision: RevisionJson = {
    56    author: 'Player 1',
    57    branch: 'main',
    58    commit_position: 123,
    59    description: 'A fun CL.',
    60    git_hash: '12345677',
    61    host: 'host',
    62    link: 'host/123',
    63    repo: 'chromium/src',
    64    when: 1,
    65  };
    66  
    67  const alert: AlertJson = {
    68    key: 'alert-1',
    69    title: 'Step "compile" failuing on builder linux-rel',
    70    body: '',
    71    links: null,
    72    resolved: false,
    73    severity: 1,
    74    start_time: new Date().valueOf(),
    75    tags: null,
    76    time: new Date().valueOf(),
    77    type: 'compile',
    78    extension: {
    79      builders: [
    80        {
    81          project: 'chromium',
    82          builder_group: 'linux',
    83          bucket: 'ci',
    84          name: 'linux-rel',
    85          build_status: 'FAILED',
    86          count: 2,
    87          start_time: new Date().valueOf(),
    88          url: '/p/chromium/b/linux-rel',
    89          failing_tests_trunc: '',
    90          latest_passing: 3,
    91          first_failing_rev: { ...revision, commit_position: 10 },
    92          first_failure: 23,
    93          first_failure_build_number: 342,
    94          first_failure_url: '/b/342',
    95          last_passing_rev: { ...revision, commit_position: 5 },
    96          latest_failure: 46,
    97          latest_failure_build_number: 356,
    98          latest_failure_url: '/b/356',
    99        },
   100      ],
   101      culprits: null,
   102      has_findings: false,
   103      is_finished: false,
   104      is_supported: false,
   105      regression_ranges: [],
   106      suspected_cls: null,
   107      tree_closer: false,
   108      reason: {
   109        num_failing_tests: 0,
   110        step: 'test step',
   111        tests: [
   112          {
   113            test_id: 'ninja://test.Example',
   114            realm: 'ci',
   115            test_name: 'test.Example',
   116            cluster_name: 'chromium/rules-v2/4242',
   117            variant_hash: '1234',
   118            cur_counts: {
   119              unexpected_results: 10,
   120              total_results: 10,
   121            },
   122            cur_start_hour: '9:00',
   123            regression_start_position: 123450,
   124            prev_counts: {
   125              unexpected_results: 1,
   126              total_results: 100,
   127            },
   128            prev_end_hour: '8:00',
   129            regression_end_position: 123456,
   130            ref_hash: '5678',
   131          },
   132        ],
   133      },
   134    },
   135  };