|
| 1 | +// biome-ignore-all lint/suspicious/noExplicitAny: store mocks intentionally accept multiple selector shapes |
1 | 2 | import { renderHook } from "@testing-library/react"; |
2 | 3 | import useSaveFlow from "../use-save-flow"; |
3 | 4 |
|
@@ -129,6 +130,82 @@ describe("useSaveFlow", () => { |
129 | 130 | expect(mockSetCurrentFlow).toHaveBeenCalled(); |
130 | 131 | }); |
131 | 132 |
|
| 133 | + it("does not autosave hydrated data while the persisted flow is locked", async () => { |
| 134 | + const persistedFlow = { |
| 135 | + ...flowsManagerState.currentFlow, |
| 136 | + locked: true, |
| 137 | + }; |
| 138 | + flowsManagerState.currentFlow = persistedFlow; |
| 139 | + flowsManagerState.flows = [persistedFlow]; |
| 140 | + flowStoreState.currentFlow = { |
| 141 | + ...persistedFlow, |
| 142 | + data: { |
| 143 | + ...persistedFlow.data, |
| 144 | + nodes: [{ id: "old-node", data: { is_refresh: true } }], |
| 145 | + viewport: { x: 10, y: 20, zoom: 0.75 }, |
| 146 | + }, |
| 147 | + }; |
| 148 | + |
| 149 | + const { result } = renderHook(() => useSaveFlow()); |
| 150 | + |
| 151 | + await expect(result.current()).resolves.toBeUndefined(); |
| 152 | + |
| 153 | + expect(mockMutate).not.toHaveBeenCalled(); |
| 154 | + expect(mockSetSaveLoading).not.toHaveBeenCalled(); |
| 155 | + }); |
| 156 | + |
| 157 | + it("unlocks a persisted flow before saving other settings changes", async () => { |
| 158 | + const persistedFlow = { |
| 159 | + ...flowsManagerState.currentFlow, |
| 160 | + locked: true, |
| 161 | + }; |
| 162 | + const requestedFlow = { |
| 163 | + ...persistedFlow, |
| 164 | + name: "Renamed after unlock", |
| 165 | + locked: false, |
| 166 | + data: { |
| 167 | + ...persistedFlow.data, |
| 168 | + nodes: [{ id: "old-node", data: { is_refresh: true } }], |
| 169 | + }, |
| 170 | + }; |
| 171 | + flowsManagerState.currentFlow = persistedFlow; |
| 172 | + flowsManagerState.flows = [persistedFlow]; |
| 173 | + flowStoreState.currentFlow = persistedFlow; |
| 174 | + |
| 175 | + mockMutate.mockImplementation((payload, options) => { |
| 176 | + options.onSuccess({ |
| 177 | + ...requestedFlow, |
| 178 | + ...payload, |
| 179 | + }); |
| 180 | + }); |
| 181 | + |
| 182 | + const { result } = renderHook(() => useSaveFlow()); |
| 183 | + |
| 184 | + await expect(result.current(requestedFlow)).resolves.toBeUndefined(); |
| 185 | + |
| 186 | + expect(mockMutate).toHaveBeenCalledTimes(2); |
| 187 | + expect(mockMutate.mock.calls[0][0]).toEqual({ |
| 188 | + id: "flow-1", |
| 189 | + locked: false, |
| 190 | + }); |
| 191 | + expect(mockMutate.mock.calls[1][0]).toEqual( |
| 192 | + expect.objectContaining({ |
| 193 | + id: "flow-1", |
| 194 | + name: "Renamed after unlock", |
| 195 | + locked: false, |
| 196 | + data: requestedFlow.data, |
| 197 | + }), |
| 198 | + ); |
| 199 | + expect(mockSetSaveLoading).toHaveBeenCalledWith(true); |
| 200 | + expect(mockSetSaveLoading).toHaveBeenCalledWith(false); |
| 201 | + expect(mockSetCurrentFlow).toHaveBeenCalledWith( |
| 202 | + expect.objectContaining({ |
| 203 | + name: "Renamed after unlock", |
| 204 | + locked: false, |
| 205 | + }), |
| 206 | + ); |
| 207 | + }); |
| 208 | + |
132 | 209 | it("should_update_store_flow_folder_id_when_moved_via_drag_drop_from_dashboard", async () => { |
133 | 210 | // Arrange — dashboard scenario: no flow open in the editor, the |
134 | 211 | // global flows store is populated from `header_flows=true`, so the |
|
0 commit comments