@elementor/locations 0.7.4 → 0.7.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 +6 -0
- package/package.json +10 -3
- package/src/__tests__/index.test.tsx +0 -238
- package/typedoc.config.js +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.7.5](https://github.com/elementor/elementor-packages/compare/@elementor/locations@0.7.4...@elementor/locations@0.7.5) (2024-08-05)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- publish only necessary files to npm ([#226](https://github.com/elementor/elementor-packages/issues/226)) ([d808e2f](https://github.com/elementor/elementor-packages/commit/d808e2f60eb7ca2d7b8560d0b79c0e62c2f969a8))
|
|
11
|
+
|
|
6
12
|
## [0.7.4](https://github.com/elementor/elementor-packages/compare/@elementor/locations@0.7.3...@elementor/locations@0.7.4) (2024-07-16)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @elementor/locations
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/locations",
|
|
3
3
|
"description": "Create & manage pluggable React applications",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.5",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "https://github.com/elementor/elementor-packages.git",
|
|
22
|
+
"url": "git+https://github.com/elementor/elementor-packages.git",
|
|
23
23
|
"directory": "packages/libs/locations"
|
|
24
24
|
},
|
|
25
25
|
"bugs": {
|
|
@@ -28,6 +28,13 @@
|
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
+
"files": [
|
|
32
|
+
"README.md",
|
|
33
|
+
"CHANGELOG.md",
|
|
34
|
+
"/dist",
|
|
35
|
+
"/src",
|
|
36
|
+
"!**/__tests__"
|
|
37
|
+
],
|
|
31
38
|
"scripts": {
|
|
32
39
|
"build": "tsup --config=../../tsup.build.ts",
|
|
33
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
@@ -35,5 +42,5 @@
|
|
|
35
42
|
"peerDependencies": {
|
|
36
43
|
"react": "^18.3.1"
|
|
37
44
|
},
|
|
38
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "f4ca33da0842a29d83736d0a173633085edddaee"
|
|
39
46
|
}
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import { lazy } from 'react';
|
|
4
|
-
import { createLocation } from '../api';
|
|
5
|
-
|
|
6
|
-
describe( '@elementor/locations', () => {
|
|
7
|
-
it( 'should render components based on the location name', () => {
|
|
8
|
-
// Arrange.
|
|
9
|
-
const { inject: injectIntoTest, Slot: TestSlot } = createLocation();
|
|
10
|
-
const { inject: injectIntoTest2 } = createLocation();
|
|
11
|
-
|
|
12
|
-
injectIntoTest( {
|
|
13
|
-
id: 'test-1',
|
|
14
|
-
component: () => <div data-testid="element">First div</div>,
|
|
15
|
-
} );
|
|
16
|
-
|
|
17
|
-
injectIntoTest( {
|
|
18
|
-
id: 'test-2',
|
|
19
|
-
component: () => <div data-testid="element">Second div</div>,
|
|
20
|
-
} );
|
|
21
|
-
|
|
22
|
-
injectIntoTest2( {
|
|
23
|
-
id: 'test-3',
|
|
24
|
-
component: () => <div data-testid="element">Should not exist</div>,
|
|
25
|
-
} );
|
|
26
|
-
|
|
27
|
-
// Act.
|
|
28
|
-
render( <TestSlot /> );
|
|
29
|
-
|
|
30
|
-
// Assert.
|
|
31
|
-
const elements = screen.getAllByTestId( 'element' );
|
|
32
|
-
|
|
33
|
-
expect( elements ).toHaveLength( 2 );
|
|
34
|
-
expect( elements[ 0 ].innerHTML ).toBe( 'First div' );
|
|
35
|
-
expect( elements[ 1 ].innerHTML ).toBe( 'Second div' );
|
|
36
|
-
} );
|
|
37
|
-
|
|
38
|
-
it( 'should render components based on priority', () => {
|
|
39
|
-
// Arrange.
|
|
40
|
-
const { inject, Slot } = createLocation();
|
|
41
|
-
|
|
42
|
-
inject( {
|
|
43
|
-
id: 'test-1',
|
|
44
|
-
component: () => <div data-testid="element">Third div</div>,
|
|
45
|
-
// Default priority is 10.
|
|
46
|
-
} );
|
|
47
|
-
|
|
48
|
-
inject( {
|
|
49
|
-
id: 'test-2',
|
|
50
|
-
component: () => <div data-testid="element">First div</div>,
|
|
51
|
-
options: { priority: 5 },
|
|
52
|
-
} );
|
|
53
|
-
|
|
54
|
-
inject( {
|
|
55
|
-
id: 'test-3',
|
|
56
|
-
component: () => <div data-testid="element">Second div</div>,
|
|
57
|
-
options: { priority: 5 },
|
|
58
|
-
} );
|
|
59
|
-
|
|
60
|
-
// Act.
|
|
61
|
-
render( <Slot /> );
|
|
62
|
-
|
|
63
|
-
// Assert.
|
|
64
|
-
const elements = screen.getAllByTestId( 'element' );
|
|
65
|
-
|
|
66
|
-
expect( elements ).toHaveLength( 3 );
|
|
67
|
-
expect( elements[ 0 ].innerHTML ).toBe( 'First div' );
|
|
68
|
-
expect( elements[ 1 ].innerHTML ).toBe( 'Second div' );
|
|
69
|
-
expect( elements[ 2 ].innerHTML ).toBe( 'Third div' );
|
|
70
|
-
} );
|
|
71
|
-
|
|
72
|
-
it( 'should render empty slot when there are no fills', () => {
|
|
73
|
-
// Arrange.
|
|
74
|
-
const { Slot } = createLocation();
|
|
75
|
-
|
|
76
|
-
// Act.
|
|
77
|
-
const { container } = render( <Slot /> );
|
|
78
|
-
|
|
79
|
-
// Assert.
|
|
80
|
-
expect( container ).toBeEmptyDOMElement();
|
|
81
|
-
} );
|
|
82
|
-
|
|
83
|
-
it( 'should render lazy components', async () => {
|
|
84
|
-
// Arrange.
|
|
85
|
-
const { inject, Slot } = createLocation();
|
|
86
|
-
|
|
87
|
-
inject( {
|
|
88
|
-
id: 'test-1',
|
|
89
|
-
component: () => <div>First div</div>,
|
|
90
|
-
} );
|
|
91
|
-
|
|
92
|
-
inject( {
|
|
93
|
-
id: 'test-2',
|
|
94
|
-
component: lazy( () =>
|
|
95
|
-
Promise.resolve( {
|
|
96
|
-
default: () => <div>Second div</div>,
|
|
97
|
-
} )
|
|
98
|
-
),
|
|
99
|
-
} );
|
|
100
|
-
|
|
101
|
-
// Act.
|
|
102
|
-
render( <Slot /> );
|
|
103
|
-
|
|
104
|
-
// Assert.
|
|
105
|
-
expect( screen.getByText( 'First div' ) ).toBeInTheDocument();
|
|
106
|
-
expect( screen.queryByText( 'Second div' ) ).not.toBeInTheDocument();
|
|
107
|
-
|
|
108
|
-
// Waits for the lazy component to be loaded.
|
|
109
|
-
await screen.findByText( 'Second div' );
|
|
110
|
-
|
|
111
|
-
expect( screen.getByText( 'First div' ) ).toBeInTheDocument();
|
|
112
|
-
expect( screen.getByText( 'Second div' ) ).toBeInTheDocument();
|
|
113
|
-
} );
|
|
114
|
-
|
|
115
|
-
it( 'should error when injecting a component with the same name (without overwrite option)', async () => {
|
|
116
|
-
// Arrange.
|
|
117
|
-
const { inject, Slot } = createLocation();
|
|
118
|
-
|
|
119
|
-
inject( {
|
|
120
|
-
id: 'test',
|
|
121
|
-
component: () => <div>First div</div>,
|
|
122
|
-
} );
|
|
123
|
-
|
|
124
|
-
inject( {
|
|
125
|
-
id: 'test',
|
|
126
|
-
component: () => <div>Second div</div>,
|
|
127
|
-
} );
|
|
128
|
-
|
|
129
|
-
// Act
|
|
130
|
-
render( <Slot /> );
|
|
131
|
-
|
|
132
|
-
// Assert.
|
|
133
|
-
expect( screen.getByText( 'First div' ) ).toBeInTheDocument();
|
|
134
|
-
expect( screen.queryByText( 'Second div' ) ).not.toBeInTheDocument();
|
|
135
|
-
expect( console ).toHaveWarned();
|
|
136
|
-
} );
|
|
137
|
-
|
|
138
|
-
it( 'should overwrite the injected component if has same name', async () => {
|
|
139
|
-
// Arrange.
|
|
140
|
-
const { inject, Slot } = createLocation();
|
|
141
|
-
|
|
142
|
-
inject( {
|
|
143
|
-
id: 'test',
|
|
144
|
-
component: () => <div>First div</div>,
|
|
145
|
-
} );
|
|
146
|
-
|
|
147
|
-
inject( {
|
|
148
|
-
id: 'test',
|
|
149
|
-
component: () => <div>Second div</div>,
|
|
150
|
-
options: { overwrite: true },
|
|
151
|
-
} );
|
|
152
|
-
|
|
153
|
-
inject( {
|
|
154
|
-
id: 'test-2',
|
|
155
|
-
component: () => <div>Third div</div>,
|
|
156
|
-
options: { overwrite: true },
|
|
157
|
-
} );
|
|
158
|
-
|
|
159
|
-
// Act
|
|
160
|
-
render( <Slot /> );
|
|
161
|
-
|
|
162
|
-
// Assert.
|
|
163
|
-
expect( screen.queryByText( 'First div' ) ).not.toBeInTheDocument();
|
|
164
|
-
expect( screen.getByText( 'Second div' ) ).toBeInTheDocument();
|
|
165
|
-
expect( screen.getByText( 'Third div' ) ).toBeInTheDocument();
|
|
166
|
-
} );
|
|
167
|
-
|
|
168
|
-
it( 'should overwrite the injection priority', () => {
|
|
169
|
-
// Arrange.
|
|
170
|
-
const { inject, getInjections } = createLocation();
|
|
171
|
-
|
|
172
|
-
inject( {
|
|
173
|
-
id: 'test-1',
|
|
174
|
-
component: () => <div />,
|
|
175
|
-
options: { priority: 5 },
|
|
176
|
-
} );
|
|
177
|
-
|
|
178
|
-
inject( {
|
|
179
|
-
id: 'test-1',
|
|
180
|
-
component: () => <div />,
|
|
181
|
-
options: { overwrite: true },
|
|
182
|
-
} );
|
|
183
|
-
|
|
184
|
-
// Act + Assert.
|
|
185
|
-
expect( getInjections() ).toHaveLength( 1 );
|
|
186
|
-
expect( getInjections()[ 0 ].priority ).toBe( 10 );
|
|
187
|
-
} );
|
|
188
|
-
|
|
189
|
-
it( 'should catch injected component errors with error boundary', () => {
|
|
190
|
-
// Arrange.
|
|
191
|
-
const { inject, Slot } = createLocation();
|
|
192
|
-
|
|
193
|
-
inject( {
|
|
194
|
-
id: 'test-1',
|
|
195
|
-
component: () => <div>Test 1</div>,
|
|
196
|
-
} );
|
|
197
|
-
|
|
198
|
-
inject( {
|
|
199
|
-
id: 'test-2',
|
|
200
|
-
component: () => {
|
|
201
|
-
throw new Error( 'Error' );
|
|
202
|
-
},
|
|
203
|
-
} );
|
|
204
|
-
|
|
205
|
-
inject( {
|
|
206
|
-
id: 'test-3',
|
|
207
|
-
component: () => <div>Test 3</div>,
|
|
208
|
-
} );
|
|
209
|
-
|
|
210
|
-
// Act.
|
|
211
|
-
render( <Slot /> );
|
|
212
|
-
|
|
213
|
-
// Assert.
|
|
214
|
-
expect( screen.getByText( 'Test 1' ) ).toBeInTheDocument();
|
|
215
|
-
expect( screen.getByText( 'Test 3' ) ).toBeInTheDocument();
|
|
216
|
-
expect( console ).toHaveErrored();
|
|
217
|
-
} );
|
|
218
|
-
|
|
219
|
-
it( 'should pass the props from Slot to the injected component', () => {
|
|
220
|
-
// Arrange.
|
|
221
|
-
const { inject, Slot } = createLocation< { text: string; number: number } >();
|
|
222
|
-
|
|
223
|
-
inject( {
|
|
224
|
-
id: 'test-1',
|
|
225
|
-
component: ( { text, number } ) => (
|
|
226
|
-
<div>
|
|
227
|
-
{ text }: { number }
|
|
228
|
-
</div>
|
|
229
|
-
),
|
|
230
|
-
} );
|
|
231
|
-
|
|
232
|
-
// Act.
|
|
233
|
-
render( <Slot text="The number is" number={ 1 } /> );
|
|
234
|
-
|
|
235
|
-
// Assert.
|
|
236
|
-
expect( screen.getByText( 'The number is: 1' ) ).toBeInTheDocument();
|
|
237
|
-
} );
|
|
238
|
-
} );
|