go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/frontend/ui/cypress/integration/bug_page.spec.ts (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  import { setupTestRule } from './test_data';
    15  
    16  describe('Bug Page', () => {
    17    beforeEach(() => {
    18      // Login.
    19      cy.visit('/').contains('Log in').click();
    20      cy.contains('LOGIN').click();
    21  
    22      setupTestRule();
    23    });
    24  
    25    it('redirects if single matching rule found', () => {
    26      cy.visit('/b/chromium/920867');
    27      cy.get('[data-testid=bug]').contains('crbug.com/920867');
    28    });
    29  
    30    it('no matching rule exists', () => {
    31      cy.visit('/b/chromium/404');
    32      cy.get('bug-page').contains('No rule found matching the specified bug (monorail:chromium/404).');
    33    });
    34  
    35    it('multiple matching rules found', () => {
    36      cy.intercept('POST', '/prpc/luci.analysis.v1.Rules/LookupBug', (req) => {
    37        const requestBody = req.body;
    38        assert.deepEqual(requestBody, { system: 'monorail', id: 'chromium/1234' });
    39  
    40        const response = {
    41          // This is a real rule that exists in the dev database, the
    42          // same used for rule section UI tests.
    43          rules: [
    44            'projects/chromium/rules/ea5305bc5069b449ee43ee64d26d667f',
    45            'projects/chromiumos/rules/1234567890abcedf1234567890abcdef',
    46          ],
    47        };
    48        // Construct pRPC response.
    49        const body = ')]}\'\n' + JSON.stringify(response);
    50        req.reply(body, {
    51          'X-Prpc-Grpc-Code': '0',
    52        });
    53      }).as('lookupBug');
    54  
    55      cy.visit('/b/chromium/1234');
    56      cy.wait('@lookupBug');
    57  
    58      cy.get('body').contains('chromiumos');
    59      cy.get('body').contains('chromium').click();
    60  
    61      cy.get('[data-testid=rule-definition]').contains('test = "cypress test 1"');
    62    });
    63  });