Files
metabase/e2e/support/helpers/api/createQuestionAndAddToDashboard.ts
Kamil Mielnik 5a1d677444 RFC 118. Prettier - arrowParens: “always” (#55807)
* Update .prettierrc
- remove "arrowParens": "avoid" so that it defaults to "always" instead

* Run "yarn prettier"
2025-03-27 09:18:07 +00:00

50 lines
1.4 KiB
TypeScript

import type { Card, DashboardCard, DashboardId } from "metabase-types/api";
import {
type NativeQuestionDetails,
createNativeQuestion,
} from "./createNativeQuestion";
import {
type StructuredQuestionDetails,
createQuestion,
} from "./createQuestion";
export const createQuestionAndAddToDashboard = (
query: NativeQuestionDetails | StructuredQuestionDetails,
dashboardId: DashboardId,
card?: Partial<Card>,
): Cypress.Chainable<Cypress.Response<DashboardCard>> =>
(isNative(query) ? createNativeQuestion(query) : createQuestion(query)).then(
({ body: { id: card_id } }) =>
cy
.request(`/api/dashboard/${dashboardId}`)
.then(({ body: { dashcards } }) =>
cy
.request("PUT", `/api/dashboard/${dashboardId}`, {
dashcards: [
...dashcards,
{
id: -1,
card_id,
// Add sane defaults for the dashboard card size and position
row: 0,
col: 0,
size_x: 11,
size_y: 8,
...card,
},
],
})
.then((response) => ({
...response,
body: response.body.dashcards.at(-1),
})),
),
);
const isNative = (
query: NativeQuestionDetails | StructuredQuestionDetails,
): query is NativeQuestionDetails => {
return "native" in query;
};