Skip to content

Commit

Permalink
feat(sdk-ui-dashboard): rich text widget tests
Browse files Browse the repository at this point in the history
Add basic tests for rich text widget.

JIRA: F1-9
  • Loading branch information
kandl committed Jan 23, 2024
1 parent b904db0 commit a1983a9
Show file tree
Hide file tree
Showing 18 changed files with 560 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ exports[`sizing > getDashboardLayoutWidgetDefaultHeight > with customHeight fals

exports[`sizing > getDashboardLayoutWidgetDefaultHeight > with customHeight false > should get default height for kpi without pop widget 1`] = `240`;

exports[`sizing > getDashboardLayoutWidgetDefaultHeight > with customHeight false > should get default height for rich text widget 1`] = `440`;

exports[`sizing > getDashboardLayoutWidgetDefaultHeight > with customHeight false > should get default height for unknown widget 1`] = `450`;

exports[`sizing > getDashboardLayoutWidgetDefaultHeight > with customHeight true > should get default height for insight widget area 1`] = `440`;
Expand Down Expand Up @@ -84,6 +86,8 @@ exports[`sizing > getDashboardLayoutWidgetDefaultHeight > with customHeight true

exports[`sizing > getDashboardLayoutWidgetDefaultHeight > with customHeight true > should get default height for kpi without pop widget 1`] = `160`;

exports[`sizing > getDashboardLayoutWidgetDefaultHeight > with customHeight true > should get default height for rich text widget 1`] = `440`;

exports[`sizing > getDashboardLayoutWidgetDefaultHeight > with customHeight true > should get default height for unknown widget 1`] = `440`;

exports[`sizing > getDashboardLayoutWidgetMaxGridHeight > with customHeight false > should get max height for insight widget area 1`] = `22.5`;
Expand Down Expand Up @@ -124,6 +128,8 @@ exports[`sizing > getDashboardLayoutWidgetMaxGridHeight > with customHeight fals

exports[`sizing > getDashboardLayoutWidgetMaxGridHeight > with customHeight false > should get max height for kpi widget 1`] = `12`;

exports[`sizing > getDashboardLayoutWidgetMaxGridHeight > with customHeight false > should get max height for rich text widget 1`] = `40`;

exports[`sizing > getDashboardLayoutWidgetMaxGridHeight > with customHeight false > should get max height for unknown widget 1`] = `undefined`;

exports[`sizing > getDashboardLayoutWidgetMaxGridHeight > with customHeight true > should get max height for insight widget area 1`] = `40`;
Expand Down Expand Up @@ -164,6 +170,8 @@ exports[`sizing > getDashboardLayoutWidgetMaxGridHeight > with customHeight true

exports[`sizing > getDashboardLayoutWidgetMaxGridHeight > with customHeight true > should get max height for kpi widget 1`] = `40`;

exports[`sizing > getDashboardLayoutWidgetMaxGridHeight > with customHeight true > should get max height for rich text widget 1`] = `40`;

exports[`sizing > getDashboardLayoutWidgetMaxGridHeight > with customHeight true > should get max height for unknown widget 1`] = `40`;

exports[`sizing > getDashboardLayoutWidgetMinGridHeight > with customHeight false > should get min height for insight widget area 1`] = `22.5`;
Expand Down Expand Up @@ -206,6 +214,8 @@ exports[`sizing > getDashboardLayoutWidgetMinGridHeight > with customHeight fals

exports[`sizing > getDashboardLayoutWidgetMinGridHeight > with customHeight false > should get min height for kpi without pop widget 1`] = `12`;

exports[`sizing > getDashboardLayoutWidgetMinGridHeight > with customHeight false > should get min height for rich text widget 1`] = `6`;

exports[`sizing > getDashboardLayoutWidgetMinGridHeight > with customHeight false > should get min height for unknown widget 1`] = `undefined`;

exports[`sizing > getDashboardLayoutWidgetMinGridHeight > with customHeight true > should get min height for insight widget area 1`] = `22`;
Expand Down Expand Up @@ -248,4 +258,6 @@ exports[`sizing > getDashboardLayoutWidgetMinGridHeight > with customHeight true

exports[`sizing > getDashboardLayoutWidgetMinGridHeight > with customHeight true > should get min height for kpi without pop widget 1`] = `6`;

exports[`sizing > getDashboardLayoutWidgetMinGridHeight > with customHeight true > should get min height for rich text widget 1`] = `6`;

exports[`sizing > getDashboardLayoutWidgetMinGridHeight > with customHeight true > should get min height for unknown widget 1`] = `22`;
18 changes: 17 additions & 1 deletion libs/sdk-ui-dashboard/src/_staging/layout/test/sizing.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2019-2023 GoodData Corporation
// (C) 2019-2024 GoodData Corporation
import { newKpiWidget } from "@gooddata/sdk-backend-base";
import {
getDashboardLayoutWidgetDefaultHeight,
Expand Down Expand Up @@ -67,6 +67,10 @@ describe("sizing", () => {
).toMatchSnapshot();
});

it("should get default height for rich text widget", () => {
expect(getDashboardLayoutWidgetDefaultHeight(settings, "richText")).toMatchSnapshot();
});

it("should get default height for unknown widget", () => {
expect(getDashboardLayoutWidgetDefaultHeight(settings, "unknown" as any)).toMatchSnapshot();
});
Expand Down Expand Up @@ -100,6 +104,10 @@ describe("sizing", () => {
).toMatchSnapshot();
});

it("should get min height for rich text widget", () => {
expect(getDashboardLayoutWidgetMinGridHeight(settings, "richText")).toMatchSnapshot();
});

it("should get min height for unknown widget", () => {
expect(getDashboardLayoutWidgetMinGridHeight(settings, "unknown" as any)).toMatchSnapshot();
});
Expand All @@ -125,6 +133,10 @@ describe("sizing", () => {
expect(getDashboardLayoutWidgetMaxGridHeight(settings, "kpi")).toMatchSnapshot();
});

it("should get max height for rich text widget", () => {
expect(getDashboardLayoutWidgetMaxGridHeight(settings, "richText")).toMatchSnapshot();
});

it("should get max height for unknown widget", () => {
expect(getDashboardLayoutWidgetMaxGridHeight(settings, "unknown" as any)).toMatchSnapshot();
});
Expand All @@ -144,6 +156,10 @@ describe("sizing", () => {
expect(getDashboardLayoutWidgetMinGridWidth(settings, "kpi")).toBe(2);
});

it("should get minimum width for rich text widget", () => {
expect(getDashboardLayoutWidgetMinGridWidth(settings, "richText")).toBe(2);
});

type Scenario = [string, string, VisType | undefined, number];
const scenarios: Scenario[] = [
["KPI", "kpi", undefined, 2],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2021-2022 GoodData Corporation
// (C) 2021-2024 GoodData Corporation
import { beforeEach, describe, it, expect } from "vitest";
import { DashboardTester, preloadedTesterFactory } from "../../../tests/DashboardTester.js";
import {
Expand All @@ -23,6 +23,7 @@ import {
testItemWithDateDataset,
testItemWithFilterIgnoreList,
TestKpiPlaceholderItem,
TestRichTextItem,
} from "../../../tests/fixtures/Layout.fixtures.js";
import { ActivityDateDatasetRef } from "../../../tests/fixtures/CatalogAvailability.fixtures.js";

Expand Down Expand Up @@ -81,12 +82,17 @@ describe("add layout section handler", () => {

it("should add a new section and initialize its items", async () => {
const event: DashboardLayoutSectionAdded = await Tester.dispatchAndWaitFor(
addLayoutSection(0, undefined, [TestKpiPlaceholderItem, TestInsightPlaceholderItem]),
addLayoutSection(0, undefined, [
TestKpiPlaceholderItem,
TestInsightPlaceholderItem,
TestRichTextItem,
]),
"GDC.DASH/EVT.FLUID_LAYOUT.SECTION_ADDED",
);
expect(event.payload.section.items).toMatchObject([
TestKpiPlaceholderItem,
TestInsightPlaceholderItem,
TestRichTextItem,
]);

const layout = selectLayout(Tester.state());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// (C) 2021-2024 GoodData Corporation
import { beforeEach, describe, it, expect } from "vitest";
import { DashboardTester, preloadedTesterFactory } from "../../../tests/DashboardTester.js";
import { EmptyDashboardIdentifier, TestCorrelation } from "../../../tests/fixtures/Dashboard.fixtures.js";
import {
ChangeRichTextWidgetContent,
addLayoutSection,
changeRichTextWidgetContent,
} from "../../../commands/index.js";
import { DashboardCommandFailed, DashboardRichTextWidgetContentChanged } from "../../../events/index.js";
import { selectAnalyticalWidgetByRef } from "../../../store/layout/layoutSelectors.js";
import { idRef, IRichTextWidgetDefinition } from "@gooddata/sdk-model";
import { TestRichTextItem } from "../../../tests/fixtures/Layout.fixtures.js";

describe("rich text widget", () => {
let Tester: DashboardTester;

beforeEach(async () => {
await preloadedTesterFactory(
(tester) => {
Tester = tester;
},
EmptyDashboardIdentifier,
{
backendConfig: {
useRefType: "id",
},
},
);

await Tester.dispatchAndWaitFor(
addLayoutSection(0, undefined, [TestRichTextItem]),
"GDC.DASH/EVT.FLUID_LAYOUT.SECTION_ADDED",
);
});

it("should set new rich text content", async () => {
const UpdatedContent = "# Title";

const event: DashboardRichTextWidgetContentChanged = await Tester.dispatchAndWaitFor(
changeRichTextWidgetContent(TestRichTextItem.widget!.ref, UpdatedContent),
"GDC.DASH/EVT.RICH_TEXT_WIDGET.CONTENT_CHANGED",
);

expect(event.payload.content).toEqual(UpdatedContent);
const widgetState = selectAnalyticalWidgetByRef(TestRichTextItem.widget!.ref)(
Tester.state(),
) as IRichTextWidgetDefinition;
expect(widgetState!.content).toEqual(UpdatedContent);
});

it("should fail if trying to vis properties of non-existent widget", async () => {
const UpdatedContent = "# Title";

const event: DashboardCommandFailed<ChangeRichTextWidgetContent> = await Tester.dispatchAndWaitFor(
changeRichTextWidgetContent(idRef("mising"), UpdatedContent, TestCorrelation),
"GDC.DASH/EVT.COMMAND.FAILED",
);

expect(event.payload.reason).toEqual("USER_ERROR");
expect(event.correlationId).toEqual(TestCorrelation);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2021-2022 GoodData Corporation
// (C) 2021-2024 GoodData Corporation
import {
idRef,
IInsight,
Expand All @@ -11,6 +11,8 @@ import {
IInsightWidgetDefinition,
IDashboardLayoutSectionHeader,
IDashboardLayoutItem,
IRichTextWidget,
IdentifierRef,
} from "@gooddata/sdk-model";
import { PivotTableWithRowAndColumnAttributes } from "./Insights.fixtures";
import {
Expand Down Expand Up @@ -75,6 +77,32 @@ export function createTestInsightItem(
};
}

export const TestRichTextItem: IDashboardLayoutItem<IRichTextWidget> = createTestRichTextItem(
idRef("richTextWidgetRef"),
);

export function createTestRichTextItem(ref: IdentifierRef): IDashboardLayoutItem<IRichTextWidget> {
return {
type: "IDashboardLayoutItem",
widget: {
type: "richText",
ref,
content: "",
ignoreDashboardFilters: [],
drills: [],
title: "Test Rich Text Item",
description: "",
identifier: ref.identifier,
uri: `/${ref.identifier}`,
},
size: {
xl: {
gridWidth: 6,
},
},
};
}

export function testItemWithDateDataset<
T extends IInsightWidget | IKpiWidget | IInsightWidgetDefinition | IKpiWidgetDefinition,
>(item: IDashboardLayoutItem<T>, dataset: ObjRef): IDashboardLayoutItem<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ export const EditModeDashboardRichText: React.FC<IDashboardRichTextProps> = ({ w
</div>
<div className="gd-rich-text-footer-actions">
<Button
className="gd-button-link gd-button-icon-only gd-icon-trash"
className="gd-button-link gd-button-icon-only gd-icon-trash s-rich-text-remove-button"
onClick={() => setIsConfirmDeleteDialogVisible(true)}
/>
<span className="gd-divider" />
<Button
className="gd-button-link gd-button-icon-only gd-icon-checkmark"
className="gd-button-link gd-button-icon-only gd-icon-checkmark s-rich-text-confirm-button"
onClick={(e) => {
e.stopPropagation();
dispatch(uiActions.clearWidgetSelection());
Expand All @@ -105,6 +105,7 @@ export const EditModeDashboardRichText: React.FC<IDashboardRichTextProps> = ({ w
{isConfirmDeleteDialogVisible ? (
<OverlayControllerProvider overlayController={overlayController}>
<ConfirmDialog
className="s-rich-text-remove-confirm-dialog"
onSubmit={() => dispatch(eagerRemoveSectionItemByWidgetRef(widget.ref))}
onCancel={() => setIsConfirmDeleteDialogVisible(false)}
headline={intl.formatMessage({ id: "richText.deleteDialog.header" })}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ export const RichText: React.FC<IRichTextProps> = ({
emptyElement,
}) => {
return (
<div className={cx(["gd-rich-text-content", { "gd-visible-scrollbar": !editMode }])}>
<div
className={cx([
"gd-rich-text-content",
"s-rich-text",
`s-rich-text-${editMode ? "edit" : "view"}`,
{ "gd-visible-scrollbar": !editMode },
])}
>
{editMode ? (
<RichTextEdit
text={text}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// (C) 2021-2024 GoodData Corporation

import * as Navigation from "../../tools/navigation";
import { EditMode } from "../../tools/editMode";
import { Widget } from "../../tools/widget";
import { LayoutRow } from "../../tools/layoutRow";
import { DashboardHeader } from "../../tools/dashboardHeader";
import { DashboardMenu } from "../../tools/dashboardMenu";

const editMode = new EditMode();
const widget = new Widget(1);
const addedWidget = new Widget(2);
const header = new DashboardHeader();
const layoutRow = new LayoutRow(1);
const dashboardMenu = new DashboardMenu();

describe("RichText - isolated", { tags: ["pre-merge_isolated_tiger"] }, () => {
beforeEach(() => {
Navigation.visit("dashboard/rich-text");
});

it("should render rich text in view mode", () => {
const richText = widget.getRichText();
richText.exist();

richText.getContentElement().find("h1").should("exist").should("have.text", "Title");
richText.getContentElement().find("img").should("exist").should("have.attr", "src", "/image.png");
});

it("should change rich text widget content in edit mode", () => {
editMode.edit().isInEditMode();

const richText = widget.getRichText();
richText.exist();

richText.updateContent("\n## Update");
richText.confirmChanges().isView();
richText.getContentElement().find("h2").should("exist").should("have.text", "Update");
});

it("should remove rich text widget in edit mode", () => {
editMode.edit().isInEditMode();
widget.getRichText().remove().notExist();
});
});

describe("RichText - integrated", { tags: ["checklist_integrated_tiger"] }, () => {
beforeEach(() => {
Navigation.visit("dashboard/rich-text");
});

it("should remove rich text widget and save it", () => {
editMode.edit().isInEditMode();
widget.getRichText().remove();
dashboardMenu.toggle();
header.saveAsNew("RichText With Removed Widget");
widget.getRichText().notExist();
});

it("should add rich text widget and save it", () => {
editMode.edit().isInEditMode();

layoutRow.scrollIntoView().addRichTextWidget();
const addedRichText = addedWidget.getRichText();
addedRichText.exist();
addedRichText.updateContent("# Title 2\n\n![Image2](/image2.png)").confirmChanges();

dashboardMenu.toggle();
header.saveAsNew("RichText With Added Widget");

addedRichText
.getContentElement()
.find("img")
.should("exist")
.should("have.attr", "src", "/image2.png");
addedRichText.getContentElement().find("h1").should("exist").should("have.text", "Title 2");
});
});
7 changes: 6 additions & 1 deletion libs/sdk-ui-tests-e2e/cypress/tools/layoutRow.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2021 GoodData Corporation
// (C) 2021-2024 GoodData Corporation

import { InsightsCatalog, InsightTitle } from "./insightsCatalog";
import { SectionHeader } from "./sectionHeader";
Expand Down Expand Up @@ -63,6 +63,11 @@ export class LayoutRow {
return this;
}

addRichTextWidget() {
this.dragAndDropItems(".s-add-rich-text", ".s-last-drop-position");
return this;
}

hasCountOfHeaderSection(count: number) {
cy.get(".s-fluid-layout-row-header").should("have.length", count);
return this;
Expand Down
Loading

0 comments on commit a1983a9

Please sign in to comment.