示例#1
0
  beforeAll(async () => {
    useSharedAdminLogin();
    cleanup.segment(await SegmentApi.create(orders_past_300_days_segment));
    store = await createTestStore();

    store.pushPath(Urls.plainQuestion());
    queryBuilder = mount(store.connectContainer(<QueryBuilder />));
    await store.waitForActions([INITIALIZE_QB]);
  });
    beforeAll(async () => {
        useSharedAdminLogin();
        metricId = (await MetricApi.create(vendor_count_metric)).id;
        store = await createTestStore()

        store.pushPath(Urls.plainQuestion());
        queryBuilder = mount(store.connectContainer(<QueryBuilder />));
        await store.waitForActions([INITIALIZE_QB]);
    })
示例#3
0
    return async () => {
        const store = await createTestStore()
        store.pushPath(Urls.plainQuestion());
        const qb = mount(store.connectContainer(<QueryBuilder />));
        await store.waitForActions([INITIALIZE_QB]);

        // Use Products table
        store.dispatch(setQueryDatabase(dbId));
        store.dispatch(setQuerySourceTable(tableId));
        await store.waitForActions([FETCH_TABLE_METADATA]);

        return { store, qb }
    }
        it("should allow users to create parameterized SQL questions", async () => {
            // Don't render Ace editor in tests because it uses many DOM methods that aren't supported by jsdom
            // NOTE Atte Keinänen 8/9/17: Ace provides a MockRenderer class which could be used for pseudo-rendering and
            // testing Ace editor in tests, but it doesn't render stuff to DOM so I'm not sure how practical it would be
            NativeQueryEditor.prototype.loadAceEditor = () => {
            }

            const store = await createTestStore();

            // load public sharing settings
            store.pushPath(Urls.plainQuestion());
            const app = mount(store.getAppContainer())
            await store.waitForActions([INITIALIZE_QB]);

            click(app.find(".Icon-sql"));
            await store.waitForActions([SET_QUERY_MODE]);

            await updateQueryText(store, "select count(*) from products where {{category}}");

            const tagEditorSidebar = app.find(TagEditorSidebar);

            const fieldFilterVarType = tagEditorSidebar.find('.ColumnarSelector-row').at(3);
            expect(fieldFilterVarType.text()).toBe("Field Filter");
            click(fieldFilterVarType);

            await store.waitForActions([UPDATE_TEMPLATE_TAG]);

            await delay(500);

            setInputValue(tagEditorSidebar.find(".TestPopoverBody .AdminSelect").first(), "cat")
            const categoryRow = tagEditorSidebar.find(".TestPopoverBody .ColumnarSelector-row").first();
            expect(categoryRow.text()).toBe("ProductsCategory");
            click(categoryRow);

            await store.waitForActions([UPDATE_TEMPLATE_TAG, FETCH_FIELD_VALUES])

            // close the template variable sidebar
            click(tagEditorSidebar.find(".Icon-close"));

            // test without the parameter
            click(app.find(RunButton));
            await store.waitForActions([RUN_QUERY, QUERY_COMPLETED])
            expect(app.find(Scalar).text()).toBe(COUNT_ALL);

            // test the parameter
            click(app.find(Parameters).find("a").first());
            click(app.find(CategoryWidget).find('li[children="Doohickey"]'));
            click(app.find(RunButton));
            await store.waitForActions([RUN_QUERY, QUERY_COMPLETED])
            expect(app.find(Scalar).text()).toBe(COUNT_DOOHICKEY);

            // save the question, required for public link/embedding
            click(app.find(".Header-buttonSection a").first().find("a"))
            await store.waitForActions([LOAD_COLLECTIONS]);

            setInputValue(app.find(SaveQuestionModal).find("input[name='name']"), "sql parametrized");

            clickButton(app.find(SaveQuestionModal).find("button").last());
            await store.waitForActions([NOTIFY_CARD_CREATED]);

            click(app.find('#QuestionSavedModal .Button[children="Not now"]'))
            // wait for modal to close :'(
            await delay(500);

            // open sharing panel
            click(app.find(".Icon-share"));

            // "Embed this question in an application"
            click(app.find(SharingPane).find("h3").last());

            // make the parameter editable
            click(app.find(".AdminSelect-content[children='Disabled']"));

            click(app.find(".TestPopoverBody .Icon-pencil"))

            await delay(500);

            click(app.find("div[children='Publish']"));
            await store.waitForActions([UPDATE_ENABLE_EMBEDDING, UPDATE_EMBEDDING_PARAMS])

            // save the embed url for next tests
            embedUrl = getRelativeUrlWithoutHash(app.find(PreviewPane).find("iframe").prop("src"));

            // back to main share panel
            click(app.find(EmbedTitle));

            // toggle public link on
            click(app.find(SharingPane).find(Toggle));
            await store.waitForActions([CREATE_PUBLIC_LINK]);

            // save the public url for next tests
            publicUrl = getRelativeUrlWithoutHash(app.find(CopyWidget).find("input").first().prop("value"));
        });