-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk-ui-dashboard): rich text widget tests
Add basic tests for rich text widget. JIRA: F1-9
- Loading branch information
Showing
18 changed files
with
560 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...hboard/src/model/commandHandlers/widgets/tests/changeRichTextWidgetContentHandler.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
libs/sdk-ui-tests-e2e/cypress/integration/01-sdk-ui-dashboard/dashboardRichText.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.