Skip to content
Snippets Groups Projects
Commit dec7ff44 authored by Tom Robinson's avatar Tom Robinson
Browse files

Refactor alert.integ.spec cleanup

parent fb946115
Branches
Tags
No related merge requests found
......@@ -581,17 +581,24 @@ export const eventually = async (assertion, timeout = 5000, period = 250) => {
// })
// afterAll(cleanup);
//
export const cleanup = () => {
export const cleanup = async () => {
useSharedAdminLogin();
Promise.all(
cleanup.actions.splice(0, cleanup.actions.length).map(action => action()),
);
try {
await Promise.all(
cleanup.actions.splice(0, cleanup.actions.length).map(action => action()),
);
} catch (e) {
console.warn("CLEANUP FAILED", e);
throw e;
}
};
cleanup.actions = [];
cleanup.fn = action => cleanup.actions.push(action);
cleanup.metric = metric => cleanup.fn(() => deleteMetric(metric));
cleanup.segment = segment => cleanup.fn(() => deleteSegment(segment));
cleanup.question = question => cleanup.fn(() => deleteQuestion(question));
cleanup.collection = collection =>
cleanup.fn(() => deleteCollection(collection));
export const deleteQuestion = question =>
CardApi.delete({ cardId: getId(question) });
......@@ -599,6 +606,8 @@ export const deleteSegment = segment =>
SegmentApi.delete({ segmentId: getId(segment), revision_message: "Please" });
export const deleteMetric = metric =>
MetricApi.delete({ metricId: getId(metric), revision_message: "Please" });
export const deleteCollection = collection =>
CollectionsApi.update({ id: getId(collection), archived: true });
const getId = o =>
typeof o === "object" && o != null
......
......@@ -5,19 +5,14 @@ import {
forBothAdminsAndNormalUsers,
useSharedAdminLogin,
useSharedNormalLogin,
cleanup,
} from "__support__/integrated_tests";
import { click, clickButton } from "__support__/enzyme_utils";
import { fetchTableMetadata } from "metabase/redux/metadata";
import { mount } from "enzyme";
import { setIn } from "icepick";
import {
AlertApi,
CardApi,
PulseApi,
UserApi,
CollectionsApi,
} from "metabase/services";
import { AlertApi, PulseApi, UserApi } from "metabase/services";
import Question from "metabase-lib/lib/Question";
import * as Urls from "metabase/lib/urls";
import { INITIALIZE_QB, QUERY_COMPLETED } from "metabase/query_builder/actions";
......@@ -88,7 +83,6 @@ const initQbWithAlertMenuItemClicked = async (
};
describe("Alerts", () => {
let collection = null;
let rawDataQuestion = null;
let timeSeriesQuestion = null;
let timeSeriesWithGoalQuestion = null;
......@@ -101,7 +95,7 @@ describe("Alerts", () => {
const store = await createTestStore();
// create a collection which all users have write permissions in
collection = await createAllUsersWritableCollection();
const collection = await createAllUsersWritableCollection();
// table metadata is needed for `Question.alertType()` calls
await store.dispatch(fetchTableMetadata(1));
......@@ -115,6 +109,7 @@ describe("Alerts", () => {
.setDisplayName("Just raw, untamed data")
.setCollectionId(collection.id),
);
cleanup.question(rawDataQuestion);
timeSeriesQuestion = await createSavedQuestion(
Question.create({ databaseId: 1, tableId: 1, metadata })
......@@ -130,6 +125,7 @@ describe("Alerts", () => {
.setDisplayName("Time series line")
.setCollectionId(collection.id),
);
cleanup.question(timeSeriesQuestion);
timeSeriesWithGoalQuestion = await createSavedQuestion(
Question.create({ databaseId: 1, tableId: 1, metadata })
......@@ -147,6 +143,7 @@ describe("Alerts", () => {
.setDisplayName("Time series line with goal")
.setCollectionId(collection.id),
);
cleanup.question(timeSeriesWithGoalQuestion);
timeMultiSeriesWithGoalQuestion = await createSavedQuestion(
Question.create({ databaseId: 1, tableId: 1, metadata })
......@@ -165,6 +162,7 @@ describe("Alerts", () => {
.setDisplayName("Time multiseries line with goal")
.setCollectionId(collection.id),
);
cleanup.question(timeMultiSeriesWithGoalQuestion);
progressBarQuestion = await createSavedQuestion(
Question.create({ databaseId: 1, tableId: 1, metadata })
......@@ -176,17 +174,13 @@ describe("Alerts", () => {
.setDisplayName("Progress bar question")
.setCollectionId(collection.id),
);
});
cleanup.question(progressBarQuestion);
afterAll(async () => {
await CardApi.delete({ cardId: rawDataQuestion.id() });
await CardApi.delete({ cardId: timeSeriesQuestion.id() });
await CardApi.delete({ cardId: timeSeriesWithGoalQuestion.id() });
await CardApi.delete({ cardId: timeMultiSeriesWithGoalQuestion.id() });
await CardApi.delete({ cardId: progressBarQuestion.id() });
await CollectionsApi.update({ id: collection.id, archived: true });
cleanup.collection(collection);
});
afterAll(cleanup);
describe("missing email/slack credentials", () => {
forBothAdminsAndNormalUsers(() => {
it("should prompt you to add email/slack credentials", async () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment