@allurereport/web-commons 3.0.0-beta.21 → 3.0.0-beta.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import { BarChartType, BarGroupMode, ChartMode, ChartType, } from "@allurereport/charts-api";
2
+ import { formatDuration } from "@allurereport/core-api";
2
3
  export const generateBarChartDurationsByLayer = (options, storeData) => {
3
4
  const testsDurationsByLayer = new Map();
4
5
  const { testResults } = storeData;
@@ -33,7 +34,7 @@ export const generateBarChartDurationsByLayer = (options, storeData) => {
33
34
  buckets.push({
34
35
  min: Math.min(...allDurations),
35
36
  max: Infinity,
36
- label: `${Math.round(Math.min(...allDurations))}+ms`,
37
+ label: `${formatDuration(Math.round(Math.min(...allDurations)))}+`,
37
38
  });
38
39
  }
39
40
  else {
@@ -44,7 +45,9 @@ export const generateBarChartDurationsByLayer = (options, storeData) => {
44
45
  const maxIndex = Math.floor(nextQuantile * (sortedDurations.length - 1));
45
46
  const bucketMin = sortedDurations[minIndex];
46
47
  const bucketMax = i === maxBuckets - 1 ? sortedDurations[sortedDurations.length - 1] : sortedDurations[maxIndex];
47
- const label = i === maxBuckets - 1 ? `${Math.round(bucketMin)}+ms` : `${Math.round(bucketMin)}-${Math.round(bucketMax)}ms`;
48
+ const label = i === maxBuckets - 1
49
+ ? `${formatDuration(Math.round(bucketMin))}+`
50
+ : `${formatDuration(Math.round(bucketMin))}-${formatDuration(Math.round(bucketMax))}`;
48
51
  buckets.push({
49
52
  min: bucketMin,
50
53
  max: bucketMax,
@@ -0,0 +1,2 @@
1
+ import type { AllureChartsStoreData, FunnelChartData, FunnelChartOptions } from "@allurereport/charts-api";
2
+ export declare const generateTestingPyramidChart: (chartOptions: FunnelChartOptions, storeData: AllureChartsStoreData) => FunnelChartData;
@@ -0,0 +1,53 @@
1
+ import { ChartType, FunnelChartType } from "@allurereport/charts-api";
2
+ const DEFAULT_LAYERS = ["unit", "integration", "e2e"];
3
+ const getPercentage = (value, total) => {
4
+ if (total === 0 || value === 0) {
5
+ return 0;
6
+ }
7
+ return Math.floor((value / total) * 10000) / 100;
8
+ };
9
+ export const generateTestingPyramidChart = (chartOptions, storeData) => {
10
+ const { layers = DEFAULT_LAYERS, title } = chartOptions;
11
+ const { testResults } = storeData;
12
+ const layersMap = new Map();
13
+ layers.forEach((layer) => {
14
+ layersMap.set(layer, layer);
15
+ layersMap.set(layer.toLocaleLowerCase(), layer);
16
+ });
17
+ const statsByLayers = new Map();
18
+ layers.forEach((layer) => {
19
+ statsByLayers.set(layer, {
20
+ passed: 0,
21
+ total: 0,
22
+ });
23
+ });
24
+ for (const testResult of testResults) {
25
+ const trLayer = testResult.labels.find((label) => label.name === "layer")?.value;
26
+ if (!trLayer) {
27
+ continue;
28
+ }
29
+ const layer = layersMap.get(trLayer.toLocaleLowerCase());
30
+ if (!layer) {
31
+ continue;
32
+ }
33
+ const data = statsByLayers.get(layer);
34
+ data.total++;
35
+ if (testResult.status === "passed") {
36
+ data.passed++;
37
+ }
38
+ }
39
+ return {
40
+ type: ChartType.Funnel,
41
+ dataType: FunnelChartType.TestingPyramid,
42
+ title,
43
+ data: layers.map((layer) => {
44
+ const data = statsByLayers.get(layer);
45
+ return {
46
+ layer,
47
+ testCount: data.total,
48
+ successRate: getPercentage(data.passed, data.total),
49
+ percentage: getPercentage(data.total, testResults.length),
50
+ };
51
+ }),
52
+ };
53
+ };
@@ -0,0 +1,2 @@
1
+ import type { AllureChartsStoreData, FunnelChartData, FunnelChartOptions } from "@allurereport/charts-api";
2
+ export declare const generateFunnelChart: (chartOption: FunnelChartOptions, storeData: AllureChartsStoreData) => FunnelChartData;
@@ -0,0 +1,9 @@
1
+ import { FunnelChartType } from "@allurereport/charts-api";
2
+ import { generateTestingPyramidChart } from "./generateTestingPyramidChart.js";
3
+ export const generateFunnelChart = (chartOption, storeData) => {
4
+ const { dataType } = chartOption;
5
+ switch (dataType) {
6
+ case FunnelChartType.TestingPyramid:
7
+ return generateTestingPyramidChart(chartOption, storeData);
8
+ }
9
+ };
@@ -2,6 +2,7 @@ import { ChartType, } from "@allurereport/charts-api";
2
2
  import { DEFAULT_ENVIRONMENT } from "@allurereport/core-api";
3
3
  import { generateBarChart } from "./bar.js";
4
4
  import { generateComingSoonChart } from "./comingSoon.js";
5
+ import { generateFunnelChart } from "./funnel/index.js";
5
6
  import { generateHeatMapChart } from "./heatMap.js";
6
7
  import { generateTrendChart } from "./line.js";
7
8
  import { generatePieChart } from "./pie.js";
@@ -36,6 +37,9 @@ const generateChartData = async (props) => {
36
37
  case ChartType.HeatMap:
37
38
  result[chartId] = generateHeatMapChart(chartOption, storeData);
38
39
  break;
40
+ case ChartType.Funnel:
41
+ result[chartId] = generateFunnelChart(chartOption, storeData);
42
+ break;
39
43
  default:
40
44
  result[chartId] = generateComingSoonChart(chartOption);
41
45
  break;
@@ -1,4 +1,4 @@
1
- import type { BarChartType, BarGroup, BarGroupMode, BaseTrendSliceMetadata, ChartDataType, ChartId, ChartMode, ChartType, HeatMapSerie, PieSlice, TreeMapChartType, TreeMapNode, TrendPointId, TrendSlice, TrendSliceId } from "@allurereport/charts-api";
1
+ import type { BarChartType, BarGroup, BarGroupMode, BaseTrendSliceMetadata, ChartDataType, ChartId, ChartMode, ChartType, FunnelChartType, HeatMapSerie, PieSlice, TreeMapChartType, TreeMapNode, TrendPointId, TrendSlice, TrendSliceId } from "@allurereport/charts-api";
2
2
  export type TreeMapTooltipAccessor = <T>(node: T) => string[];
3
3
  export interface Point {
4
4
  x: Date | string | number;
@@ -94,8 +94,21 @@ export interface UITreeMapChartData extends ResponseTreeMapChartData {
94
94
  export interface UIHeatMapChartData extends ResponseHeatMapChartData {
95
95
  colors: (value: number, domain?: number[]) => string;
96
96
  }
97
- export type ChartData<SeriesType extends string = string, Metadata extends BaseTrendSliceMetadata = BaseTrendSliceMetadata> = ResponseTrendChartData<SeriesType, Metadata> | ResponsePieChartData | ResponseBarChartData | ResponseComingSoonChartData | ResponseTreeMapChartData | ResponseHeatMapChartData;
98
- export type UIChartData<Metadata extends BaseTrendSliceMetadata = BaseTrendSliceMetadata> = UITrendChartData<Metadata> | UIPieChartData | UIBarChartData | UIComingSoonChartData | UITreeMapChartData | UIHeatMapChartData;
97
+ export interface UITestingPyramidChartData extends ResponseTestingPyramidChartData {
98
+ }
99
+ export interface ResponseTestingPyramidChartData {
100
+ type: ChartType.Funnel;
101
+ dataType: FunnelChartType;
102
+ title?: string;
103
+ data: {
104
+ layer: string;
105
+ testCount: number;
106
+ successRate: number;
107
+ percentage: number;
108
+ }[];
109
+ }
110
+ export type ChartData<SeriesType extends string = string, Metadata extends BaseTrendSliceMetadata = BaseTrendSliceMetadata> = ResponseTrendChartData<SeriesType, Metadata> | ResponsePieChartData | ResponseBarChartData | ResponseComingSoonChartData | ResponseTreeMapChartData | ResponseHeatMapChartData | ResponseTestingPyramidChartData;
111
+ export type UIChartData<Metadata extends BaseTrendSliceMetadata = BaseTrendSliceMetadata> = UITrendChartData<Metadata> | UIPieChartData | UIBarChartData | UIComingSoonChartData | UITreeMapChartData | UIHeatMapChartData | UITestingPyramidChartData;
99
112
  export type ChartsData<SeriesType extends string = string, Metadata extends BaseTrendSliceMetadata = BaseTrendSliceMetadata> = Record<ChartId, ChartData<SeriesType, Metadata>>;
100
113
  export type ChartsDataWithEnvs<SeriesType extends string = string, Metadata extends BaseTrendSliceMetadata = BaseTrendSliceMetadata> = {
101
114
  general: Record<ChartId, ChartData<SeriesType, Metadata>>;
@@ -1,6 +1,6 @@
1
1
  import type { ChartId } from "@allurereport/charts-api";
2
2
  import type { SeverityLevel, TestStatus } from "@allurereport/core-api";
3
- import type { ChartsData, ChartsDataWithEnvs, ResponseBarChartData, ResponseHeatMapChartData, ResponseTreeMapChartData, ResponseTrendChartData, TreeMapTooltipAccessor, UIBarChartData, UIChartData, UIChartsDataWithEnvs, UIHeatMapChartData, UITreeMapChartData, UITrendChartData } from "./types.js";
3
+ import type { ChartsData, ChartsDataWithEnvs, ResponseBarChartData, ResponseHeatMapChartData, ResponseTestingPyramidChartData, ResponseTreeMapChartData, ResponseTrendChartData, TreeMapTooltipAccessor, UIBarChartData, UIChartData, UIChartsDataWithEnvs, UIHeatMapChartData, UITestingPyramidChartData, UITreeMapChartData, UITrendChartData } from "./types.js";
4
4
  export declare const createTrendChartDataGeneric: <T extends TestStatus | SeverityLevel>(getChart: () => ResponseTrendChartData | undefined, getGroups: () => readonly T[], getColor: (group: T) => string) => UITrendChartData | undefined;
5
5
  export declare const createBarChartDataGeneric: <T extends string>(getChart: () => ResponseBarChartData | undefined, getColors: () => Record<T, string>) => UIBarChartData | undefined;
6
6
  export declare const createTreeMapChartDataGeneric: (getChart: () => ResponseTreeMapChartData | undefined, colors: (value: number, domain?: number[]) => string, formatLegend?: (value: number) => string, legendDomain?: number[], tooltipRows?: TreeMapTooltipAccessor) => UITreeMapChartData | undefined;
@@ -19,6 +19,7 @@ export declare const createProblemsDistributionHeatMapChartData: (chartId: Chart
19
19
  export declare const createaTrendChartData: (chartId: string, chartData: ResponseTrendChartData, res: ChartsData) => UITrendChartData | undefined;
20
20
  export declare const createBarChartData: (chartId: string, chartData: ResponseBarChartData, res: ChartsData) => UIBarChartData | undefined;
21
21
  export declare const createTreeMapChartData: (chartId: ChartId, chartData: ResponseTreeMapChartData, res: ChartsData) => UITreeMapChartData | undefined;
22
+ export declare const createFunnelChartData: (chartId: string, chartData: ResponseTestingPyramidChartData) => UITestingPyramidChartData | undefined;
22
23
  export declare const createHeatMapChartData: (chartId: ChartId, res: ChartsData) => UIHeatMapChartData | undefined;
23
24
  export declare const createCharts: (res: ChartsData) => Record<ChartId, UIChartData>;
24
25
  export declare const createChartsWithEnvs: (res: ChartsDataWithEnvs) => UIChartsDataWithEnvs;
@@ -1,4 +1,4 @@
1
- import { BarChartType, ChartDataType, ChartType, TreeMapChartType } from "@allurereport/charts-api";
1
+ import { BarChartType, ChartDataType, ChartType, FunnelChartType, TreeMapChartType } from "@allurereport/charts-api";
2
2
  import { severityLevels, statusesList } from "@allurereport/core-api";
3
3
  import { interpolateRgb } from "d3-interpolate";
4
4
  import { scaleLinear } from "d3-scale";
@@ -187,6 +187,12 @@ export const createTreeMapChartData = (chartId, chartData, res) => {
187
187
  return createCoverageDiffTreeMapChartData(chartId, res);
188
188
  }
189
189
  };
190
+ export const createFunnelChartData = (chartId, chartData) => {
191
+ switch (chartData.dataType) {
192
+ case FunnelChartType.TestingPyramid:
193
+ return chartData;
194
+ }
195
+ };
190
196
  export const createHeatMapChartData = (chartId, res) => {
191
197
  return createProblemsDistributionHeatMapChartData(chartId, res);
192
198
  };
@@ -216,8 +222,14 @@ export const createCharts = (res) => {
216
222
  acc[chartId] = chartData;
217
223
  }
218
224
  }
225
+ else if (chart.type === ChartType.Funnel) {
226
+ const chartData = createFunnelChartData(chartId, chart);
227
+ if (chartData) {
228
+ acc[chartId] = chartData;
229
+ }
230
+ }
219
231
  else if ([ChartType.Pie, ChartType.ComingSoon].includes(chart.type)) {
220
- acc[chartId] = chart;
232
+ return acc;
221
233
  }
222
234
  return acc;
223
235
  }, {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allurereport/web-commons",
3
- "version": "3.0.0-beta.21",
3
+ "version": "3.0.0-beta.22",
4
4
  "description": "Collection of utilities used across the web Allure reports",
5
5
  "keywords": [
6
6
  "allure",
@@ -23,9 +23,9 @@
23
23
  "clean": "rimraf ./dist"
24
24
  },
25
25
  "dependencies": {
26
- "@allurereport/charts-api": "3.0.0-beta.21",
27
- "@allurereport/core-api": "3.0.0-beta.21",
28
- "@allurereport/plugin-api": "3.0.0-beta.21",
26
+ "@allurereport/charts-api": "3.0.0-beta.22",
27
+ "@allurereport/core-api": "3.0.0-beta.22",
28
+ "@allurereport/plugin-api": "3.0.0-beta.22",
29
29
  "ansi-to-html": "^0.7.2",
30
30
  "d3-interpolate": "^3.0.1",
31
31
  "d3-scale": "^4.0.2",