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

e2e tests for adding card to dashboard and duplicating a dashboard

parent bad17cb1
Branches
Tags
No related merge requests found
......@@ -48,7 +48,10 @@ export default class DashCard extends Component {
// HACK: way to scroll to a newly added card
if (dashcard.justAdded) {
ReactDOM.findDOMNode(this).scrollIntoView();
const element = ReactDOM.findDOMNode(this);
if (element && element.scrollIntoView) {
element.scrollIntoView();
}
markNewCardSeen(dashcard.id);
}
}
......
......@@ -584,10 +584,13 @@ 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.dashboard = dashboard => cleanup.fn(() => deleteDashboard(dashboard));
cleanup.collection = c => cleanup.fn(() => deleteCollection(c));
export const deleteQuestion = question =>
CardApi.delete({ cardId: getId(question) });
export const deleteDashboard = dashboard =>
DashboardApi.delete({ dashId: getId(dashboard) });
export const deleteSegment = segment =>
SegmentApi.delete({ segmentId: getId(segment), revision_message: "Please" });
export const deleteMetric = metric =>
......
import "__support__/mocks";
// requried to get dashboard to render
jest.mock("metabase/components/ExplicitSize");
import {
BROWSER_HISTORY_PUSH,
createTestStore,
useSharedAdminLogin,
cleanup,
} from "__support__/e2e_tests";
import { click, clickButton, setInputValue } from "__support__/enzyme_utils";
......@@ -19,7 +23,12 @@ import {
SET_EDITING_DASHBOARD,
SET_EDITING_PARAMETER_ID,
FETCH_REVISIONS,
FETCH_CARD_DATA,
} from "metabase/dashboard/dashboard";
import Question from "metabase/entities/questions";
import Search from "metabase/entities/search";
import EditBar from "metabase/components/EditBar";
import { delay } from "metabase/lib/promise";
......@@ -86,10 +95,30 @@ PublicApi.dashboard = async () => {
};
describe("Dashboard", () => {
let question;
beforeAll(async () => {
useSharedAdminLogin();
question = await Question.api.create({
name: "Example Question",
display: "scalar",
visualization_settings: {},
dataset_query: {
type: "query",
database: 1,
query: {
"source-table": 1,
aggregation: [["count"]],
},
},
});
cleanup.question(question);
});
afterAll(cleanup);
describe("redux actions", () => {
describe("fetchDashboard(...)", () => {
it("should add the parameter values to state tree for public dashboards", async () => {
......@@ -134,6 +163,7 @@ describe("Dashboard", () => {
// Create a dashboard programmatically
const dashboard = await DashboardApi.create({ name, description });
cleanup.dashboard(dashboard);
dashboardId = dashboard.id;
const store = await createTestStore();
......@@ -271,13 +301,59 @@ describe("Dashboard", () => {
expect(store.getPath()).toBe(`/dashboard/${dashboardId}`);
});
afterAll(async () => {
if (dashboardId) {
await DashboardApi.update({
id: dashboardId,
archived: true,
});
}
it("lets you add a question", async () => {
const store = await createTestStore();
store.pushPath(Urls.dashboard(dashboardId));
const app = mount(store.getAppContainer());
await store.waitForActions([FETCH_DASHBOARD]);
expect(app.find(".DashCard")).toHaveLength(0);
click(app.find(".Dashboard .Icon.Icon-add"));
await store.waitForActions([Search.actionTypes.FETCH_LIST]);
expect(question.name).toBe("Example Question");
await delay(100);
click(app.find(`h4[children=\"${question.name}\"]`));
await store.waitForActions([FETCH_CARD_DATA]);
expect(app.find(".DashCard")).toHaveLength(1);
clickButton(app.find(EditBar).find(".Button--primary.Button"));
await store.waitForActions([SAVE_DASHBOARD_AND_CARDS, FETCH_DASHBOARD]);
});
it("should have added card", async () => {
const store = await createTestStore();
store.pushPath(Urls.dashboard(dashboardId));
const app = mount(store.getAppContainer());
await store.waitForActions([FETCH_DASHBOARD]);
expect(app.find(".DashCard")).toHaveLength(1);
});
it("lets you duplicate a dashboard", async () => {
const store = await createTestStore();
store.pushPath(Urls.dashboard(dashboardId));
const app = mount(store.getAppContainer());
await store.waitForActions([FETCH_DASHBOARD]);
expect(app.find(".DashCard")).toHaveLength(1);
// click copy button
click(app.find(".Icon.Icon-clone"));
// click duplicate button
clickButton(app.find('.Button [children="Duplicate"]'));
await delay(100);
await store.waitForActions([BROWSER_HISTORY_PUSH]);
// NOTE: assumes incrementing dashboardId
expect(store.getPath()).toBe(`/dashboard/${dashboardId + 1}`);
await store.waitForActions([FETCH_DASHBOARD]);
expect(app.find(".DashCard")).toHaveLength(1);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment