|
1 | 1 | import { |
| 2 | + act, |
2 | 3 | fireEvent, |
3 | 4 | render, |
4 | 5 | screen, |
@@ -30,8 +31,11 @@ const runtimeMock = vi.hoisted(() => ({ |
30 | 31 | resolvePluginRecipeChoices: vi.fn(), |
31 | 32 | resolvePluginRecipeCallbacks: vi.fn(), |
32 | 33 | resolvePluginRecipeActive: vi.fn(), |
| 34 | + onWorkspaceMutation: vi.fn(), |
33 | 35 | })); |
34 | 36 |
|
| 37 | +const mutationListeners: ((name: string) => void)[] = []; |
| 38 | + |
35 | 39 | vi.mock("../../../src/runtime/RuntimeContext", () => ({ |
36 | 40 | useRuntime: () => ({ runtime: runtimeMock as unknown as RuntimeApi }), |
37 | 41 | })); |
@@ -224,6 +228,15 @@ function renderDialog( |
224 | 228 |
|
225 | 229 | beforeEach(() => { |
226 | 230 | vi.clearAllMocks(); |
| 231 | + mutationListeners.length = 0; |
| 232 | + runtimeMock.onWorkspaceMutation.mockImplementation( |
| 233 | + (listener: (name: string) => void) => { |
| 234 | + mutationListeners.push(listener); |
| 235 | + return () => { |
| 236 | + mutationListeners.splice(mutationListeners.indexOf(listener), 1); |
| 237 | + }; |
| 238 | + }, |
| 239 | + ); |
227 | 240 | runtimeMock.listPlugins.mockResolvedValue([APPLICATION]); |
228 | 241 | runtimeMock.assessPluginRecipes.mockResolvedValue({ [RECIPE_ID]: READY }); |
229 | 242 | runtimeMock.preparePluginRecipe.mockResolvedValue(PREPARATION); |
@@ -321,6 +334,39 @@ describe("ApplicationsDialog", () => { |
321 | 334 | ); |
322 | 335 | }); |
323 | 336 |
|
| 337 | + it("re-assesses the methods when workspace objects change", async () => { |
| 338 | + renderDialog(); |
| 339 | + await screen.findByText("Ready to run on the current selection"); |
| 340 | + const assessments = runtimeMock.assessPluginRecipes.mock.calls.length; |
| 341 | + |
| 342 | + runtimeMock.assessPluginRecipes.mockResolvedValueOnce({ |
| 343 | + [RECIPE_ID]: { |
| 344 | + status: "not_ready", |
| 345 | + bindings: { frames: ["image-1", "image-2"] }, |
| 346 | + issues: [ |
| 347 | + { |
| 348 | + code: "missing_metadata", |
| 349 | + slot_id: "frames", |
| 350 | + details: { key: "exposure_time", count: 2, titles: ["A", "B"] }, |
| 351 | + }, |
| 352 | + ], |
| 353 | + diagnostics: [], |
| 354 | + }, |
| 355 | + }); |
| 356 | + act(() => { |
| 357 | + for (const listener of [...mutationListeners]) { |
| 358 | + listener("delete_object_metadata"); |
| 359 | + } |
| 360 | + }); |
| 361 | + |
| 362 | + expect( |
| 363 | + await screen.findByText("To set it, use Edit > Metadata > Add metadata…"), |
| 364 | + ).toBeInTheDocument(); |
| 365 | + expect(runtimeMock.assessPluginRecipes).toHaveBeenCalledTimes( |
| 366 | + assessments + 1, |
| 367 | + ); |
| 368 | + }); |
| 369 | + |
324 | 370 | it("runs a ready method directly on the current selection", async () => { |
325 | 371 | const onCommitted = vi.fn(); |
326 | 372 | renderDialog({ onCommitted }); |
|
0 commit comments