@dotcms/react 0.0.1-alpha.11 → 0.0.1-alpha.12
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/index.esm.d.ts +1 -0
- package/index.esm.js +1928 -0
- package/package.json +30 -27
- package/src/lib/components/Column/Column.d.ts +5 -0
- package/src/lib/components/Container/Container.d.ts +5 -0
- package/src/lib/components/DotcmsLayout/{DotcmsLayout.tsx → DotcmsLayout.d.ts} +3 -17
- package/src/lib/components/PageProvider/{PageProvider.tsx → PageProvider.d.ts} +1 -12
- package/src/lib/components/Row/Row.d.ts +25 -0
- package/src/lib/contexts/PageContext.d.ts +3 -0
- package/src/lib/hooks/useDotcmsEditor.d.ts +2 -0
- package/src/lib/hooks/{useDotcmsPageContext.tsx → useDotcmsPageContext.d.ts} +1 -7
- package/src/lib/mocks/mockPageContext.d.ts +7 -0
- package/src/lib/utils/utils.d.ts +22 -0
- package/.babelrc +0 -12
- package/.eslintrc.json +0 -18
- package/jest.config.ts +0 -11
- package/project.json +0 -51
- package/src/lib/components/Column/Column.module.css +0 -99
- package/src/lib/components/Column/Column.spec.tsx +0 -78
- package/src/lib/components/Column/Column.tsx +0 -45
- package/src/lib/components/Container/Container.module.css +0 -7
- package/src/lib/components/Container/Container.spec.tsx +0 -82
- package/src/lib/components/Container/Container.tsx +0 -106
- package/src/lib/components/DotcmsLayout/DotcmsLayout.module.css +0 -7
- package/src/lib/components/DotcmsLayout/DotcmsLayout.spec.tsx +0 -41
- package/src/lib/components/PageProvider/PageProvider.module.css +0 -7
- package/src/lib/components/PageProvider/PageProvider.spec.tsx +0 -54
- package/src/lib/components/Row/Row.module.css +0 -5
- package/src/lib/components/Row/Row.spec.tsx +0 -92
- package/src/lib/components/Row/Row.tsx +0 -51
- package/src/lib/contexts/PageContext.tsx +0 -5
- package/src/lib/hooks/useDotcmsEditor.spec.ts +0 -56
- package/src/lib/hooks/useDotcmsEditor.ts +0 -29
- package/src/lib/hooks/useDotcmsPageContext.spec.tsx +0 -43
- package/src/lib/mocks/mockPageContext.tsx +0 -84
- package/src/lib/utils/utils.ts +0 -69
- package/tsconfig.json +0 -20
- package/tsconfig.lib.json +0 -23
- package/tsconfig.spec.json +0 -20
- /package/src/{index.ts → index.d.ts} +0 -0
- /package/src/lib/mocks/{index.ts → index.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
2
|
+
"name": "@dotcms/react",
|
|
3
|
+
"version": "0.0.1-alpha.12",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"react": ">=18",
|
|
6
|
+
"react-dom": ">=18",
|
|
7
|
+
"@dotcms/client": "0.0.1-alpha.12"
|
|
8
|
+
},
|
|
9
|
+
"description": "Official React Components library to render a dotCMS page.",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/dotCMS/core.git#master"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"dotCMS",
|
|
16
|
+
"CMS",
|
|
17
|
+
"Content Management",
|
|
18
|
+
"API Client",
|
|
19
|
+
"REST API",
|
|
20
|
+
"React",
|
|
21
|
+
"Components"
|
|
22
|
+
],
|
|
23
|
+
"author": "dotcms <dev@dotcms.com>",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/dotCMS/core/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/dotCMS/core/tree/master/core-web/libs/sdk/react/README.md",
|
|
29
|
+
"module": "./index.esm.js",
|
|
30
|
+
"type": "module",
|
|
31
|
+
"main": "./index.esm.js"
|
|
29
32
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PageProviderContext } from '../PageProvider/PageProvider';
|
|
2
|
+
export interface ColumnProps {
|
|
3
|
+
readonly column: PageProviderContext['layout']['body']['rows'][0]['columns'][0];
|
|
4
|
+
}
|
|
5
|
+
export declare function Column({ column }: ColumnProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PageProviderContext } from '../PageProvider/PageProvider';
|
|
2
|
+
export interface ContainerProps {
|
|
3
|
+
readonly containerRef: PageProviderContext['layout']['body']['rows'][0]['columns'][0]['containers'][0];
|
|
4
|
+
}
|
|
5
|
+
export declare function Container({ containerRef }: ContainerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { DotCMSPageEditorConfig } from '@dotcms/client';
|
|
2
|
-
|
|
3
|
-
import { useDotcmsEditor } from '../../hooks/useDotcmsEditor';
|
|
4
|
-
import { PageProvider, PageProviderContext } from '../PageProvider/PageProvider';
|
|
5
|
-
import { Row } from '../Row/Row';
|
|
3
|
+
import { PageProviderContext } from '../PageProvider/PageProvider';
|
|
6
4
|
/**
|
|
7
5
|
* `DotcmsPageProps` is a type that defines the properties for the `DotcmsLayout` component.
|
|
8
6
|
* It includes a readonly `entity` property that represents the context for a DotCMS page.
|
|
@@ -23,10 +21,8 @@ export type DotcmsPageProps = {
|
|
|
23
21
|
* @readonly
|
|
24
22
|
*/
|
|
25
23
|
readonly entity: PageProviderContext;
|
|
26
|
-
|
|
27
24
|
readonly config?: DotCMSPageEditorConfig;
|
|
28
25
|
};
|
|
29
|
-
|
|
30
26
|
/**
|
|
31
27
|
* `DotcmsLayout` is a functional component that renders a layout for a DotCMS page.
|
|
32
28
|
* It takes a `DotcmsPageProps` object as a parameter and returns a JSX element.
|
|
@@ -35,14 +31,4 @@ export type DotcmsPageProps = {
|
|
|
35
31
|
* @param {DotcmsPageProps} props - The properties for the DotCMS page.
|
|
36
32
|
* @returns {JSX.Element} - A JSX element that represents the layout for a DotCMS page.
|
|
37
33
|
*/
|
|
38
|
-
export function DotcmsLayout({ entity, config }: DotcmsPageProps): JSX.Element
|
|
39
|
-
const isInsideEditor = useDotcmsEditor(config);
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<PageProvider entity={{ ...entity, isInsideEditor }}>
|
|
43
|
-
{entity.layout.body.rows.map((row, index) => (
|
|
44
|
-
<Row key={index} row={row} />
|
|
45
|
-
))}
|
|
46
|
-
</PageProvider>
|
|
47
|
-
);
|
|
48
|
-
}
|
|
34
|
+
export declare function DotcmsLayout({ entity, config }: DotcmsPageProps): JSX.Element;
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
import { PageContext } from '../../contexts/PageContext';
|
|
4
|
-
|
|
5
2
|
export interface PageProviderProps {
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
3
|
readonly entity: any;
|
|
8
4
|
readonly children: ReactNode;
|
|
9
5
|
}
|
|
10
|
-
|
|
11
6
|
export interface ContainerData {
|
|
12
7
|
[key: string]: {
|
|
13
8
|
container: {
|
|
@@ -31,7 +26,6 @@ export interface ContainerData {
|
|
|
31
26
|
};
|
|
32
27
|
};
|
|
33
28
|
}
|
|
34
|
-
|
|
35
29
|
export interface PageProviderContext {
|
|
36
30
|
/**
|
|
37
31
|
* `components` is a property of the `PageProviderProps` type.
|
|
@@ -79,7 +73,6 @@ export interface PageProviderContext {
|
|
|
79
73
|
};
|
|
80
74
|
isInsideEditor: boolean;
|
|
81
75
|
}
|
|
82
|
-
|
|
83
76
|
/**
|
|
84
77
|
* `PageProvider` is a functional component that provides a context for a DotCMS page.
|
|
85
78
|
* It takes a `PageProviderProps` object as a parameter and returns a JSX element.
|
|
@@ -88,8 +81,4 @@ export interface PageProviderContext {
|
|
|
88
81
|
* @param {PageProviderProps} props - The properties for the PageProvider. Includes an `entity` and `children`.
|
|
89
82
|
* @returns {JSX.Element} - A JSX element that provides a context for a DotCMS page.
|
|
90
83
|
*/
|
|
91
|
-
export function PageProvider(props: PageProviderProps): JSX.Element
|
|
92
|
-
const { entity, children } = props;
|
|
93
|
-
|
|
94
|
-
return <PageContext.Provider value={entity}>{children}</PageContext.Provider>;
|
|
95
|
-
}
|
|
84
|
+
export declare function PageProvider(props: PageProviderProps): JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PageProviderContext } from '../PageProvider/PageProvider';
|
|
3
|
+
/**
|
|
4
|
+
* Props for the row component
|
|
5
|
+
*
|
|
6
|
+
* @interface RowProps
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
export interface RowProps {
|
|
10
|
+
/**
|
|
11
|
+
* Row data
|
|
12
|
+
*
|
|
13
|
+
* @type {PageProviderContext['layout']['body']['rows'][0]}
|
|
14
|
+
* @memberof RowProps
|
|
15
|
+
*/
|
|
16
|
+
row: PageProviderContext['layout']['body']['rows'][0];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Renders a row
|
|
20
|
+
*
|
|
21
|
+
* @category Components
|
|
22
|
+
* @param {React.ForwardedRef<HTMLDivElement, RowProps>} ref
|
|
23
|
+
* @return {*}
|
|
24
|
+
*/
|
|
25
|
+
export declare const Row: import("react").ForwardRefExoticComponent<RowProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
|
|
3
1
|
import { PageProviderContext } from '../components/PageProvider/PageProvider';
|
|
4
|
-
import { PageContext } from '../contexts/PageContext';
|
|
5
|
-
|
|
6
2
|
/**
|
|
7
3
|
* `useDotcmsPageContext` is a custom React hook that provides access to the `PageProviderContext`.
|
|
8
4
|
* It takes no parameters and returns the context value or `null` if it's not available.
|
|
@@ -10,6 +6,4 @@ import { PageContext } from '../contexts/PageContext';
|
|
|
10
6
|
* @category Hooks
|
|
11
7
|
* @returns {PageProviderContext | null} - The context value or `null` if it's not available.
|
|
12
8
|
*/
|
|
13
|
-
export function useDotcmsPageContext()
|
|
14
|
-
return useContext<PageProviderContext | null>(PageContext);
|
|
15
|
-
}
|
|
9
|
+
export declare function useDotcmsPageContext(): PageProviderContext | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PageProviderContext } from '../components/PageProvider/PageProvider';
|
|
3
|
+
export declare const mockPageContext: PageProviderContext;
|
|
4
|
+
export declare const MockContextRender: ({ children, mockContext }: {
|
|
5
|
+
children: JSX.Element;
|
|
6
|
+
mockContext: Partial<PageProviderContext>;
|
|
7
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ContainerData, PageProviderContext } from '../components/PageProvider/PageProvider';
|
|
2
|
+
export declare const getContainersData: (containers: ContainerData, containerRef: PageProviderContext['layout']['body']['rows'][0]['columns'][0]['containers'][0]) => {
|
|
3
|
+
acceptTypes: string;
|
|
4
|
+
contentlets: {
|
|
5
|
+
contentType: string;
|
|
6
|
+
identifier: string;
|
|
7
|
+
title: string;
|
|
8
|
+
inode: string;
|
|
9
|
+
onNumberOfPages: number;
|
|
10
|
+
widgetTitle?: string | undefined;
|
|
11
|
+
}[];
|
|
12
|
+
variantId: string;
|
|
13
|
+
path: string;
|
|
14
|
+
identifier: string;
|
|
15
|
+
maxContentlets: number;
|
|
16
|
+
parentPermissionable: Record<string, string>;
|
|
17
|
+
};
|
|
18
|
+
export declare const combineClasses: (classes: string[]) => string;
|
|
19
|
+
export declare const getPositionStyleClasses: (start: number, end: number) => {
|
|
20
|
+
startClass: string;
|
|
21
|
+
endClass: string;
|
|
22
|
+
};
|
package/.babelrc
DELETED
package/.eslintrc.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": ["plugin:@nrwl/nx/react", "../../../.eslintrc.base.json"],
|
|
3
|
-
"ignorePatterns": ["!**/*"],
|
|
4
|
-
"overrides": [
|
|
5
|
-
{
|
|
6
|
-
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
|
7
|
-
"rules": {}
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
"files": ["*.ts", "*.tsx"],
|
|
11
|
-
"rules": {}
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"files": ["*.js", "*.jsx"],
|
|
15
|
-
"rules": {}
|
|
16
|
-
}
|
|
17
|
-
]
|
|
18
|
-
}
|
package/jest.config.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
export default {
|
|
3
|
-
displayName: 'sdk-react',
|
|
4
|
-
preset: '../../../jest.preset.js',
|
|
5
|
-
transform: {
|
|
6
|
-
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest',
|
|
7
|
-
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nrwl/react/babel'] }]
|
|
8
|
-
},
|
|
9
|
-
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
|
10
|
-
coverageDirectory: '../../../coverage/libs/sdk/react'
|
|
11
|
-
};
|
package/project.json
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "sdk-react",
|
|
3
|
-
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "libs/sdk/react/src",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"tags": [],
|
|
7
|
-
"targets": {
|
|
8
|
-
"lint": {
|
|
9
|
-
"executor": "@nrwl/linter:eslint",
|
|
10
|
-
"outputs": ["{options.outputFile}"],
|
|
11
|
-
"options": {
|
|
12
|
-
"lintFilePatterns": ["libs/sdk/react/**/*.{ts,tsx,js,jsx}"]
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"build": {
|
|
16
|
-
"executor": "@nrwl/rollup:rollup",
|
|
17
|
-
"outputs": ["{options.outputPath}"],
|
|
18
|
-
"options": {
|
|
19
|
-
"outputPath": "dist/libs/sdk/react",
|
|
20
|
-
"tsConfig": "libs/sdk/react/tsconfig.lib.json",
|
|
21
|
-
"project": "libs/sdk/react/package.json",
|
|
22
|
-
"entryFile": "libs/sdk/react/src/index.ts",
|
|
23
|
-
"external": ["react/jsx-runtime"],
|
|
24
|
-
"rollupConfig": "@nrwl/react/plugins/bundle-rollup",
|
|
25
|
-
"compiler": "babel",
|
|
26
|
-
"extractCss": false,
|
|
27
|
-
"assets": [
|
|
28
|
-
{
|
|
29
|
-
"glob": "libs/sdk/react/README.md",
|
|
30
|
-
"input": ".",
|
|
31
|
-
"output": "."
|
|
32
|
-
}
|
|
33
|
-
]
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
"test": {
|
|
37
|
-
"executor": "@nrwl/jest:jest",
|
|
38
|
-
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
|
39
|
-
"options": {
|
|
40
|
-
"jestConfig": "libs/sdk/react/jest.config.ts",
|
|
41
|
-
"passWithNoTests": true
|
|
42
|
-
},
|
|
43
|
-
"configurations": {
|
|
44
|
-
"ci": {
|
|
45
|
-
"ci": true,
|
|
46
|
-
"codeCoverage": true
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
.col-start-1 {
|
|
2
|
-
grid-column-start: 1;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
.col-start-2 {
|
|
6
|
-
grid-column-start: 2;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
.col-start-3 {
|
|
10
|
-
grid-column-start: 3;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.col-start-4 {
|
|
14
|
-
grid-column-start: 4;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.col-start-5 {
|
|
18
|
-
grid-column-start: 5;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.col-start-6 {
|
|
22
|
-
grid-column-start: 6;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
.col-start-7 {
|
|
26
|
-
grid-column-start: 7;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.col-start-8 {
|
|
30
|
-
grid-column-start: 8;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.col-start-9 {
|
|
34
|
-
grid-column-start: 9;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
.col-start-10 {
|
|
38
|
-
grid-column-start: 10;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.col-start-11 {
|
|
42
|
-
grid-column-start: 11;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
.col-start-12 {
|
|
46
|
-
grid-column-start: 12;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
.col-end-1 {
|
|
50
|
-
grid-column-end: 1;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
.col-end-2 {
|
|
54
|
-
grid-column-end: 2;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.col-end-3 {
|
|
58
|
-
grid-column-end: 3;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
.col-end-4 {
|
|
62
|
-
grid-column-end: 4;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.col-end-5 {
|
|
66
|
-
grid-column-end: 5;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
.col-end-6 {
|
|
70
|
-
grid-column-end: 6;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.col-end-7 {
|
|
74
|
-
grid-column-end: 7;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.col-end-8 {
|
|
78
|
-
grid-column-end: 8;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
.col-end-9 {
|
|
82
|
-
grid-column-end: 9;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
.col-end-10 {
|
|
86
|
-
grid-column-end: 10;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
.col-end-11 {
|
|
90
|
-
grid-column-end: 11;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
.col-end-12 {
|
|
94
|
-
grid-column-end: 12;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
.col-end-13 {
|
|
98
|
-
grid-column-end: 13;
|
|
99
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/react';
|
|
2
|
-
import '@testing-library/jest-dom';
|
|
3
|
-
|
|
4
|
-
import * as dotcmsClient from '@dotcms/client';
|
|
5
|
-
|
|
6
|
-
import { Column } from './Column';
|
|
7
|
-
|
|
8
|
-
import { MockContextRender } from '../../mocks/mockPageContext';
|
|
9
|
-
import { ContainerProps } from '../Container/Container';
|
|
10
|
-
|
|
11
|
-
jest.mock('../Container/Container', () => {
|
|
12
|
-
return {
|
|
13
|
-
Container: ({ containerRef }: Partial<ContainerProps>) => (
|
|
14
|
-
<div data-testid="mockContainer">{containerRef?.identifier}</div>
|
|
15
|
-
)
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('Column', () => {
|
|
20
|
-
const mockColumnData = {
|
|
21
|
-
width: 6, // Adjust as needed
|
|
22
|
-
leftOffset: 3, // Adjust as needed
|
|
23
|
-
containers: [
|
|
24
|
-
{ identifier: 'Container1', uuid: 'unique-id-1' },
|
|
25
|
-
{ identifier: 'Container2', uuid: 'unique-id-2' }
|
|
26
|
-
// Add more containers as needed for your test
|
|
27
|
-
],
|
|
28
|
-
styleClass: ''
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
describe('Column is inside editor', () => {
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
jest.spyOn(dotcmsClient, 'isInsideEditor').mockReturnValue(true);
|
|
34
|
-
render(
|
|
35
|
-
<MockContextRender mockContext={{ isInsideEditor: true }}>
|
|
36
|
-
<Column column={mockColumnData} />
|
|
37
|
-
</MockContextRender>
|
|
38
|
-
);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('applies the correct width and start classes based on props', () => {
|
|
42
|
-
const columnElement = screen.getByTestId('column');
|
|
43
|
-
expect(columnElement).toHaveClass('col-end-9');
|
|
44
|
-
expect(columnElement).toHaveClass('col-start-3');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('applies the correct data attr', () => {
|
|
48
|
-
expect(screen.getByTestId('column')).toHaveAttribute('data-dot', 'column');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('renders the correct number of containers', () => {
|
|
52
|
-
const containers = screen.getAllByTestId('mockContainer');
|
|
53
|
-
expect(containers.length).toBe(mockColumnData.containers.length);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('passes the correct props to each Container', () => {
|
|
57
|
-
mockColumnData.containers.forEach((container) => {
|
|
58
|
-
expect(screen.getByText(container.identifier)).toBeInTheDocument();
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('Column is not inside editor', () => {
|
|
64
|
-
beforeEach(() => {
|
|
65
|
-
jest.spyOn(dotcmsClient, 'isInsideEditor').mockReturnValue(false);
|
|
66
|
-
render(
|
|
67
|
-
<MockContextRender mockContext={{ isInsideEditor: false }}>
|
|
68
|
-
<Column column={mockColumnData} />
|
|
69
|
-
</MockContextRender>
|
|
70
|
-
);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should not have dot attrs', () => {
|
|
74
|
-
const columnElement = screen.queryByTestId('column');
|
|
75
|
-
expect(columnElement).toBeNull();
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
|
|
3
|
-
import styles from './column.module.css';
|
|
4
|
-
|
|
5
|
-
import { PageContext } from '../../contexts/PageContext';
|
|
6
|
-
import { combineClasses, getPositionStyleClasses } from '../../utils/utils';
|
|
7
|
-
import { Container } from '../Container/Container';
|
|
8
|
-
import { PageProviderContext } from '../PageProvider/PageProvider';
|
|
9
|
-
|
|
10
|
-
export interface ColumnProps {
|
|
11
|
-
readonly column: PageProviderContext['layout']['body']['rows'][0]['columns'][0];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function Column({ column }: ColumnProps) {
|
|
15
|
-
const { isInsideEditor } = useContext(PageContext) as PageProviderContext;
|
|
16
|
-
|
|
17
|
-
const { startClass, endClass } = getPositionStyleClasses(
|
|
18
|
-
column.leftOffset,
|
|
19
|
-
column.width + column.leftOffset
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
const combinedClasses = combineClasses([
|
|
23
|
-
styles[endClass],
|
|
24
|
-
styles[startClass],
|
|
25
|
-
column.styleClass
|
|
26
|
-
]);
|
|
27
|
-
|
|
28
|
-
const columnProps = isInsideEditor
|
|
29
|
-
? {
|
|
30
|
-
'data-dot': 'column',
|
|
31
|
-
'data-testid': 'column'
|
|
32
|
-
}
|
|
33
|
-
: {};
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<div {...columnProps} className={combinedClasses}>
|
|
37
|
-
{column.containers.map((container) => (
|
|
38
|
-
<Container
|
|
39
|
-
key={`${container.identifier}-${container.uuid}`}
|
|
40
|
-
containerRef={container}
|
|
41
|
-
/>
|
|
42
|
-
))}
|
|
43
|
-
</div>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
2
|
-
|
|
3
|
-
import { render, screen } from '@testing-library/react';
|
|
4
|
-
|
|
5
|
-
import * as dotcmsClient from '@dotcms/client';
|
|
6
|
-
|
|
7
|
-
import { Container } from './Container';
|
|
8
|
-
|
|
9
|
-
import { MockContextRender, mockPageContext } from '../../mocks/mockPageContext';
|
|
10
|
-
|
|
11
|
-
describe('Container', () => {
|
|
12
|
-
// Mock data for your context and container
|
|
13
|
-
jest.spyOn(dotcmsClient, 'isInsideEditor').mockReturnValue(true);
|
|
14
|
-
|
|
15
|
-
describe('with contentlets', () => {
|
|
16
|
-
const mockContainerRef = {
|
|
17
|
-
identifier: 'container-1',
|
|
18
|
-
uuid: '1',
|
|
19
|
-
containers: []
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
it('renders NoContent component for unsupported content types', () => {
|
|
23
|
-
const updatedContext = {
|
|
24
|
-
...mockPageContext,
|
|
25
|
-
components: {}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
render(
|
|
29
|
-
<MockContextRender mockContext={updatedContext}>
|
|
30
|
-
<Container containerRef={mockContainerRef} />
|
|
31
|
-
</MockContextRender>
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
expect(screen.getByTestId('no-component')).toHaveTextContent(
|
|
35
|
-
'No Component for content-type-1'
|
|
36
|
-
);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('without contentlets', () => {
|
|
40
|
-
const mockContainerRef = {
|
|
41
|
-
identifier: 'container-2',
|
|
42
|
-
uuid: '2',
|
|
43
|
-
containers: []
|
|
44
|
-
};
|
|
45
|
-
it('renders EmptyContainer component in editor mode', () => {
|
|
46
|
-
const updatedContext = {
|
|
47
|
-
...mockPageContext,
|
|
48
|
-
components: {},
|
|
49
|
-
isInsideEditor: true
|
|
50
|
-
};
|
|
51
|
-
render(
|
|
52
|
-
<MockContextRender mockContext={updatedContext}>
|
|
53
|
-
<Container containerRef={mockContainerRef} />
|
|
54
|
-
</MockContextRender>
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
expect(screen.getByTestId('empty-container')).toHaveTextContent(
|
|
58
|
-
'This container is empty.'
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('dont render EmptyContainer component outside editor mode', () => {
|
|
63
|
-
jest.spyOn(dotcmsClient, 'isInsideEditor').mockReturnValue(false);
|
|
64
|
-
|
|
65
|
-
const updatedContext = {
|
|
66
|
-
...mockPageContext,
|
|
67
|
-
components: {},
|
|
68
|
-
isInsideEditor: false
|
|
69
|
-
};
|
|
70
|
-
render(
|
|
71
|
-
<MockContextRender mockContext={updatedContext}>
|
|
72
|
-
<Container containerRef={mockContainerRef} />
|
|
73
|
-
</MockContextRender>
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
expect(screen.queryByTestId('empty-container')).toBeNull();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// Add tests for pointer events, dynamic component rendering, and other scenarios...
|
|
82
|
-
});
|