Skip to content

Commit

Permalink
check if detector finished loading before checking if indices exist
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Galitzky <[email protected]>
  • Loading branch information
amitgalitz committed May 17, 2022
1 parent b25860d commit 92996ab
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 64 deletions.
6 changes: 2 additions & 4 deletions public/components/ContentPanel/ContentPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ContentPanel = (props: ContentPanelProps) => {
);
return (
<EuiPanel
style={{ padding: '20px'}}
style={{ padding: '20px' }}
className={props.contentPanelClassName}
>
<EuiFlexGroup
Expand Down Expand Up @@ -133,9 +133,7 @@ const ContentPanel = (props: ContentPanelProps) => {
margin="s"
className={props.horizontalRuleClassName}
/>
<div style={{ padding: '10px 0px' }}>
{props.children}
</div>
<div style={{ padding: '10px 0px' }}>{props.children}</div>
</div>
) : null}
</EuiPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('<ConfigureModel /> spec', () => {
test('validate all required fields', async () => {
const { getByText } = renderWithRouter();
fireEvent.click(getByText('Next'));
await waitFor(()=>{});
await waitFor(() => {});
getByText('You must enter a feature name');
getByText('You must select a field');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('<DefineDetector /> spec', () => {
});
const { getByText } = renderWithRouter();
fireEvent.click(getByText('Next'));
await waitFor(()=>{});
await waitFor(() => {});
getByText('Detector name cannot be empty');
getByText('Must specify an index');
getByText('Required');
Expand Down
7 changes: 5 additions & 2 deletions public/pages/DetectorDetail/containers/DetectorDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ export const DetectorDetail = (props: DetectorDetailProps) => {
core.notifications.toasts.addDanger('Error getting all indices');
});
};
getInitialIndices();
// only need to check if indices exist after detector finishes loading
if (!isLoadingDetector) {
getInitialIndices();
}
}, [detector]);

