Skip to content

Commit

Permalink
feat(text-editor): add support for new validation designs
Browse files Browse the repository at this point in the history
  • Loading branch information
edleeks87 committed Oct 17, 2023
1 parent 3e690ad commit 91bb986
Show file tree
Hide file tree
Showing 15 changed files with 387 additions and 298 deletions.
12 changes: 10 additions & 2 deletions cypress/components/text-editor/text-editor.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
TextEditorCustomValidation,
} from "../../../src/components/text-editor/text-editor-test.stories";

import { WithNewValidation as TextEditorNewValidation } from "../../../src/components/text-editor/text-editor.stories";

import {
textEditorInput,
textEditorCounter,
Expand Down Expand Up @@ -45,7 +47,7 @@ context("Test for TextEditor component", () => {
CypressMountWithProviders(<TextEditorCustom />);

textEditorInput().clear().type(textForInput);
textEditorCounter().should("have.text", 2982);
textEditorCounter().should("have.text", "2,982 characters left");
});

it.each(["bold", "italic"])(
Expand Down Expand Up @@ -200,7 +202,7 @@ context("Test for TextEditor component", () => {

textEditorInput().clear().type(longText);

textEditorCounter().should("have.text", 0);
textEditorCounter().should("have.text", "0 characters left");
innerText().should("have.text", longTextAssert);
});

Expand Down Expand Up @@ -443,5 +445,11 @@ context("Test for TextEditor component", () => {
cy.checkAccessibility();
}
);

it("should pass accessibility tests for TextEditor validation when opt in flag is set", () => {
CypressMountWithProviders(<TextEditorNewValidation />);

cy.checkAccessibility();
});
});
});
5 changes: 2 additions & 3 deletions cypress/locators/text-editor/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { LINK } from "../locators";
import { CHARACTER_COUNT, LINK } from "../locators";
import {
TEXT_EDITOR_CONTAINER,
TEXT_EDITOR_COUNTER,
TEXT_EDITOR_INPUT,
TEXT_EDITOR_TOOLBAR,
} from "./locators";

// component preview locators
export const textEditorCounter = () => cy.get(TEXT_EDITOR_COUNTER);
export const textEditorCounter = () => cy.get(CHARACTER_COUNT);
export const textEditorInput = () => cy.get(TEXT_EDITOR_INPUT);
export const textEditorToolbar = (buttonType) =>
cy
Expand Down
1 change: 0 additions & 1 deletion cypress/locators/text-editor/locators.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// component preview locators
export const TEXT_EDITOR_COUNTER = '[data-component="text-editor-counter"]';
export const TEXT_EDITOR_INPUT = '[role="textbox"]';
export const TEXT_EDITOR_TOOLBAR = '[data-component="text-editor-toolbar"]';
export const TEXT_EDITOR_CONTAINER = '[data-component="text-editor-container"]';

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";

import StyledValidationWrapper from "./editor-validation-wrapper.style";
import ValidationIcon from "../../../../__internal__/validations";

export interface EditorValidationWrapperProps {
/** Message to be displayed when there is an error */
error?: string;
/** Message to be displayed when there is a warning */
warning?: string;
/** Message to be displayed when there is an info */
info?: string;
}

const ValidationWrapper = ({
error,
warning,
info,
}: EditorValidationWrapperProps) => (
<StyledValidationWrapper data-component="text-editor-validation-wrapper">
<ValidationIcon
error={error}
warning={warning}
info={info}
tooltipPosition="top"
tabIndex={0}
/>
</StyledValidationWrapper>
);

export default ValidationWrapper;
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from "react";
import { mount } from "enzyme";
import { assertStyleMatch } from "../../../../__spec_helper__/test-utils";
import ValidationWrapper, {
EditorValidationWrapperProps,
} from "./editor-validation-wrapper.component";
import ValidationIcon from "../../../../__internal__/validations";

const render = (props: EditorValidationWrapperProps = {}, renderer = mount) => {
return renderer(<ValidationWrapper {...props} />);
};

describe("EditorValidationWrapper", () => {
it("has the expected styles", () => {
const wrapper = render();
assertStyleMatch(
{
margin:
"var(--spacing200) var(--spacing200) var(--spacing000) var(--spacing050)",
minWidth: "var(--sizing500)",
height: "var(--sizing275)",
float: "right",
alignItems: "center",
},
wrapper
);
});

describe("with validation", () => {
it.each([
{ error: "error" },
{ warning: "warning" },
{ info: "info" },
] as const)("renders the icon when a message is provided", (msg) => {
expect(
render({ ...msg })
.find(ValidationIcon)
.exists()
).toEqual(true);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import styled from "styled-components";

const StyledValidationWrapper = styled.div`
margin: var(--spacing200) var(--spacing200) var(--spacing000)
var(--spacing050);
min-width: var(--sizing500);
height: var(--sizing275);
display: flex;
float: right;
align-items: center;
`;

export default StyledValidationWrapper;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from "./editor-validation-wrapper.component";
export type { EditorValidationWrapperProps } from "./editor-validation-wrapper.component";
Loading

0 comments on commit 91bb986

Please sign in to comment.