@khanacademy/wonder-blocks-cell 3.4.4 → 3.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.ts +1 -0
- package/package.json +6 -6
- package/src/components/__tests__/compact-cell.test.tsx +0 -106
- package/src/components/__tests__/detail-cell.test.tsx +0 -102
- package/src/components/compact-cell.tsx +0 -43
- package/src/components/detail-cell.tsx +0 -106
- package/src/components/internal/__tests__/cell-core.test.tsx +0 -216
- package/src/components/internal/__tests__/common.test.ts +0 -45
- package/src/components/internal/cell-core.tsx +0 -356
- package/src/components/internal/common.ts +0 -74
- package/src/index.ts +0 -4
- package/src/util/types.ts +0 -156
- package/tsconfig-build.json +0 -16
- package/tsconfig-build.tsbuildinfo +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-cell
|
|
2
2
|
|
|
3
|
+
## 3.4.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 02a1b298: Make sure we don't package tsconfig and tsbuildinfo files
|
|
8
|
+
- Updated dependencies [02a1b298]
|
|
9
|
+
- @khanacademy/wonder-blocks-clickable@4.2.8
|
|
10
|
+
- @khanacademy/wonder-blocks-core@7.0.1
|
|
11
|
+
- @khanacademy/wonder-blocks-layout@2.2.1
|
|
12
|
+
- @khanacademy/wonder-blocks-tokens@2.0.1
|
|
13
|
+
- @khanacademy/wonder-blocks-typography@2.1.16
|
|
14
|
+
|
|
3
15
|
## 3.4.4
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-cell",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.5",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/runtime": "^7.18.6",
|
|
17
|
-
"@khanacademy/wonder-blocks-clickable": "^4.2.
|
|
18
|
-
"@khanacademy/wonder-blocks-core": "^7.0.
|
|
19
|
-
"@khanacademy/wonder-blocks-layout": "^2.2.
|
|
20
|
-
"@khanacademy/wonder-blocks-tokens": "^2.0.
|
|
21
|
-
"@khanacademy/wonder-blocks-typography": "^2.1.
|
|
17
|
+
"@khanacademy/wonder-blocks-clickable": "^4.2.8",
|
|
18
|
+
"@khanacademy/wonder-blocks-core": "^7.0.1",
|
|
19
|
+
"@khanacademy/wonder-blocks-layout": "^2.2.1",
|
|
20
|
+
"@khanacademy/wonder-blocks-tokens": "^2.0.1",
|
|
21
|
+
"@khanacademy/wonder-blocks-typography": "^2.1.16"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"aphrodite": "^1.2.5",
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {render, screen} from "@testing-library/react";
|
|
3
|
-
|
|
4
|
-
import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon";
|
|
5
|
-
import {HeadingMedium} from "@khanacademy/wonder-blocks-typography";
|
|
6
|
-
import caretRightIcon from "@phosphor-icons/core/regular/caret-right.svg";
|
|
7
|
-
|
|
8
|
-
import CompactCell from "../compact-cell";
|
|
9
|
-
|
|
10
|
-
describe("CompactCell", () => {
|
|
11
|
-
it("should render the default CompactCell component", () => {
|
|
12
|
-
// Arrange
|
|
13
|
-
|
|
14
|
-
// Act
|
|
15
|
-
render(<CompactCell title="Compact cell" />);
|
|
16
|
-
|
|
17
|
-
// Assert
|
|
18
|
-
expect(screen.getByText("Compact cell")).toBeInTheDocument();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("should render the title using a Typography element", () => {
|
|
22
|
-
// Arrange
|
|
23
|
-
|
|
24
|
-
// Act
|
|
25
|
-
render(
|
|
26
|
-
<CompactCell title={<HeadingMedium>Compact cell</HeadingMedium>} />,
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
// Assert
|
|
30
|
-
expect(
|
|
31
|
-
screen.getByRole("heading", {name: "Compact cell"}),
|
|
32
|
-
).toBeInTheDocument();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("should render the leftAccessory", () => {
|
|
36
|
-
// Arrange
|
|
37
|
-
|
|
38
|
-
// Act
|
|
39
|
-
render(
|
|
40
|
-
<CompactCell
|
|
41
|
-
title="Compact cell"
|
|
42
|
-
leftAccessory={
|
|
43
|
-
<PhosphorIcon
|
|
44
|
-
icon={caretRightIcon}
|
|
45
|
-
aria-label="Caret icon"
|
|
46
|
-
/>
|
|
47
|
-
}
|
|
48
|
-
/>,
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
// Assert
|
|
52
|
-
expect(screen.getByLabelText("Caret icon")).toBeInTheDocument();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("should render the rightAccessory", () => {
|
|
56
|
-
// Arrange
|
|
57
|
-
|
|
58
|
-
// Act
|
|
59
|
-
render(
|
|
60
|
-
<CompactCell
|
|
61
|
-
title="Compact cell"
|
|
62
|
-
rightAccessory={
|
|
63
|
-
<PhosphorIcon
|
|
64
|
-
icon={caretRightIcon}
|
|
65
|
-
aria-label="Caret icon"
|
|
66
|
-
/>
|
|
67
|
-
}
|
|
68
|
-
/>,
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
// Assert
|
|
72
|
-
expect(screen.getByLabelText("Caret icon")).toBeInTheDocument();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("should add testId to the content wrapper", () => {
|
|
76
|
-
// Arrange
|
|
77
|
-
|
|
78
|
-
// Act
|
|
79
|
-
render(<CompactCell title="Compact cell" testId="cellId" />);
|
|
80
|
-
|
|
81
|
-
// Assert
|
|
82
|
-
expect(screen.getByTestId("cellId")).toHaveTextContent("Compact cell");
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("should add a button if onClick is set", () => {
|
|
86
|
-
// Arrange
|
|
87
|
-
|
|
88
|
-
// Act
|
|
89
|
-
render(<CompactCell title="Compact cell" onClick={jest.fn()} />);
|
|
90
|
-
|
|
91
|
-
// Assert
|
|
92
|
-
expect(screen.getByRole("button")).toBeInTheDocument();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("should allow clicking the cell if onClick is set", () => {
|
|
96
|
-
// Arrange
|
|
97
|
-
const onClickMock = jest.fn();
|
|
98
|
-
render(<CompactCell title="Compact cell" onClick={onClickMock} />);
|
|
99
|
-
|
|
100
|
-
// Act
|
|
101
|
-
screen.getByRole("button").click();
|
|
102
|
-
|
|
103
|
-
// Assert
|
|
104
|
-
expect(onClickMock).toHaveBeenCalled();
|
|
105
|
-
});
|
|
106
|
-
});
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {render, screen} from "@testing-library/react";
|
|
3
|
-
|
|
4
|
-
import {HeadingMedium} from "@khanacademy/wonder-blocks-typography";
|
|
5
|
-
|
|
6
|
-
import DetailCell from "../detail-cell";
|
|
7
|
-
|
|
8
|
-
describe("DetailCell", () => {
|
|
9
|
-
it("should render the default DetailCell component", () => {
|
|
10
|
-
// Arrange
|
|
11
|
-
|
|
12
|
-
// Act
|
|
13
|
-
render(<DetailCell title="Detail cell" />);
|
|
14
|
-
|
|
15
|
-
// Assert
|
|
16
|
-
expect(screen.getByText("Detail cell")).toBeInTheDocument();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("should render the title using a Typography element", () => {
|
|
20
|
-
// Arrange
|
|
21
|
-
|
|
22
|
-
// Act
|
|
23
|
-
render(
|
|
24
|
-
<DetailCell
|
|
25
|
-
title={<HeadingMedium>Detail cell title</HeadingMedium>}
|
|
26
|
-
/>,
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
// Assert
|
|
30
|
-
expect(
|
|
31
|
-
screen.getByRole("heading", {name: "Detail cell title"}),
|
|
32
|
-
).toBeInTheDocument();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("should render the subtitle1 using a plain text", () => {
|
|
36
|
-
// Arrange
|
|
37
|
-
|
|
38
|
-
// Act
|
|
39
|
-
render(
|
|
40
|
-
<DetailCell
|
|
41
|
-
title="Detail cell"
|
|
42
|
-
subtitle1="Detail cell subtitle 1"
|
|
43
|
-
/>,
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
// Assert
|
|
47
|
-
expect(screen.getByText("Detail cell subtitle 1")).toBeInTheDocument();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("should render the subtitle1 using a Typography element", () => {
|
|
51
|
-
// Arrange
|
|
52
|
-
|
|
53
|
-
// Act
|
|
54
|
-
render(
|
|
55
|
-
<DetailCell
|
|
56
|
-
title="Detail cell"
|
|
57
|
-
subtitle1={
|
|
58
|
-
<HeadingMedium>Detail cell subtitle 1</HeadingMedium>
|
|
59
|
-
}
|
|
60
|
-
/>,
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
// Assert
|
|
64
|
-
expect(
|
|
65
|
-
screen.getByRole("heading", {name: "Detail cell subtitle 1"}),
|
|
66
|
-
).toBeInTheDocument();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("should render the subtitle2 using a plain text", () => {
|
|
70
|
-
// Arrange
|
|
71
|
-
|
|
72
|
-
// Act
|
|
73
|
-
render(
|
|
74
|
-
<DetailCell
|
|
75
|
-
title="Detail cell"
|
|
76
|
-
subtitle2="Detail cell subtitle 2"
|
|
77
|
-
/>,
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
// Assert
|
|
81
|
-
expect(screen.getByText("Detail cell subtitle 2")).toBeInTheDocument();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("should render the subtitle2 using a Typography element", () => {
|
|
85
|
-
// Arrange
|
|
86
|
-
|
|
87
|
-
// Act
|
|
88
|
-
render(
|
|
89
|
-
<DetailCell
|
|
90
|
-
title="Detail cell"
|
|
91
|
-
subtitle2={
|
|
92
|
-
<HeadingMedium>Detail cell subtitle 2</HeadingMedium>
|
|
93
|
-
}
|
|
94
|
-
/>,
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
// Assert
|
|
98
|
-
expect(
|
|
99
|
-
screen.getByRole("heading", {name: "Detail cell subtitle 2"}),
|
|
100
|
-
).toBeInTheDocument();
|
|
101
|
-
});
|
|
102
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
import {LabelMedium} from "@khanacademy/wonder-blocks-typography";
|
|
4
|
-
|
|
5
|
-
import CellCore from "./internal/cell-core";
|
|
6
|
-
|
|
7
|
-
import type {CellProps} from "../util/types";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* `CompactCell` is the simplest form of the Cell. It is a compacted-height Cell
|
|
11
|
-
* with limited subviews and accessories. Typically they represent additional
|
|
12
|
-
* info or selection lists. It has a minimum height of 48px and a non-bold
|
|
13
|
-
* title. It does not have subtitles or a progress bar, and in general it has
|
|
14
|
-
* less vertical space around text and accessories.
|
|
15
|
-
*
|
|
16
|
-
* ### Usage
|
|
17
|
-
*
|
|
18
|
-
* ```jsx
|
|
19
|
-
* import {CompactCell} from "@khanacademy/wonder-blocks-cell";
|
|
20
|
-
* import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon";
|
|
21
|
-
* import caretRightIcon from "@phosphor-icons/core/regular/caret-right.svg";
|
|
22
|
-
*
|
|
23
|
-
* <CompactCell
|
|
24
|
-
* title="Compact cell"
|
|
25
|
-
* rightAccessory={<PhosphorIcon icon={caretRightIcon} size="medium" />}
|
|
26
|
-
* />
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
const CompactCell = function (props: CellProps): React.ReactElement {
|
|
30
|
-
const {title, ...coreProps} = props;
|
|
31
|
-
|
|
32
|
-
return (
|
|
33
|
-
<CellCore {...coreProps}>
|
|
34
|
-
{typeof title === "string" ? (
|
|
35
|
-
<LabelMedium>{title}</LabelMedium>
|
|
36
|
-
) : (
|
|
37
|
-
title
|
|
38
|
-
)}
|
|
39
|
-
</CellCore>
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export default CompactCell;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {StyleSheet} from "aphrodite";
|
|
3
|
-
|
|
4
|
-
import {Strut} from "@khanacademy/wonder-blocks-layout";
|
|
5
|
-
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
|
|
6
|
-
import {LabelSmall, LabelMedium} from "@khanacademy/wonder-blocks-typography";
|
|
7
|
-
|
|
8
|
-
import CellCore from "./internal/cell-core";
|
|
9
|
-
import {CellMeasurements} from "./internal/common";
|
|
10
|
-
|
|
11
|
-
import type {CellProps, TypographyText} from "../util/types";
|
|
12
|
-
|
|
13
|
-
type SubtitleProps = {
|
|
14
|
-
subtitle?: TypographyText;
|
|
15
|
-
/**
|
|
16
|
-
* If true, the subtitle will use the alpha color defined in the parent
|
|
17
|
-
* component/element.
|
|
18
|
-
*/
|
|
19
|
-
disabled?: boolean;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const Subtitle = ({subtitle, disabled}: SubtitleProps): React.ReactElement => {
|
|
23
|
-
if (!subtitle) {
|
|
24
|
-
// @ts-expect-error [FEI-5019] - TS2322 - Type 'null' is not assignable to type 'ReactElement<any, string | JSXElementConstructor<any>>'.
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (typeof subtitle === "string") {
|
|
29
|
-
return (
|
|
30
|
-
<LabelSmall style={!disabled && styles.subtitle}>
|
|
31
|
-
{subtitle}
|
|
32
|
-
</LabelSmall>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return subtitle;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
type DetailCellProps = CellProps & {
|
|
40
|
-
/**
|
|
41
|
-
* You can either provide a string or a custom node Typography element (or
|
|
42
|
-
* nothing at all). Both a string or a custom node Typography element will
|
|
43
|
-
* occupy the “Subtitle1” area of the Cell.
|
|
44
|
-
*/
|
|
45
|
-
subtitle1?: TypographyText;
|
|
46
|
-
/**
|
|
47
|
-
* You can either provide a string or a custom node Typography element (or
|
|
48
|
-
* nothing at all). Both a string or a custom node Typography element will
|
|
49
|
-
* occupy the “Subtitle2” area of the Cell.
|
|
50
|
-
*/
|
|
51
|
-
subtitle2?: TypographyText;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* This is a variant of CompactCell that allows adding subtitles, before and
|
|
56
|
-
* after the cell title. They typically represent an item that can be
|
|
57
|
-
* clicked/tapped to view more complex details. They vary in height depending on
|
|
58
|
-
* the presence or absence of subtitles, and they allow for a wide range of
|
|
59
|
-
* functionality depending on which accessories are active.
|
|
60
|
-
*
|
|
61
|
-
* ### Usage
|
|
62
|
-
*
|
|
63
|
-
* ```jsx
|
|
64
|
-
* import {DetailCell} from "@khanacademy/wonder-blocks-cell";
|
|
65
|
-
* import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon";
|
|
66
|
-
*
|
|
67
|
-
* <DetailCell
|
|
68
|
-
* leftAccessory={<PhosphorIcon icon={contentVideo} size="medium" />}
|
|
69
|
-
* subtitle1="Subtitle 1"
|
|
70
|
-
* title="Detail cell"
|
|
71
|
-
* subtitle1="Subtitle 2"
|
|
72
|
-
* rightAccessory={<PhosphorIcon icon={caretRight} size="medium" />}
|
|
73
|
-
* />
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
const DetailCell = function (props: DetailCellProps): React.ReactElement {
|
|
77
|
-
const {title, subtitle1, subtitle2, ...coreProps} = props;
|
|
78
|
-
|
|
79
|
-
return (
|
|
80
|
-
<CellCore {...coreProps} innerStyle={styles.innerWrapper}>
|
|
81
|
-
<Subtitle subtitle={subtitle1} disabled={coreProps.disabled} />
|
|
82
|
-
{subtitle1 && <Strut size={spacing.xxxxSmall_2} />}
|
|
83
|
-
{typeof title === "string" ? (
|
|
84
|
-
<LabelMedium>{title}</LabelMedium>
|
|
85
|
-
) : (
|
|
86
|
-
title
|
|
87
|
-
)}
|
|
88
|
-
{/* Add a vertical spacing between the title and the subtitle */}
|
|
89
|
-
{subtitle2 && <Strut size={spacing.xxxxSmall_2} />}
|
|
90
|
-
<Subtitle subtitle={subtitle2} disabled={coreProps.disabled} />
|
|
91
|
-
</CellCore>
|
|
92
|
-
);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const styles = StyleSheet.create({
|
|
96
|
-
subtitle: {
|
|
97
|
-
color: color.offBlack64,
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
// This is to override the default padding of the CellCore innerWrapper.
|
|
101
|
-
innerWrapper: {
|
|
102
|
-
padding: `${CellMeasurements.detailCellPadding.paddingVertical}px ${CellMeasurements.detailCellPadding.paddingHorizontal}px`,
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
export default DetailCell;
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {render, screen} from "@testing-library/react";
|
|
3
|
-
|
|
4
|
-
import CellCore from "../cell-core";
|
|
5
|
-
|
|
6
|
-
describe("CellCore", () => {
|
|
7
|
-
it("should render the CellCore component", () => {
|
|
8
|
-
// Arrange
|
|
9
|
-
|
|
10
|
-
// Act
|
|
11
|
-
render(
|
|
12
|
-
<CellCore>
|
|
13
|
-
<div>cell core content</div>
|
|
14
|
-
</CellCore>,
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
// Assert
|
|
18
|
-
expect(screen.getByText("cell core content")).toBeInTheDocument();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("should NOT add a button by default", () => {
|
|
22
|
-
// Arrange
|
|
23
|
-
|
|
24
|
-
// Act
|
|
25
|
-
render(
|
|
26
|
-
<CellCore>
|
|
27
|
-
<div>cell core content</div>
|
|
28
|
-
</CellCore>,
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
// Assert
|
|
32
|
-
expect(screen.queryByRole("button")).not.toBeInTheDocument();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("should add a button if onClick is set", () => {
|
|
36
|
-
// Arrange
|
|
37
|
-
|
|
38
|
-
// Act
|
|
39
|
-
render(
|
|
40
|
-
<CellCore onClick={jest.fn()}>
|
|
41
|
-
<div>cell core content</div>
|
|
42
|
-
</CellCore>,
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
// Assert
|
|
46
|
-
expect(screen.getByRole("button")).toBeInTheDocument();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("should add an anchor if href is set", () => {
|
|
50
|
-
// Arrange
|
|
51
|
-
|
|
52
|
-
// Act
|
|
53
|
-
render(
|
|
54
|
-
<CellCore href="/math">
|
|
55
|
-
<div>cell core content</div>
|
|
56
|
-
</CellCore>,
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
// Assert
|
|
60
|
-
expect(screen.getByRole("link")).toHaveAttribute("href", "/math");
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("should add aria-label to the button", () => {
|
|
64
|
-
// Arrange
|
|
65
|
-
|
|
66
|
-
// Act
|
|
67
|
-
render(
|
|
68
|
-
<CellCore onClick={jest.fn()} aria-label="some description">
|
|
69
|
-
<div>cell core content</div>
|
|
70
|
-
</CellCore>,
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
// Assert
|
|
74
|
-
expect(
|
|
75
|
-
screen.getByRole("button", {name: "some description"}),
|
|
76
|
-
).toBeInTheDocument();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("should add aria-disabled if disabled is set", () => {
|
|
80
|
-
// Arrange
|
|
81
|
-
|
|
82
|
-
// Act
|
|
83
|
-
render(
|
|
84
|
-
<CellCore onClick={jest.fn()} disabled={true}>
|
|
85
|
-
<div>cell core content</div>
|
|
86
|
-
</CellCore>,
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
// Assert
|
|
90
|
-
expect(screen.getByRole("button")).toHaveAttribute(
|
|
91
|
-
"aria-disabled",
|
|
92
|
-
"true",
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("should add aria-current if active is set", () => {
|
|
97
|
-
// Arrange
|
|
98
|
-
|
|
99
|
-
// Act
|
|
100
|
-
const {container} = render(
|
|
101
|
-
<CellCore active={true}>
|
|
102
|
-
<div>cell core content</div>
|
|
103
|
-
</CellCore>,
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
// Assert
|
|
107
|
-
// Verify that the root element has the aria-current attribute
|
|
108
|
-
// eslint-disable-next-line testing-library/no-node-access
|
|
109
|
-
expect(container.firstChild).toHaveAttribute("aria-current", "true");
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("should allow passing a role", () => {
|
|
113
|
-
// Arrange
|
|
114
|
-
|
|
115
|
-
// Act
|
|
116
|
-
render(
|
|
117
|
-
<CellCore onClick={jest.fn()} role="menuitem">
|
|
118
|
-
<div>cell core content</div>
|
|
119
|
-
</CellCore>,
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
// Assert
|
|
123
|
-
expect(
|
|
124
|
-
screen.getByRole("menuitem", {name: "cell core content"}),
|
|
125
|
-
).toBeInTheDocument();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it("should pass an style to the top node", () => {
|
|
129
|
-
// Arrange
|
|
130
|
-
|
|
131
|
-
// Act
|
|
132
|
-
render(
|
|
133
|
-
<CellCore onClick={jest.fn()} rootStyle={{color: "blue"}}>
|
|
134
|
-
<div>cell core content</div>
|
|
135
|
-
</CellCore>,
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
// Assert
|
|
139
|
-
expect(screen.getByRole("button")).toHaveStyle("color: blue");
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("should pass an style to the content container", () => {
|
|
143
|
-
// Arrange
|
|
144
|
-
|
|
145
|
-
// Act
|
|
146
|
-
render(
|
|
147
|
-
<CellCore
|
|
148
|
-
onClick={jest.fn()}
|
|
149
|
-
contentStyle={{alignSelf: "flex-start"}}
|
|
150
|
-
>
|
|
151
|
-
<div>cell core content</div>
|
|
152
|
-
</CellCore>,
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
// Assert
|
|
156
|
-
const elem = screen.getByText("cell core content");
|
|
157
|
-
// eslint-disable-next-line testing-library/no-node-access
|
|
158
|
-
expect(elem.parentElement).toHaveStyle("align-self: flex-start");
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe("aria-checked", () => {
|
|
162
|
-
it("should add aria-checked if aria-checked is set and it is a link", () => {
|
|
163
|
-
// Arrange
|
|
164
|
-
|
|
165
|
-
// Act
|
|
166
|
-
const {container} = render(
|
|
167
|
-
<CellCore aria-checked={true} href="#">
|
|
168
|
-
<div>cell core content</div>
|
|
169
|
-
</CellCore>,
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
// Assert
|
|
173
|
-
// Verify that the root element has the aria-current attribute
|
|
174
|
-
// eslint-disable-next-line testing-library/no-node-access
|
|
175
|
-
expect(container.firstChild).toHaveAttribute(
|
|
176
|
-
"aria-checked",
|
|
177
|
-
"true",
|
|
178
|
-
);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("should add aria-checked if aria-checked is set and it has an onClick handler", () => {
|
|
182
|
-
// Arrange
|
|
183
|
-
|
|
184
|
-
// Act
|
|
185
|
-
const {container} = render(
|
|
186
|
-
<CellCore aria-checked={true} onClick={jest.fn()}>
|
|
187
|
-
<div>cell core content</div>
|
|
188
|
-
</CellCore>,
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
// Assert
|
|
192
|
-
// Verify that the root element has the aria-current attribute
|
|
193
|
-
// eslint-disable-next-line testing-library/no-node-access
|
|
194
|
-
expect(container.firstChild).toHaveAttribute(
|
|
195
|
-
"aria-checked",
|
|
196
|
-
"true",
|
|
197
|
-
);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it("should not add aria-checked if it is not clickable", () => {
|
|
201
|
-
// Arrange
|
|
202
|
-
|
|
203
|
-
// Act
|
|
204
|
-
const {container} = render(
|
|
205
|
-
<CellCore aria-checked={true}>
|
|
206
|
-
<div>cell core content</div>
|
|
207
|
-
</CellCore>,
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
// Assert
|
|
211
|
-
// Verify that the root element has the aria-current attribute
|
|
212
|
-
// eslint-disable-next-line testing-library/no-node-access
|
|
213
|
-
expect(container.firstChild).not.toHaveAttribute("aria-checked");
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {getHorizontalRuleStyles} from "../common";
|
|
2
|
-
|
|
3
|
-
describe("getHorizontalRuleStyles", () => {
|
|
4
|
-
it("should get 'inset' styles as an array", () => {
|
|
5
|
-
// Arrange
|
|
6
|
-
|
|
7
|
-
// Act
|
|
8
|
-
const styles = getHorizontalRuleStyles("inset");
|
|
9
|
-
|
|
10
|
-
// Assert
|
|
11
|
-
// Verify that both classes are injected
|
|
12
|
-
expect(styles).toMatchObject([
|
|
13
|
-
{
|
|
14
|
-
_name: /horizontalRule/,
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
_name: /horizontalRuleInset/,
|
|
18
|
-
},
|
|
19
|
-
]);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("should get 'full-width' styles as an object", () => {
|
|
23
|
-
// Arrange
|
|
24
|
-
|
|
25
|
-
// Act
|
|
26
|
-
const styles = getHorizontalRuleStyles("full-width");
|
|
27
|
-
|
|
28
|
-
// Assert
|
|
29
|
-
// Verify that only one class is injected
|
|
30
|
-
expect(styles).toMatchObject({
|
|
31
|
-
_name: /horizontalRule/,
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("should not inject styles with 'none'", () => {
|
|
36
|
-
// Arrange
|
|
37
|
-
|
|
38
|
-
// Act
|
|
39
|
-
const styles = getHorizontalRuleStyles("none");
|
|
40
|
-
|
|
41
|
-
// Assert
|
|
42
|
-
// Verify that we don't inject any styles
|
|
43
|
-
expect(styles).toMatchObject({});
|
|
44
|
-
});
|
|
45
|
-
});
|