Welcome to mirror list, hosted at ThFree Co, Russian Federation.

utils.js « test_reports « stores « pipeline_details « ci « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 87081e61e4825aaee60ecd8f31b44f1fd418e832 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { __, sprintf } from '~/locale';
import { parseSeconds, stringifyTime } from '~/lib/utils/datetime_utility';
import { testStatus } from '../../constants';

/**
 * Removes `./` from the beginning of a file path so it can be appended onto a blob path
 * @param {String} file
 * @returns {String}  - formatted value
 */
export function formatFilePath(file) {
  return file.replace(/^\.?\/*/, '');
}

export function iconForTestStatus(status) {
  switch (status) {
    case testStatus.SUCCESS:
      return 'status_success';
    case testStatus.FAILED:
      return 'status_failed';
    case testStatus.ERROR:
      return 'status_warning';
    case testStatus.SKIPPED:
      return 'status_skipped';
    case testStatus.UNKNOWN:
    default:
      return 'status_notfound';
  }
}
export const formattedTime = (seconds = 0) => {
  if (seconds < 1) {
    return sprintf(__('%{milliseconds}ms'), {
      milliseconds: (seconds * 1000).toFixed(2),
    });
  }
  if (seconds < 60) {
    return sprintf(__('%{seconds}s'), {
      seconds: (seconds % 60).toFixed(2),
    });
  }

  const hoursAndMinutes = stringifyTime(parseSeconds(seconds));
  const remainingSeconds =
    seconds % 60 >= 1
      ? sprintf(__('%{seconds}s'), {
          seconds: Math.floor(seconds % 60),
        })
      : '';
  return `${hoursAndMinutes} ${remainingSeconds}`.trim();
};
export const addIconStatus = (testCase) => ({
  ...testCase,
  icon: iconForTestStatus(testCase.status),
  formattedTime: formattedTime(testCase.execution_time),
});