Skip to content

Commit

Permalink
add last api key test
Browse files Browse the repository at this point in the history
  • Loading branch information
guskovaue committed Mar 12, 2023
1 parent 6b90daf commit ce08972
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
ruleType,
} from './test_helpers';
import { IToasts } from '@kbn/core/public';
import { act, render, screen, waitForElementToBeRemoved, fireEvent } from '@testing-library/react';
import { render, screen, waitForElementToBeRemoved, fireEvent } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { __IntlProvider as IntlProvider } from '@kbn/i18n-react';

Expand Down Expand Up @@ -156,131 +156,6 @@ describe('Rules list Bulk Edit', () => {
queryClient.clear();
});

// FLAKY: https://github.com/elastic/kibana/issues/152268
// FLAKY: https://github.com/elastic/kibana/issues/152267
describe.skip('bulk actions', () => {
beforeEach(async () => {
renderWithProviders(<RulesList />);
await waitForElementToBeRemoved(() => screen.queryByTestId('centerJustifiedSpinner'));

fireEvent.click(screen.getByTestId('checkboxSelectRow-1'));
fireEvent.click(screen.getByTestId('selectAllRulesButton'));
fireEvent.click(screen.getByTestId('checkboxSelectRow-2'));
fireEvent.click(screen.getByTestId('showBulkActionButton'));
});

it('can bulk add snooze schedule', async () => {
fireEvent.click(screen.getByTestId('bulkSnoozeSchedule'));
expect(screen.queryByTestId('ruleSnoozeScheduler')).toBeInTheDocument();
await act(async () => {
fireEvent.click(screen.getByTestId('scheduler-saveSchedule'));
});

const filter = bulkSnoozeRules.mock.calls[0][0].filter;

expect(filter.function).toEqual('and');
expect(filter.arguments[0].function).toEqual('or');
expect(filter.arguments[1].function).toEqual('not');
expect(filter.arguments[1].arguments[0].arguments[0].value).toEqual('alert.id');
expect(filter.arguments[1].arguments[0].arguments[1].value).toEqual('alert:2');

expect(bulkSnoozeRules).toHaveBeenCalledWith(
expect.objectContaining({
ids: [],
})
);
});

it('can bulk remove snooze schedule', async () => {
fireEvent.click(screen.getByTestId('bulkRemoveSnoozeSchedule'));
expect(screen.queryByTestId('bulkRemoveScheduleConfirmationModal')).toBeInTheDocument();
await act(async () => {
fireEvent.click(screen.getByTestId('confirmModalConfirmButton'));
});

const filter = bulkUnsnoozeRules.mock.calls[0][0].filter;

expect(filter.function).toEqual('and');
expect(filter.arguments[0].function).toEqual('or');
expect(filter.arguments[1].function).toEqual('not');
expect(filter.arguments[1].arguments[0].arguments[0].value).toEqual('alert.id');
expect(filter.arguments[1].arguments[0].arguments[1].value).toEqual('alert:2');

expect(bulkUnsnoozeRules).toHaveBeenCalledWith(
expect.objectContaining({
ids: [],
scheduleIds: [],
})
);
});

it('can bulk snooze', async () => {
fireEvent.click(screen.getByTestId('bulkSnooze'));
expect(screen.queryByTestId('snoozePanel')).toBeInTheDocument();
await act(async () => {
fireEvent.click(screen.getByTestId('linkSnooze1h'));
});

const filter = bulkSnoozeRules.mock.calls[0][0].filter;

expect(filter.function).toEqual('and');
expect(filter.arguments[0].function).toEqual('or');
expect(filter.arguments[1].function).toEqual('not');
expect(filter.arguments[1].arguments[0].arguments[0].value).toEqual('alert.id');
expect(filter.arguments[1].arguments[0].arguments[1].value).toEqual('alert:2');

expect(bulkSnoozeRules).toHaveBeenCalledWith(
expect.objectContaining({
ids: [],
})
);
});

it('can bulk unsnooze', async () => {
fireEvent.click(screen.getByTestId('bulkUnsnooze'));
expect(screen.queryByTestId('bulkUnsnoozeConfirmationModal')).toBeInTheDocument();
await act(async () => {
fireEvent.click(screen.getByTestId('confirmModalConfirmButton'));
});

const filter = bulkUnsnoozeRules.mock.calls[0][0].filter;

expect(filter.function).toEqual('and');
expect(filter.arguments[0].function).toEqual('or');
expect(filter.arguments[1].function).toEqual('not');
expect(filter.arguments[1].arguments[0].arguments[0].value).toEqual('alert.id');
expect(filter.arguments[1].arguments[0].arguments[1].value).toEqual('alert:2');

expect(bulkUnsnoozeRules).toHaveBeenCalledWith(
expect.objectContaining({
ids: [],
})
);
});

it('can bulk update API key', async () => {
fireEvent.click(screen.getByTestId('updateAPIKeys'));
expect(screen.queryByTestId('updateApiKeyIdsConfirmation')).toBeInTheDocument();
await act(async () => {
fireEvent.click(screen.getByTestId('confirmModalConfirmButton'));
});

const filter = bulkUpdateAPIKey.mock.calls[0][0].filter;

expect(filter.function).toEqual('and');
expect(filter.arguments[0].function).toEqual('or');
expect(filter.arguments[1].function).toEqual('not');
expect(filter.arguments[1].arguments[0].arguments[0].value).toEqual('alert.id');
expect(filter.arguments[1].arguments[0].arguments[1].value).toEqual('alert:2');

expect(bulkUpdateAPIKey).toHaveBeenCalledWith(
expect.objectContaining({
ids: [],
})
);
});
});

it('renders select all button for bulk editing', async () => {
renderWithProviders(<RulesList />);
await waitForElementToBeRemoved(() => screen.queryByTestId('centerJustifiedSpinner'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await testSubjects.click('rulesTab');
}

describe('rules list', function () {
describe('rules list', () => {
before(async () => {
await pageObjects.common.navigateToApp('triggersActions');
await testSubjects.click('rulesTab');
Expand Down Expand Up @@ -143,7 +143,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await testSubjects.missingOrFail('rulesListNotifyBadge-scheduled');
});

it.only('should allow rules to be unscheduled', async () => {
it('should allow rules to be unscheduled', async () => {
const rule1 = await createAlert({
supertest,
objectRemover,
Expand Down Expand Up @@ -182,5 +182,32 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await pageObjects.triggersActionsUI.searchAlerts(rule2.name);
await testSubjects.existOrFail('rulesListNotifyBadge-scheduled');
});

it('can bulk update API key', async () => {
const rule1 = await createAlert({
supertest,
objectRemover,
overwrites: { name: 'a' },
});
const rule2 = await createAlert({
supertest,
objectRemover,
overwrites: { name: 'b' },
});

await refreshAlertsList();
await testSubjects.click(`checkboxSelectRow-${rule1.id}`);
await testSubjects.click('selectAllRulesButton');
await testSubjects.click(`checkboxSelectRow-${rule2.id}`);
await testSubjects.click('showBulkActionButton');
await testSubjects.click('updateAPIKeys');
await testSubjects.existOrFail('updateApiKeyIdsConfirmation');
await testSubjects.click('confirmModalConfirmButton');

await retry.try(async () => {
const toastTitle = await pageObjects.common.closeToast();
expect(toastTitle).to.eql('Updated API key for 1 rule.');
});
});
});
};

0 comments on commit ce08972

Please sign in to comment.