go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/bisection/tools/link_constructors.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 { BuilderID } from '@/proto/go.chromium.org/luci/buildbucket/proto/builder_common.pb'; 16 import { GitilesCommit } from '@/proto/go.chromium.org/luci/buildbucket/proto/common.pb'; 17 18 import { 19 linkToBuild, 20 linkToBuilder, 21 linkToCommit, 22 linkToCommitRange, 23 } from './link_constructors'; 24 25 describe('Test link constructors', () => { 26 test('getting link to build', () => { 27 expect(linkToBuild('12345678987654321')).toStrictEqual({ 28 linkText: '12345678987654321', 29 url: 'https://ci.chromium.org/b/12345678987654321', 30 }); 31 }); 32 33 test('getting link to builder', () => { 34 const mockBuilder: BuilderID = { 35 project: 'mockProject', 36 bucket: 'mockBucket', 37 builder: 'mockBuilder', 38 }; 39 expect(linkToBuilder(mockBuilder)).toStrictEqual({ 40 linkText: 'mockProject/mockBucket/mockBuilder', 41 url: 'https://ci.chromium.org/p/mockProject/builders/mockBucket/mockBuilder', 42 }); 43 }); 44 45 test('getting link to commit', () => { 46 const mockCommit: GitilesCommit = { 47 host: 'mockHost', 48 project: 'mockProject', 49 id: '123456abcdef', 50 ref: 'ref/main', 51 position: 321, 52 }; 53 expect(linkToCommit(mockCommit)).toStrictEqual({ 54 linkText: '123456a', 55 url: 'https://mockHost/mockProject/+/123456abcdef', 56 }); 57 }); 58 59 test('getting link to commit range', () => { 60 const firstMockCommit: GitilesCommit = { 61 host: 'mockHost', 62 project: 'mockProject', 63 id: '123456abcdef', 64 ref: 'ref/main', 65 position: 321, 66 }; 67 const secondMockCommit: GitilesCommit = { 68 host: 'mockHost', 69 project: 'mockProject', 70 id: '987654fedcba', 71 ref: 'ref/main', 72 position: 654, 73 }; 74 expect(linkToCommitRange(firstMockCommit, secondMockCommit)).toStrictEqual({ 75 linkText: '123456a ... 987654f', 76 url: 'https://mockHost/mockProject/+log/123456abcdef..987654fedcba', 77 }); 78 }); 79 });