forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Reporting] Disable Delete button after click (elastic#173707)
## Summary This PR takes care of an issue in Stack Management Reporting where the Delete button must be disabled after click to avoid accidental double-clicking ### Release note Fixed a bug in Stack Management Reporting where the Delete button was not disabled after click. ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
121fb3a
commit 4f9dc10
Showing
4 changed files
with
106 additions
and
9 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
77 changes: 77 additions & 0 deletions
77
x-pack/plugins/reporting/public/management/components/report_delete_button.test.tsx
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,77 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import * as Rx from 'rxjs'; | ||
import { | ||
fireEvent, | ||
render, | ||
findByTestId as findItByTestId, | ||
findByText as findItByText, | ||
} from '@testing-library/react'; | ||
|
||
import { mockJobs } from '../../../common/test'; | ||
import type { Job } from '../../lib/job'; | ||
import { ReportDeleteButton } from './report_delete_button'; | ||
|
||
describe('ReportDeleteButton', () => { | ||
it('renders prompt modal for single selected report', async () => { | ||
const deletePerformed$ = new Rx.Subject<void>(); | ||
const performDelete = jest.fn().mockResolvedValue(Rx.firstValueFrom(deletePerformed$)); | ||
const jobs = [mockJobs[0].payload] as Job[]; | ||
|
||
const { findByTestId } = render( | ||
<ReportDeleteButton jobsToDelete={jobs} performDelete={performDelete} /> | ||
); | ||
const getDeleteReportButton = () => findByTestId('deleteReportButton'); | ||
|
||
expect(await getDeleteReportButton()).not.toBeDisabled(); | ||
fireEvent.click(await getDeleteReportButton()); | ||
expect(await getDeleteReportButton()).toBeDisabled(); | ||
|
||
const modalElem = await findByTestId('deleteReportConfirm'); | ||
expect( | ||
await findItByText(modalElem, 'Delete the "My Canvas Workpad" report?') | ||
).toBeInTheDocument(); | ||
const getConfirmButton = () => findItByTestId(modalElem, 'confirmModalConfirmButton'); | ||
|
||
expect(await getConfirmButton()).not.toBeDisabled(); | ||
fireEvent.click(await getConfirmButton()); | ||
expect(await getConfirmButton()).toBeDisabled(); | ||
|
||
deletePerformed$.next(); | ||
|
||
expect(await getConfirmButton()).not.toBeDisabled(); | ||
}); | ||
|
||
it('renders prompt modal for multiple selected reports', async () => { | ||
const deletePerformed$ = new Rx.Subject<void>(); | ||
const performDelete = jest.fn().mockResolvedValue(Rx.firstValueFrom(deletePerformed$)); | ||
const jobs = [mockJobs[0].payload, mockJobs[1].payload] as Job[]; | ||
|
||
const { findByTestId } = render( | ||
<ReportDeleteButton jobsToDelete={jobs} performDelete={performDelete} /> | ||
); | ||
const getDeleteReportButton = () => findByTestId('deleteReportButton'); | ||
|
||
expect(await getDeleteReportButton()).not.toBeDisabled(); | ||
fireEvent.click(await getDeleteReportButton()); | ||
expect(await getDeleteReportButton()).toBeDisabled(); | ||
|
||
const modalElem = await findByTestId('deleteReportConfirm'); | ||
expect(await findItByText(modalElem, 'Delete the 2 selected reports?')).toBeInTheDocument(); | ||
const getConfirmButton = () => findItByTestId(modalElem, 'confirmModalConfirmButton'); | ||
|
||
expect(await getConfirmButton()).not.toBeDisabled(); | ||
fireEvent.click(await getConfirmButton()); | ||
expect(await getConfirmButton()).toBeDisabled(); | ||
|
||
deletePerformed$.next(); | ||
|
||
expect(await getConfirmButton()).not.toBeDisabled(); | ||
}); | ||
}); |
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