-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Actionable Observability] Add functional tests for the Rule Details …
…page (#133271) * Init * Update test name * Add rule title check * Add permissions and components tests * Uncomment other tests * Fix failing tests * Code review change tests folder structure * Fix imports
- Loading branch information
Showing
15 changed files
with
225 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
x-pack/test/observability_functional/apps/observability/pages/rule_details_page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
export default ({ getService }: FtrProviderContext) => { | ||
const testSubjects = getService('testSubjects'); | ||
const observability = getService('observability'); | ||
const supertest = getService('supertest'); | ||
const find = getService('find'); | ||
const retry = getService('retry'); | ||
const RULE_ENDPOINT = '/api/alerting/rule'; | ||
|
||
async function createRule(rule: any): Promise<string> { | ||
const ruleResponse = await supertest.post(RULE_ENDPOINT).set('kbn-xsrf', 'foo').send(rule); | ||
expect(ruleResponse.status).to.eql(200); | ||
return ruleResponse.body.id; | ||
} | ||
async function deleteRuleById(ruleId: string) { | ||
const ruleResponse = await supertest | ||
.delete(`${RULE_ENDPOINT}/${ruleId}`) | ||
.set('kbn-xsrf', 'foo'); | ||
expect(ruleResponse.status).to.eql(204); | ||
return true; | ||
} | ||
|
||
describe('Observability Rule Details page', function () { | ||
this.tags('includeFirefox'); | ||
|
||
let uptimeRuleId: string; | ||
const uptimeRuleName = 'uptime'; | ||
|
||
let logThresholdRuleId: string; | ||
const logThresholdRuleName = 'error-log'; | ||
|
||
before(async () => { | ||
await observability.users.restoreDefaultTestUserRole(); | ||
const uptimeRule = { | ||
params: { | ||
search: '', | ||
numTimes: 5, | ||
timerangeUnit: 'm', | ||
timerangeCount: 15, | ||
shouldCheckStatus: true, | ||
shouldCheckAvailability: true, | ||
availability: { range: 30, rangeUnit: 'd', threshold: '99' }, | ||
}, | ||
consumer: 'alerts', | ||
schedule: { interval: '1m' }, | ||
tags: [], | ||
name: uptimeRuleName, | ||
rule_type_id: 'xpack.uptime.alerts.monitorStatus', | ||
notify_when: 'onActionGroupChange', | ||
actions: [], | ||
}; | ||
const logThresholdRule = { | ||
params: { | ||
timeSize: 5, | ||
timeUnit: 'm', | ||
count: { value: 75, comparator: 'more than' }, | ||
criteria: [{ field: 'log.level', comparator: 'equals', value: 'error' }], | ||
}, | ||
consumer: 'alerts', | ||
schedule: { interval: '1m' }, | ||
tags: [], | ||
name: logThresholdRuleName, | ||
rule_type_id: 'logs.alert.document.count', | ||
notify_when: 'onActionGroupChange', | ||
actions: [], | ||
}; | ||
uptimeRuleId = await createRule(uptimeRule); | ||
logThresholdRuleId = await createRule(logThresholdRule); | ||
}); | ||
after(async () => { | ||
await deleteRuleById(uptimeRuleId); | ||
await deleteRuleById(logThresholdRuleId); | ||
}); | ||
|
||
describe('Navigate to the new Rule Details page', () => { | ||
it('should navigate to the new rule details page by clicking on the rule from the rules table', async () => { | ||
await observability.alerts.common.navigateToRulesPage(); | ||
await retry.waitFor( | ||
'Rules table to be visible', | ||
async () => await testSubjects.exists('rulesList') | ||
); | ||
await find.clickByLinkText(logThresholdRuleName); | ||
await retry.waitFor( | ||
'Rule details to be visible', | ||
async () => await testSubjects.exists('ruleDetails') | ||
); | ||
}); | ||
|
||
it('should navigate to the new rule details page by URL', async () => { | ||
await observability.alerts.common.navigateToRuleDetailsByRuleId(uptimeRuleId); | ||
await retry.waitFor( | ||
'Rule details to be visible', | ||
async () => await testSubjects.exists('ruleDetails') | ||
); | ||
}); | ||
}); | ||
|
||
describe('Page components', () => { | ||
before(async () => { | ||
await observability.alerts.common.navigateToRuleDetailsByRuleId(logThresholdRuleId); | ||
}); | ||
it('show the rule name as the page title', async () => { | ||
await retry.waitFor( | ||
'Rule name to be visible', | ||
async () => await testSubjects.exists('ruleName') | ||
); | ||
const ruleName = await testSubjects.getVisibleText('ruleName'); | ||
expect(ruleName).to.be(logThresholdRuleName); | ||
}); | ||
|
||
it('shows the rule status section in the rule summary', async () => { | ||
await testSubjects.existOrFail('ruleSummaryRuleStatus'); | ||
}); | ||
|
||
it('shows the rule definition section in the rule summary', async () => { | ||
await testSubjects.existOrFail('ruleSummaryRuleDefinition'); | ||
}); | ||
|
||
it('maps correctly the rule type with the human readable rule type', async () => { | ||
const ruleType = await testSubjects.getVisibleText('ruleSummaryRuleType'); | ||
expect(ruleType).to.be('Log threshold'); | ||
}); | ||
}); | ||
|
||
describe('User permissions', () => { | ||
before(async () => { | ||
await observability.alerts.common.navigateToRuleDetailsByRuleId(logThresholdRuleId); | ||
}); | ||
it('should show the more (...) button if user has permissions', async () => { | ||
await retry.waitFor( | ||
'More button to be visible', | ||
async () => await testSubjects.exists('moreButton') | ||
); | ||
}); | ||
|
||
it('should shows the rule edit and delete button if user has permissions', async () => { | ||
await testSubjects.click('moreButton'); | ||
await testSubjects.existOrFail('editRuleButton'); | ||
await testSubjects.existOrFail('deleteRuleButton'); | ||
}); | ||
|
||
it('should not let user edit/delete the rule if he has no permissions', async () => { | ||
await observability.users.setTestUserRole( | ||
observability.users.defineBasicObservabilityRole({ | ||
logs: ['read'], | ||
}) | ||
); | ||
await observability.alerts.common.navigateToRuleDetailsByRuleId(logThresholdRuleId); | ||
await testSubjects.missingOrFail('moreButton'); | ||
}); | ||
}); | ||
}); | ||
}; |
File renamed without changes.