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

Fix metrics/segmentsi test

parent d59a9cd4
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ import {
import React from "react";
import { mount } from "enzyme";
import { assocIn } from "icepick";
import { CardApi, MetricApi } from "metabase/services";
......@@ -21,6 +22,8 @@ import MetricDetailContainer from "metabase/reference/metrics/MetricDetailContai
import MetricQuestionsContainer from "metabase/reference/metrics/MetricQuestionsContainer";
import MetricRevisionsContainer from "metabase/reference/metrics/MetricRevisionsContainer";
// NOTE: database/table_id/source_table are hard-coded, this might be a problem at some point
describe("The Reference Section", () => {
// Test data
const metricDef = {
......@@ -28,7 +31,7 @@ describe("The Reference Section", () => {
description: "I did it!",
table_id: 1,
show_in_getting_started: true,
definition: { database: 1, query: { aggregation: ["count"] } },
definition: { database: 1, query: { aggregation: [["count"]] } },
};
const anotherMetricDef = {
......@@ -36,7 +39,7 @@ describe("The Reference Section", () => {
description: "I did it again!",
table_id: 1,
show_in_getting_started: true,
definition: { database: 1, query: { aggregation: ["count"] } },
definition: { database: 1, query: { aggregation: [["count"]] } },
};
const metricCardDef = {
......@@ -46,7 +49,7 @@ describe("The Reference Section", () => {
database: 1,
table_id: 1,
type: "query",
query: { source_table: 1, aggregation: ["metric", 1] },
query: { source_table: 1, aggregation: [["metric", 1]] },
},
visualization_settings: {},
};
......@@ -116,10 +119,16 @@ describe("The Reference Section", () => {
});
it("Should see a newly asked question in its questions list", async () => {
let card = await CardApi.create(metricCardDef);
expect(card.name).toBe(metricCardDef.name);
let card;
try {
const cardDef = assocIn(
metricCardDef,
["dataset_query", "query", "aggregation", 0, 1],
metricIds[0],
);
card = await CardApi.create(cardDef);
expect(card.name).toBe(metricCardDef.name);
// see that there is a new question on the metric's questions page
const store = await createTestStore();
......@@ -127,8 +136,10 @@ describe("The Reference Section", () => {
mount(store.connectContainer(<MetricQuestionsContainer />));
await store.waitForActions([FETCH_METRICS, FETCH_METRIC_TABLE]);
} finally {
// even if the code above results in an exception, try to delete the question
await CardApi.delete({ cardId: card.id });
if (card) {
// even if the code above results in an exception, try to delete the question
await CardApi.delete({ cardId: card.id });
}
}
});
});
......
......@@ -5,6 +5,7 @@ import {
import React from "react";
import { mount } from "enzyme";
import { assocIn } from "icepick";
import { CardApi, SegmentApi } from "metabase/services";
......@@ -24,6 +25,8 @@ import SegmentRevisionsContainer from "metabase/reference/segments/SegmentRevisi
import SegmentFieldListContainer from "metabase/reference/segments/SegmentFieldListContainer";
import SegmentFieldDetailContainer from "metabase/reference/segments/SegmentFieldDetailContainer";
// NOTE: database/table_id/source_table are hard-coded, this might be a problem at some point
describe("The Reference Section", () => {
// Test data
const segmentDef = {
......@@ -154,7 +157,12 @@ describe("The Reference Section", () => {
});
it("Should see a newly asked question in its questions list", async () => {
let card = await CardApi.create(segmentCardDef);
const cardDef = assocIn(
segmentCardDef,
["dataset_query", "query", "filter", 1],
segmentIds[0],
);
let card = await CardApi.create(cardDef);
expect(card.name).toBe(segmentCardDef.name);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment