Ejemplo n.º 1
0
 return async function(dispatch, getState) {
     let { pulse: { editingPulse } } = getState();
     if (editingPulse.id != null) {
         return await PulseApi.update(editingPulse);
     } else {
         return await PulseApi.create(editingPulse);
     }
 };
Ejemplo n.º 2
0
  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 })
    }
  })
Ejemplo n.º 3
0
  it("should load create pulse", async () => {
    store.pushPath("/pulse/create");
    const app = mount(store.connectContainer(<PulseEditApp />));
    await store.waitForActions([SET_EDITING_PULSE,FETCH_CARDS]);

    // 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(CardPicker).first().props().onChange(questionCount.id())
    await store.waitForActions([FETCH_PULSE_CARD_PREVIEW]);

    // add raw card
    app.find(CardPicker).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("count12,805")
    expect(previews.at(0).find(".Icon-attachment").length).toBe(1)
    expect(previews.at(1).text()).toBe("tableThis question will be added as a file attachment")
    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("count12,805")
    expect(previews.at(0).find(".Icon-attachment").length).toBe(0)
    expect(previews.at(1).text()).toBe("tableThis question won't be included in your Pulse")
    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);
  })
Ejemplo n.º 4
0
 return async function(dispatch, getState) {
     if (id != null) {
         try {
             return await PulseApi.get({ pulseId: id });
         } catch (e) {
         }
     }
     // HACK: need a way to wait for form_input to finish loading
     const channels = formInputSelector(getState()).channels ||
         (await PulseApi.form_input()).channels;
     const defaultChannelSpec = getDefaultChannel(channels);
     return {
         name: null,
         cards: [],
         channels: defaultChannelSpec ?
           [createChannel(defaultChannelSpec)] :
           [],
         skip_if_empty: false,
     }
 };
Ejemplo n.º 5
0
  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()
            .addAggregation(["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 })
    }
  })
Ejemplo n.º 6
0
 return async function(dispatch, getState) {
     return await PulseApi.test(pulse);
 };
Ejemplo n.º 7
0
 return async function(dispatch, getState) {
     return await PulseApi.delete({ pulseId: id });
 };
Ejemplo n.º 8
0
 return async function(dispatch, getState) {
     let pulses = await PulseApi.list();
     return normalize(pulses, [pulse]);
 };
Ejemplo n.º 9
0
 return async function(dispatch, getState) {
     return await PulseApi.preview_card({ id: id });
 }
Ejemplo n.º 10
0
 return async function(dispatch, getState) {
     return await PulseApi.form_input();
 };