The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Fix 2 flaky tests (#66839)
Denis Berezin6aac5296de25
diff --git a/e2e/test/scenarios/documents/documents.cy.spec.ts b/e2e/test/scenarios/documents/documents.cy.spec.tsindex 6ef41d49cdd..27683a27c29 100644--- a/e2e/test/scenarios/documents/documents.cy.spec.ts+++ b/e2e/test/scenarios/documents/documents.cy.spec.ts@@ -1240,15 +1240,19 @@ describe("documents", () => {it("should display an error toast when creating a new document fails", () => {// setupcy.intercept("POST", "/api/document", { statusCode: 500 });+ cy.intercept("GET", "/api/collection/*").as("getCollection");cy.visit("/document/new");// make changes and attempt to savecy.findByRole("textbox", { name: "Document Title" }).type("Title");H.documentSaveButton().click();H.entityPickerModalTab("Collections").click();- H.entityPickerModalItem(0, "Our analytics")- .should("have.attr", "data-active", "true")- .click();+ cy.wait("@getCollection");+ H.entityPickerModalItem(0, "Our analytics").should(+ "have.attr",+ "data-active",+ "true",+ );H.entityPickerModal().findByRole("button", { name: "Select" }).click();// assert error toast is visible and user can reattempt savediff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/sync-task-slice.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/sync-task-slice.tsindex 5176be802d4..f1b81bc2fde 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/sync-task-slice.ts+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/sync-task-slice.ts@@ -34,9 +34,15 @@ export const remoteSyncSlice = createSlice({state.showModal = true;},taskUpdated: (state, action: { payload: RemoteSyncTask }) => {- state.currentTask = action.payload;- if (action.payload.ended_at === null) {- state.showModal = true;+ if (+ !state.currentTask ||+ // status for old task can come in when a new task has been already started+ state.currentTask.sync_task_type === action.payload.sync_task_type+ ) {+ state.currentTask = action.payload;+ if (action.payload.ended_at === null) {+ state.showModal = true;+ }}},modalDismissed: (state) => {diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/sync-task-slice.unit.spec.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/sync-task-slice.unit.spec.tsnew file mode 100644index 00000000000..48d1f1acde3--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/sync-task-slice.unit.spec.ts@@ -0,0 +1,107 @@+import type { RemoteSyncTask } from "metabase-types/api";++import {+ initialState,+ remoteSyncReducer,+ taskStarted,+ taskUpdated,+} from "./sync-task-slice";++describe("sync-task-slice", () => {+ describe("taskUpdated with different task types", () => {+ it("should not update currentTask when taskUpdated is for a different task type", () => {+ // Start with export task+ let state = remoteSyncReducer(+ initialState,+ taskStarted({ taskType: "export" }),+ );++ expect(state.currentTask?.sync_task_type).toBe("export");+ expect(state.showModal).toBe(true);++ // Start import task (overwrites export task)+ state = remoteSyncReducer(state, taskStarted({ taskType: "import" }));++ expect(state.currentTask?.sync_task_type).toBe("import");+ expect(state.showModal).toBe(true);++ // Try to update with export task data+ const exportTaskUpdate: RemoteSyncTask = {+ id: 1,+ sync_task_type: "export",+ status: "successful",+ progress: 100,+ started_at: new Date().toISOString(),+ ended_at: new Date().toISOString(),+ last_progress_report_at: new Date().toISOString(),+ error_message: null,+ initiated_by: 1,+ };++ state = remoteSyncReducer(state, taskUpdated(exportTaskUpdate));++ // Current task should still be the import task, not updated to export+ expect(state.currentTask?.sync_task_type).toBe("import");+ expect(state.currentTask?.id).toBe(0); // Still the original import task with id 0+ expect(state.currentTask?.status).toBe("running"); // Still in running state+ });++ it("should update currentTask when taskUpdated is for the same task type", () => {+ // Start with import task+ let state = remoteSyncReducer(+ initialState,+ taskStarted({ taskType: "import" }),+ );++ expect(state.currentTask?.sync_task_type).toBe("import");++ // Update import task with new data+ const importTaskUpdate: RemoteSyncTask = {+ id: 1,+ sync_task_type: "import",+ status: "successful",+ progress: 100,+ started_at: new Date().toISOString(),+ ended_at: new Date().toISOString(),+ last_progress_report_at: new Date().toISOString(),+ error_message: null,+ initiated_by: 1,+ };++ state = remoteSyncReducer(state, taskUpdated(importTaskUpdate));++ // Current task should be updated+ expect(state.currentTask?.sync_task_type).toBe("import");+ expect(state.currentTask?.id).toBe(1);+ expect(state.currentTask?.status).toBe("successful");+ expect(state.currentTask?.progress).toBe(100);+ });++ it("should update currentTask when there is no current task", () => {+ // Start with no current task+ let state = initialState;++ expect(state.currentTask).toBeNull();++ // Update with export task data+ const exportTaskUpdate: RemoteSyncTask = {+ id: 1,+ sync_task_type: "export",+ status: "successful",+ progress: 100,+ started_at: new Date().toISOString(),+ ended_at: new Date().toISOString(),+ last_progress_report_at: new Date().toISOString(),+ error_message: null,+ initiated_by: 1,+ };++ state = remoteSyncReducer(state, taskUpdated(exportTaskUpdate));++ // Current task should be set to the export task+ expect(state.currentTask?.sync_task_type).toBe("export");+ expect(state.currentTask?.id).toBe(1);+ expect(state.currentTask?.status).toBe("successful");+ });+ });+});