go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/common/tools/url_utils/url_utils.test.ts (about)

     1  // Copyright 2023 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 {
    16    getBuilderURLPath,
    17    getSwarmingBotListURL,
    18    getTestHistoryURLPath,
    19    setSingleQueryParam,
    20  } from './url_utils';
    21  
    22  describe('getBuilderURLPath', () => {
    23    test('should encode the builder', () => {
    24      const url = getBuilderURLPath({
    25        project: 'testproject',
    26        bucket: 'testbucket',
    27        builder: 'test builder',
    28      });
    29      expect(url).toStrictEqual(
    30        '/ui/p/testproject/builders/testbucket/test%20builder',
    31      );
    32    });
    33  });
    34  
    35  describe('getTestHisotryURLPath', () => {
    36    test('should encode the test ID', () => {
    37      const url = getTestHistoryURLPath('testproject', 'test/id');
    38      expect(url).toStrictEqual('/ui/test/testproject/test%2Fid');
    39    });
    40  });
    41  
    42  describe('getSwarmingBotListURL', () => {
    43    test('should support multiple dimensions', () => {
    44      const url = getSwarmingBotListURL('chromium-swarm-dev.appspot.com', [
    45        'cpu:x86-64',
    46        'os:Windows-11',
    47      ]);
    48      expect(url).toStrictEqual(
    49        'https://chromium-swarm-dev.appspot.com/botlist?f=cpu%3Ax86-64&f=os%3AWindows-11',
    50      );
    51    });
    52  });
    53  
    54  describe('setSingleQueryParam', () => {
    55    it('should set parameter string value', () => {
    56      const parameterString = 'a=b&c=d';
    57      const updatedParams = setSingleQueryParam(parameterString, 'e', 'f');
    58      expect(updatedParams.toString()).toEqual('a=b&c=d&e=f');
    59    });
    60  
    61    it('should update parameter string value', () => {
    62      const parameterString = 'a=b&c=d';
    63      const updatedParams = setSingleQueryParam(parameterString, 'a', 'f');
    64      expect(updatedParams.toString()).toEqual('a=f&c=d');
    65    });
    66  });