|
| 1 | +import {GroupFixture} from 'sentry-fixture/group'; |
| 2 | + |
| 3 | +import {renderHook} from 'sentry-test/reactTestingLibrary'; |
| 4 | + |
| 5 | +import type {useExplorerAutofix} from 'sentry/components/events/autofix/useExplorerAutofix'; |
| 6 | +import {useAutoTriggerAutofix} from 'sentry/components/events/autofix/v3/useAutoTriggerAutofix'; |
| 7 | + |
| 8 | +function makeAutofix( |
| 9 | + overrides: Partial<ReturnType<typeof useExplorerAutofix>> = {} |
| 10 | +): ReturnType<typeof useExplorerAutofix> { |
| 11 | + return { |
| 12 | + runState: null, |
| 13 | + startStep: jest.fn(), |
| 14 | + createPR: jest.fn(), |
| 15 | + reset: jest.fn(), |
| 16 | + triggerCodingAgentHandoff: jest.fn(), |
| 17 | + isLoading: false, |
| 18 | + isPolling: false, |
| 19 | + ...overrides, |
| 20 | + } as ReturnType<typeof useExplorerAutofix>; |
| 21 | +} |
| 22 | + |
| 23 | +describe('useAutoTriggerAutofix', () => { |
| 24 | + it('starts root_cause when seerAutofixLastTriggered is set but seerExplorerAutofixLastTriggered is not', () => { |
| 25 | + const autofix = makeAutofix(); |
| 26 | + const group = GroupFixture({ |
| 27 | + seerAutofixLastTriggered: '2024-01-01T00:00:00Z', |
| 28 | + seerExplorerAutofixLastTriggered: null, |
| 29 | + }); |
| 30 | + |
| 31 | + renderHook(() => useAutoTriggerAutofix({autofix, group})); |
| 32 | + |
| 33 | + expect(autofix.startStep).toHaveBeenCalledWith('root_cause'); |
| 34 | + expect(autofix.startStep).toHaveBeenCalledTimes(1); |
| 35 | + }); |
| 36 | + |
| 37 | + it('does not start root_cause when seerExplorerAutofixLastTriggered is set', () => { |
| 38 | + const autofix = makeAutofix(); |
| 39 | + const group = GroupFixture({ |
| 40 | + seerAutofixLastTriggered: '2024-01-01T00:00:00Z', |
| 41 | + seerExplorerAutofixLastTriggered: '2024-01-02T00:00:00Z', |
| 42 | + }); |
| 43 | + |
| 44 | + renderHook(() => useAutoTriggerAutofix({autofix, group})); |
| 45 | + |
| 46 | + expect(autofix.startStep).not.toHaveBeenCalled(); |
| 47 | + }); |
| 48 | + |
| 49 | + it('does not trigger root_cause more than once on re-render', () => { |
| 50 | + const autofix = makeAutofix(); |
| 51 | + const group = GroupFixture({ |
| 52 | + seerAutofixLastTriggered: '2024-01-01T00:00:00Z', |
| 53 | + seerExplorerAutofixLastTriggered: null, |
| 54 | + }); |
| 55 | + |
| 56 | + const {rerender} = renderHook(() => useAutoTriggerAutofix({autofix, group})); |
| 57 | + |
| 58 | + rerender(); |
| 59 | + rerender(); |
| 60 | + |
| 61 | + expect(autofix.startStep).toHaveBeenCalledTimes(1); |
| 62 | + }); |
| 63 | +}); |
0 commit comments