go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/build/legacy/build_page/steps_tab/step_cluster.test.ts (about) 1 // Copyright 2021 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 { fixture, html } from '@open-wc/testing-helpers'; 16 17 import { BuildbucketStatus } from '@/common/services/buildbucket'; 18 import { Store } from '@/common/store'; 19 import { StepExt } from '@/common/store/build_state'; 20 21 import './step_cluster'; 22 import { BuildPageStepClusterElement } from './step_cluster'; 23 24 function createStep(index: number, startTime: string, endTime: string) { 25 return new StepExt({ 26 step: { 27 name: 'step' + index, 28 status: BuildbucketStatus.Success, 29 startTime, 30 endTime, 31 }, 32 listNumber: index + 1 + '.', 33 selfName: 'step' + index, 34 depth: 0, 35 index, 36 }); 37 } 38 39 const step1 = createStep(0, '2022-01-01T00:00:00Z', '2022-01-01T00:02:00Z'); 40 const step2 = createStep(0, '2022-01-01T00:01:00Z', '2022-01-01T00:03:00Z'); 41 const step3 = createStep(0, '2022-01-01T00:02:00Z', '2022-01-01T00:04:00Z'); 42 43 describe('StepCluster', () => { 44 test('should calculate duration based on start & end time', async () => { 45 const ele = await fixture<BuildPageStepClusterElement>(html` 46 <milo-bp-step-cluster 47 .store=${Store.create()} 48 .steps=${[step1, step2, step3]} 49 ></milo-bp-step-cluster> 50 `); 51 52 // The duration should equals endTime - startTime. Not a sum of all 53 // durations. Because steps can run in parallel. 54 expect(ele.duration?.toMillis()).toStrictEqual(240000); 55 }); 56 });