diff --git a/graylog2-web-interface/src/components/inputs/InputStateControl.test.tsx b/graylog2-web-interface/src/components/inputs/InputStateControl.test.tsx index 567985dad9..1e9c107a0e 100644 --- a/graylog2-web-interface/src/components/inputs/InputStateControl.test.tsx +++ b/graylog2-web-interface/src/components/inputs/InputStateControl.test.tsx @@ -64,9 +64,34 @@ const renderSUT = (inputStates: InputStates, featureEnabled = true) => { return render(); }; +const messageInput = { + title: baseInput.title, + global: baseInput.global, + name: baseInput.name, + content_pack: '', + id: baseInput.id, + created_at: baseInput.created_at, + type: baseInput.type, + creator_user_id: baseInput.creator_user_id, + attributes: baseInput.attributes, + static_fields: baseInput.static_fields, + node: baseInput.node, +}; + describe('InputStateControl', () => { - it('shows setup state when feature is enabled and input state is not loaded yet', async () => { - renderSUT({}); + it('shows setup when feature is enabled and input is in setup mode', async () => { + const setupStates: InputStates = { + [baseInput.id]: { + node1: { + id: baseInput.id, + state: 'SETUP', + detailed_message: null, + message_input: messageInput, + }, + }, + }; + + renderSUT(setupStates); expect(await screen.findByRole('button', { name: /set-up input/i })).toBeInTheDocument(); }); @@ -84,19 +109,7 @@ describe('InputStateControl', () => { id: baseInput.id, state: 'RUNNING', detailed_message: null, - message_input: { - title: baseInput.title, - global: baseInput.global, - name: baseInput.name, - content_pack: '', - id: baseInput.id, - created_at: baseInput.created_at, - type: baseInput.type, - creator_user_id: baseInput.creator_user_id, - attributes: baseInput.attributes, - static_fields: baseInput.static_fields, - node: baseInput.node, - }, + message_input: messageInput, }, }, }; @@ -106,35 +119,8 @@ describe('InputStateControl', () => { expect(await screen.findByRole('button', { name: /stop input/i })).toBeInTheDocument(); }); - it('shows start after stopping an input instead of setup', async () => { - const runningStates: InputStates = { - [baseInput.id]: { - node1: { - id: baseInput.id, - state: 'RUNNING', - detailed_message: null, - message_input: { - title: baseInput.title, - global: baseInput.global, - name: baseInput.name, - content_pack: '', - id: baseInput.id, - created_at: baseInput.created_at, - type: baseInput.type, - creator_user_id: baseInput.creator_user_id, - attributes: baseInput.attributes, - static_fields: baseInput.static_fields, - node: baseInput.node, - }, - }, - }, - }; - - const { rerender } = renderSUT(runningStates); - - expect(await screen.findByRole('button', { name: /stop input/i })).toBeInTheDocument(); - - rerender(); + it('shows start instead of setup when input has no state after page reload', async () => { + renderSUT({}); expect(await screen.findByRole('button', { name: /start input/i })).toBeInTheDocument(); }); diff --git a/graylog2-web-interface/src/components/inputs/InputStateControl.tsx b/graylog2-web-interface/src/components/inputs/InputStateControl.tsx index 13e0ceb934..3ce44ed328 100644 --- a/graylog2-web-interface/src/components/inputs/InputStateControl.tsx +++ b/graylog2-web-interface/src/components/inputs/InputStateControl.tsx @@ -28,7 +28,6 @@ import { TELEMETRY_EVENT_TYPE } from 'logic/telemetry/Constants'; import { Button } from 'components/bootstrap'; import { INPUT_SETUP_MODE_FEATURE_FLAG } from 'components/inputs/InputSetupWizard'; import type { InputStates } from 'hooks/useInputsStates'; -import useIsInitialUnknownInputState from 'components/inputs/hooks/useIsInitialUnknownInputState'; type Props = { input: Input; @@ -41,7 +40,7 @@ const InputStateControl = ({ input, openWizard, inputStates }: Props) => { const { pathname } = useLocation(); const [isLoading, setIsLoading] = useState(false); const inputSetupFeatureFlagIsEnabled = useFeature(INPUT_SETUP_MODE_FEATURE_FLAG); - const isInitialUnknownState = useIsInitialUnknownInputState(inputStates, input.id); + const startInput = () => { setIsLoading(true); @@ -77,7 +76,7 @@ const InputStateControl = ({ input, openWizard, inputStates }: Props) => { openWizard(); }; - if (inputSetupFeatureFlagIsEnabled && (isInputInSetupMode(inputStates, input.id) || isInitialUnknownState)) { + if (inputSetupFeatureFlagIsEnabled && isInputInSetupMode(inputStates, input.id)) { return (