useEffect(() => {
Expand All @@ -188,7 +191,7 @@ export const DetectorDetail = (props: DetectorDetailProps) => {
// If the detector state was changed after opening the stop detector modal,
// re-check if any jobs are running, and close the modal if it's not needed anymore
useEffect(() => {
if (!isRTJobRunning && !isHistoricalJobRunning) {
if (!isRTJobRunning && !isHistoricalJobRunning && !isEmpty(detector)) {
hideStopDetectorModal();
}
}, [detector]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('<ListActions /> spec', () => {
expect(queryByText('Stop')).toBeNull();
expect(queryByText('Delete')).toBeNull();
fireEvent.click(getByTestId('listActionsButton'));
await waitFor(()=>{});
await waitFor(() => {});
expect(queryByText('Start')).toBeNull();
expect(queryByText('Stop')).toBeNull();
expect(queryByText('Delete')).toBeNull();
Expand All @@ -50,7 +50,7 @@ describe('<ListActions /> spec', () => {
expect(queryByText('Stop')).toBeNull();
expect(queryByText('Delete')).toBeNull();
fireEvent.click(getByTestId('listActionsButton'));
await waitFor(()=>{});
await waitFor(() => {});
expect(queryByText('Start real-time detectors')).not.toBeNull();
expect(queryByText('Stop real-time detectors')).not.toBeNull();
expect(queryByText('Delete detectors')).not.toBeNull();
Expand All @@ -60,7 +60,7 @@ describe('<ListActions /> spec', () => {
<ListActions {...defaultProps} isActionsDisabled={false} />
);
fireEvent.click(getByTestId('listActionsButton'));
await waitFor(()=>{});
await waitFor(() => {});
fireEvent.click(getByTestId('startDetectors'));
expect(defaultProps.onStartDetectors).toHaveBeenCalled();
});
Expand All @@ -69,7 +69,7 @@ describe('<ListActions /> spec', () => {
<ListActions {...defaultProps} isActionsDisabled={false} />
);
fireEvent.click(getByTestId('listActionsButton'));
await waitFor(()=>{});
await waitFor(() => {});
fireEvent.click(getByTestId('stopDetectors'));
expect(defaultProps.onStopDetectors).toHaveBeenCalled();
});
Expand All @@ -78,7 +78,7 @@ describe('<ListActions /> spec', () => {
<ListActions {...defaultProps} isActionsDisabled={false} />
);
fireEvent.click(getByTestId('listActionsButton'));
await waitFor(()=>{});
await waitFor(() => {});
fireEvent.click(getByTestId('deleteDetectors'));
expect(defaultProps.onDeleteDetectors).toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ describe('<ConfirmDeleteDetectorsModal /> spec', () => {
const { getByTestId, getByPlaceholderText } = render(
<ConfirmDeleteDetectorsModal {...defaultDeleteProps} />
);
await waitFor(()=>{});
await waitFor(() => {});
userEvent.type(getByPlaceholderText('delete'), 'foo');
await waitFor(()=>{});
await waitFor(() => {});
userEvent.click(getByTestId('confirmButton'));
await waitFor(()=>{});
await waitFor(() => {});
expect(defaultDeleteProps.onStopDetectors).not.toHaveBeenCalled();
expect(defaultDeleteProps.onDeleteDetectors).not.toHaveBeenCalled();
expect(defaultDeleteProps.onConfirm).not.toHaveBeenCalled();
Expand All @@ -87,11 +87,11 @@ describe('<ConfirmDeleteDetectorsModal /> spec', () => {
const { getByTestId, getByPlaceholderText } = render(
<ConfirmDeleteDetectorsModal {...defaultDeleteProps} />
);
await waitFor(()=>{});
await waitFor(() => {});
userEvent.type(getByPlaceholderText('delete'), 'delete');
await waitFor(()=>{});
await waitFor(() => {});
userEvent.click(getByTestId('confirmButton'));
await waitFor(()=>{});
await waitFor(() => {});
expect(defaultDeleteProps.onConfirm).toHaveBeenCalled();
}, 10000);
test('should not show callout if no detectors are running', async () => {
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('<ConfirmDeleteDetectorsModal /> spec', () => {
}
/>
);
await waitFor(()=>{});
await waitFor(() => {});
expect(
queryByText('Some of the selected detectors are currently running.')
).not.toBeNull();
Expand All @@ -135,9 +135,9 @@ describe('<ConfirmDeleteDetectorsModal /> spec', () => {
const { getByTestId } = render(
<ConfirmDeleteDetectorsModal {...defaultDeleteProps} />
);
await waitFor(()=>{});
await waitFor(() => {});
fireEvent.click(getByTestId('cancelButton'));
await waitFor(()=>{});
await waitFor(() => {});
expect(defaultDeleteProps.onHide).toHaveBeenCalled();
});
test('should call onStopDetectors when deleting running detectors', async () => {
Expand All @@ -156,14 +156,14 @@ describe('<ConfirmDeleteDetectorsModal /> spec', () => {
/>
);
// Try clicking before 'delete' has been typed
await waitFor(()=>{});
await waitFor(() => {});
userEvent.click(getByTestId('confirmButton'));
await waitFor(()=>{});
await waitFor(() => {});
expect(defaultDeleteProps.onStopDetectors).not.toHaveBeenCalled();
userEvent.type(getByPlaceholderText('delete'), 'delete');
await waitFor(()=>{});
await waitFor(() => {});
userEvent.click(getByTestId('confirmButton'));
await waitFor(()=>{});
await waitFor(() => {});
expect(defaultDeleteProps.onStopDetectors).toHaveBeenCalled();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('<ConfirmStartDetectorsModal /> spec', () => {
<ConfirmStartDetectorsModal {...defaultStartProps} />
);
fireEvent.click(getByTestId('confirmButton'));
await waitFor(()=>{});
await waitFor(() => {});
expect(defaultStartProps.onStartDetectors).toHaveBeenCalled();
expect(defaultStartProps.onConfirm).toHaveBeenCalled();
});
Expand All @@ -68,7 +68,7 @@ describe('<ConfirmStartDetectorsModal /> spec', () => {
<ConfirmStartDetectorsModal {...defaultStartProps} />
);
fireEvent.click(getByTestId('cancelButton'));
await waitFor(()=>{});
await waitFor(() => {});
expect(defaultStartProps.onHide).toHaveBeenCalled();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ describe('<ConfirmStopDetectorsModal /> spec', () => {
<ConfirmStopDetectorsModal {...defaultStopProps} />
);
fireEvent.click(getByTestId('confirmButton'));
await waitFor(()=>{});
await waitFor(() => {});
expect(defaultStopProps.onStopDetectors).toHaveBeenCalled();
});
test('should call onHide() when closing', async () => {
const { getByTestId } = render(
<ConfirmStopDetectorsModal {...defaultStopProps} />
);
fireEvent.click(getByTestId('cancelButton'));
await waitFor(()=>{});
await waitFor(() => {});
expect(defaultStopProps.onHide).toHaveBeenCalled();
});
});
Expand Down
Loading

0 comments on commit 92996ab

Please sign in to comment.