Skip to content

Commit

Permalink
Unit Tests for new o11y rules page (#128576)
Browse files Browse the repository at this point in the history
* tests for rules page

* mock useKibana and useBreadcrubms

* mock useFetchRules

* rules page scenarios

* temp

* mock usePluginContext and useLoadRuleTypes

* fix typescript errors

* fix Jest did not exit one second after the test run has completed warning

* add more tests to the empty rules page scenario

* fix typescript error

* render documentation link

* empty RulesPage with show only capability

* rules page with items

* RulesPage with items and show only capability

* remove disabled items (I need to implement it later on)

* refactoring

* update documentation link

* add types to the ruleState

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
mgiota and kibanamachine authored Apr 20, 2022
1 parent 285e336 commit 9d6aa99
Show file tree
Hide file tree
Showing 6 changed files with 585 additions and 11 deletions.
11 changes: 2 additions & 9 deletions x-pack/plugins/observability/public/hooks/use_fetch_rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@

import { useEffect, useState, useCallback } from 'react';
import { isEmpty } from 'lodash';
import { loadRules, Rule } from '@kbn/triggers-actions-ui-plugin/public';
import { loadRules } from '@kbn/triggers-actions-ui-plugin/public';
import { RULES_LOAD_ERROR } from '../pages/rules/translations';
import { FetchRulesProps } from '../pages/rules/types';
import { FetchRulesProps, RuleState } from '../pages/rules/types';
import { OBSERVABILITY_RULE_TYPES } from '../pages/rules/config';
import { useKibana } from '../utils/kibana_react';

interface RuleState {
isLoading: boolean;
data: Rule[];
error: string | null;
totalItemCount: number;
}

export function useFetchRules({
searchText,
ruleLastResponseFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,26 @@ const embeddableStartMock = {
},
};

const triggersActionsUiStartMock = {
createStart() {
return {
getAddAlertFlyout: jest.fn(),
ruleTypeRegistry: {
has: jest.fn(),
register: jest.fn(),
get: jest.fn(),
list: jest.fn(),
},
};
},
};

export const observabilityPublicPluginsStartMock = {
createStart() {
return {
cases: casesUiStartMock.createStart(),
embeddable: embeddableStartMock.createStart(),
triggersActionsUi: null,
triggersActionsUi: triggersActionsUiStartMock.createStart(),
data: null,
lens: null,
discover: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function NoDataPrompt({
/>
</EuiButton>,
<EuiButtonEmpty color="primary">
<EuiLink href={documentationLink} target="_blank">
<EuiLink data-test-subj="documentationLink" href={documentationLink} target="_blank">
Documentation
</EuiLink>
</EuiButtonEmpty>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function NoPermissionPrompt() {
}}
>
<EuiEmptyPrompt
data-test-subj="noPermissionPrompt"
color="plain"
hasBorder={true}
iconType="securityApp"
Expand Down
Loading

0 comments on commit 9d6aa99

Please sign in to comment.