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 { ...@@ -5,6 +5,7 @@ import {
import React from "react"; import React from "react";
import { mount } from "enzyme"; import { mount } from "enzyme";
import { assocIn } from "icepick";
import { CardApi, MetricApi } from "metabase/services"; import { CardApi, MetricApi } from "metabase/services";
...@@ -21,6 +22,8 @@ import MetricDetailContainer from "metabase/reference/metrics/MetricDetailContai ...@@ -21,6 +22,8 @@ import MetricDetailContainer from "metabase/reference/metrics/MetricDetailContai
import MetricQuestionsContainer from "metabase/reference/metrics/MetricQuestionsContainer"; import MetricQuestionsContainer from "metabase/reference/metrics/MetricQuestionsContainer";
import MetricRevisionsContainer from "metabase/reference/metrics/MetricRevisionsContainer"; 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", () => { describe("The Reference Section", () => {
// Test data // Test data
const metricDef = { const metricDef = {
...@@ -28,7 +31,7 @@ describe("The Reference Section", () => { ...@@ -28,7 +31,7 @@ describe("The Reference Section", () => {
description: "I did it!", description: "I did it!",
table_id: 1, table_id: 1,
show_in_getting_started: true, show_in_getting_started: true,
definition: { database: 1, query: { aggregation: ["count"] } }, definition: { database: 1, query: { aggregation: [["count"]] } },
}; };
const anotherMetricDef = { const anotherMetricDef = {
...@@ -36,7 +39,7 @@ describe("The Reference Section", () => { ...@@ -36,7 +39,7 @@ describe("The Reference Section", () => {
description: "I did it again!", description: "I did it again!",
table_id: 1, table_id: 1,
show_in_getting_started: true, show_in_getting_started: true,
definition: { database: 1, query: { aggregation: ["count"] } }, definition: { database: 1, query: { aggregation: [["count"]] } },
}; };
const metricCardDef = { const metricCardDef = {
...@@ -46,7 +49,7 @@ describe("The Reference Section", () => { ...@@ -46,7 +49,7 @@ describe("The Reference Section", () => {
database: 1, database: 1,
table_id: 1, table_id: 1,
type: "query", type: "query",
query: { source_table: 1, aggregation: ["metric", 1] }, query: { source_table: 1, aggregation: [["metric", 1]] },
}, },
visualization_settings: {}, visualization_settings: {},
}; };
...@@ -116,10 +119,16 @@ describe("The Reference Section", () => { ...@@ -116,10 +119,16 @@ describe("The Reference Section", () => {
}); });
it("Should see a newly asked question in its questions list", async () => { it("Should see a newly asked question in its questions list", async () => {
let card = await CardApi.create(metricCardDef); let card;
expect(card.name).toBe(metricCardDef.name);
try { 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 // see that there is a new question on the metric's questions page
const store = await createTestStore(); const store = await createTestStore();
...@@ -127,8 +136,10 @@ describe("The Reference Section", () => { ...@@ -127,8 +136,10 @@ describe("The Reference Section", () => {
mount(store.connectContainer(<MetricQuestionsContainer />)); mount(store.connectContainer(<MetricQuestionsContainer />));
await store.waitForActions([FETCH_METRICS, FETCH_METRIC_TABLE]); await store.waitForActions([FETCH_METRICS, FETCH_METRIC_TABLE]);
} finally { } finally {
// even if the code above results in an exception, try to delete the question if (card) {
await CardApi.delete({ cardId: card.id }); // 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 { ...@@ -5,6 +5,7 @@ import {
import React from "react"; import React from "react";
import { mount } from "enzyme"; import { mount } from "enzyme";
import { assocIn } from "icepick";
import { CardApi, SegmentApi } from "metabase/services"; import { CardApi, SegmentApi } from "metabase/services";
...@@ -24,6 +25,8 @@ import SegmentRevisionsContainer from "metabase/reference/segments/SegmentRevisi ...@@ -24,6 +25,8 @@ import SegmentRevisionsContainer from "metabase/reference/segments/SegmentRevisi
import SegmentFieldListContainer from "metabase/reference/segments/SegmentFieldListContainer"; import SegmentFieldListContainer from "metabase/reference/segments/SegmentFieldListContainer";
import SegmentFieldDetailContainer from "metabase/reference/segments/SegmentFieldDetailContainer"; 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", () => { describe("The Reference Section", () => {
// Test data // Test data
const segmentDef = { const segmentDef = {
...@@ -154,7 +157,12 @@ describe("The Reference Section", () => { ...@@ -154,7 +157,12 @@ describe("The Reference Section", () => {
}); });
it("Should see a newly asked question in its questions list", async () => { 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); 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