Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benakansara committed Jan 30, 2024
1 parent 219b02e commit a980af8
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('AlertDetailsAppSection', () => {
it('should render rule and alert data', async () => {
const result = renderComponent();

expect((await result.findByTestId('thresholdAlertOverviewSection')).children.length).toBe(3);
expect((await result.findByTestId('thresholdAlertOverviewSection')).children.length).toBe(6);
expect(result.getByTestId('thresholdRule-2000-2500')).toBeTruthy();
});

Expand Down Expand Up @@ -145,7 +145,30 @@ describe('AlertDetailsAppSection', () => {
(ExpressionChart as jest.Mock).mockImplementation(mockedExpressionChart);
const alertDetailsAppSectionComponent = renderComponent();

expect(alertDetailsAppSectionComponent.getAllByTestId('ExpressionChart').length).toBe(3);
expect(alertDetailsAppSectionComponent.getAllByTestId('ExpressionChart').length).toBe(6);
expect(mockedExpressionChart.mock.calls[0]).toMatchSnapshot();
});

it('should render title on condition charts', async () => {
const result = renderComponent();

expect(result.getByTestId('chartTitle-0').textContent).toBe(
'Equation result for count (all documents)'
);
expect(result.getByTestId('chartTitle-1').textContent).toBe(
'Equation result for max (system.cpu.user.pct)'
);
expect(result.getByTestId('chartTitle-2').textContent).toBe(
'Equation result for min (system.memory.used.pct)'
);
expect(result.getByTestId('chartTitle-3').textContent).toBe(
'Equation result for min (system.memory.used.pct) + min (system.memory.used.pct) + min (system.memory.used.pct) + min (system.memory.used.pct...'
);
expect(result.getByTestId('chartTitle-4').textContent).toBe(
'Equation result for min (system.memory.used.pct) + min (system.memory.used.pct)'
);
expect(result.getByTestId('chartTitle-5').textContent).toBe(
'Equation result for min (system.memory.used.pct) + min (system.memory.used.pct) + min (system.memory.used.pct)'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export default function AlertDetailsAppSection({

const generateChartTitle = (criterion: MetricExpression) => {
let equationTitle = '';
const equation = criterion.equation ?? (criterion.metrics.length === 2 ? 'A + B' : 'A');
const symbolResolver: Record<string, string> = {};
const equation = criterion.equation ?? criterion.metrics.map((m) => m.name).join(' + ');

criterion.metrics.forEach(
(metric) =>
Expand Down Expand Up @@ -204,7 +204,9 @@ export default function AlertDetailsAppSection({
<EuiPanel hasBorder hasShadow={false}>
<EuiToolTip content={generateChartTitle(criterion).tooltip}>
<EuiTitle size="xs">
<h4>{generateChartTitle(criterion).title}</h4>
<h4 data-test-subj={`chartTitle-${index}`}>
{generateChartTitle(criterion).title}
</h4>
</EuiTitle>
</EuiToolTip>
<EuiText size="s" color="subdued">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,62 @@ export const buildCustomThresholdRule = (
timeSize: 15,
timeUnit: 'm',
},
{
comparator: Comparator.GT,
metrics: [
{
name: 'A',
aggType: Aggregators.MIN,
field: 'system.memory.used.pct',
},
],
threshold: [0.8],
timeSize: 15,
timeUnit: 'm',
equation:
'A + A + A + A + A + A + A + A + A + A + A + A + A + A + A + A + A + A + A + A + A',
},
{
comparator: Comparator.GT,
metrics: [
{
name: 'C',
aggType: Aggregators.MIN,
field: 'system.memory.used.pct',
},
{
name: 'D',
aggType: Aggregators.MIN,
field: 'system.memory.used.pct',
},
],
threshold: [0.8],
timeSize: 15,
timeUnit: 'm',
},
{
comparator: Comparator.GT,
metrics: [
{
name: 'C',
aggType: Aggregators.MIN,
field: 'system.memory.used.pct',
},
{
name: 'D',
aggType: Aggregators.MIN,
field: 'system.memory.used.pct',
},
{
name: 'E',
aggType: Aggregators.MIN,
field: 'system.memory.used.pct',
},
],
threshold: [0.8],
timeSize: 15,
timeUnit: 'm',
},
],
searchConfiguration: {
query: {
Expand Down

0 comments on commit a980af8

Please sign in to comment.