Skip to content
Snippets Groups Projects
Unverified Commit a8dc07be authored by Tom Robinson's avatar Tom Robinson Committed by GitHub
Browse files

Port pulse e2e test (#11661)

parent ec965c57
No related branches found
No related tags found
No related merge requests found
import {
useSharedAdminLogin,
createTestStore,
createSavedQuestion,
} from "__support__/e2e";
import { click, setInputValue } from "__support__/enzyme";
import React from "react";
import { mount } from "enzyme";
import { CardApi, PulseApi } from "metabase/services";
import Question from "metabase-lib/lib/Question";
import PulseEditApp from "metabase/pulse/containers/PulseEditApp";
import QuestionSelect from "metabase/containers/QuestionSelect";
import PulseCardPreview from "metabase/pulse/components/PulseCardPreview";
import Toggle from "metabase/components/Toggle";
import {
SET_EDITING_PULSE,
SAVE_EDITING_PULSE,
FETCH_PULSE_CARD_PREVIEW,
} from "metabase/pulse/actions";
describe("Pulse", () => {
let questionCount, questionRaw;
const normalFormInput = PulseApi.form_input;
beforeAll(async () => {
useSharedAdminLogin();
const formInput = await PulseApi.form_input();
PulseApi.form_input = () => ({
channels: {
...formInput.channels,
email: {
...formInput.channels.email,
configured: true,
},
},
});
questionCount = await createSavedQuestion(
Question.create({ databaseId: 1, tableId: 1, metadata: null })
.query()
.aggregate(["count"])
.question()
.setDisplay("scalar")
.setDisplayName("count"),
);
questionRaw = await createSavedQuestion(
Question.create({ databaseId: 1, tableId: 1, metadata: null })
.query()
.question()
.setDisplay("table")
.setDisplayName("table"),
);
// possibly not necessary, but just to be sure we start with clean slate
for (const pulse of await PulseApi.list()) {
await PulseApi.delete({ pulseId: pulse.id });
}
});
afterAll(async () => {
PulseApi.form_input = normalFormInput;
await CardApi.delete({ cardId: questionCount.id() });
await CardApi.delete({ cardId: questionRaw.id() });
for (const pulse of await PulseApi.list()) {
await PulseApi.delete({ pulseId: pulse.id });
}
});
let store;
beforeEach(async () => {
store = await createTestStore();
});
it("should load create pulse", async () => {
store.pushPath("/pulse/create");
const app = mount(store.connectContainer(<PulseEditApp />));
await store.waitForActions([SET_EDITING_PULSE]);
// no previews yet
expect(app.find(PulseCardPreview).length).toBe(0);
// set name to 'foo'
setInputValue(app.find("input").first(), "foo");
// email channel should be enabled
expect(
app
.find(Toggle)
.first()
.props().value,
).toBe(true);
// add count card
app
.find(QuestionSelect)
.first()
.props()
.onChange(questionCount.id());
await store.waitForActions([FETCH_PULSE_CARD_PREVIEW]);
// add raw card
app
.find(QuestionSelect)
.first()
.props()
.onChange(questionRaw.id());
await store.waitForActions([FETCH_PULSE_CARD_PREVIEW]);
let previews = app.find(PulseCardPreview);
expect(previews.length).toBe(2);
// NOTE: check text content since enzyme doesn't doesn't seem to work well with dangerouslySetInnerHTML
expect(previews.at(0).text()).toBe("count18,760");
expect(previews.at(0).find(".Icon-attachment").length).toBe(1);
expect(previews.at(1).text()).toEqual(
expect.stringContaining("Showing 20 of 18,760 rows"),
);
expect(previews.at(1).find(".Icon-attachment").length).toBe(0);
// toggle email channel off
click(app.find(Toggle).first());
previews = app.find(PulseCardPreview);
expect(previews.at(0).text()).toBe("count18,760");
expect(previews.at(0).find(".Icon-attachment").length).toBe(0);
expect(previews.at(1).text()).toEqual(
expect.stringContaining("Showing 20 of 18,760 rows"),
);
expect(previews.at(1).find(".Icon-attachment").length).toBe(0);
// toggle email channel on
click(app.find(Toggle).first());
// save
const saveButton = app.find(".PulseEdit-footer .Button").first();
expect(saveButton.hasClass("Button--primary")).toBe(true);
click(saveButton);
await store.waitForActions([SAVE_EDITING_PULSE]);
const [pulse] = await PulseApi.list();
expect(pulse.name).toBe("foo");
expect(pulse.cards[0].id).toBe(questionCount.id());
expect(pulse.cards[1].id).toBe(questionRaw.id());
expect(pulse.channels[0].channel_type).toBe("email");
expect(pulse.channels[0].enabled).toBe(true);
});
});
import { signInAsAdmin, restore } from "__support__/cypress";
const MOCK_PULSE_FORM_INPUT = {
channels: {
email: {
type: "email",
name: "Email",
allows_recipients: true,
configured: true,
recipients: ["user", "email"],
schedules: ["daily", "weekly", "monthly"],
},
},
};
describe("pulse", () => {
before(restore);
beforeEach(signInAsAdmin);
it("should be able get to the new pulse page from the nav bar", () => {
cy.visit("/");
cy.get(".Icon-add").click();
cy.contains("New pulse").click();
cy.url().should("match", /\/pulse\/create$/);
});
it("should create a new pulse", () => {
cy.server();
cy.route("GET", "/api/pulse/form_input", MOCK_PULSE_FORM_INPUT);
cy.visit("/pulse/create");
cy.get('[placeholder="Important metrics"]')
.wait(10)
.type("pulse title");
cy.contains("Select a question").click();
cy.contains("Orders, Count").click();
// pulse card preview
cy.contains("18,760");
cy.contains("Create pulse").click();
cy.url().should("match", /\/collection\/root$/);
cy.contains("pulse title");
});
it("should load existing pulses", () => {
cy.visit("/collection/root");
cy.contains("pulse title").click({ force: true });
cy.contains("18,760");
});
it("should edit existing pulses", () => {
cy.visit("/pulse/1");
cy.get('[placeholder="Important metrics"]')
.clear()
.type("new pulse title");
cy.contains("Save changes").click();
cy.url().should("match", /\/collection\/root$/);
cy.contains("new pulse title");
});
});
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