Skip to content

Commit 00a4a5d

Browse files
committed
Fix Tests
Signed-off-by: guido <[email protected]>
1 parent 73890a4 commit 00a4a5d

File tree

8 files changed

+75
-70
lines changed

8 files changed

+75
-70
lines changed

@types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ declare namespace EntitiesSearch {
7171
entitiesOptions: EntitiesState<V>['entitiesOptions'];
7272
}
7373
| {
74-
type: 'UPDATE_CONTEXUAL_ENTITIES_OPTIONS';
74+
type: 'UPDATE_CONTEXTUAL_ENTITIES_OPTIONS';
7575
contextualEntitiesOptions: EntitiesState<V>['contexualEntitiesOptions'];
7676
}
7777
| {

sources/js/src/components/composite-entities-by-kind.tsx

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,27 @@ export function CompositeEntitiesByKind<P, T>(
4242
);
4343
}
4444

45-
Promise.all(promises).then((result) => {
46-
const entitiesOptions = result[0] ?? OrderedSet([]);
47-
const selectedEntitiesOptions = result[1] ?? OrderedSet([]);
45+
Promise.all(promises)
46+
.then((result) => {
47+
const entitiesOptions = result[0] ?? OrderedSet([]);
48+
const selectedEntitiesOptions = result[1] ?? OrderedSet([]);
4849

49-
dispatch({
50-
type: 'UPDATE_SELECTED_ENTITIES_OPTIONS',
51-
selectedEntitiesOptions: selectedEntitiesOptions,
52-
});
53-
dispatch({
54-
type: 'UPDATE_CONTEXUAL_ENTITIES_OPTIONS',
55-
contextualEntitiesOptions: entitiesOptions,
56-
});
57-
dispatch({
58-
type: 'UPDATE_ENTITIES_OPTIONS',
59-
entitiesOptions: entitiesOptions,
50+
dispatch({
51+
type: 'UPDATE_SELECTED_ENTITIES_OPTIONS',
52+
selectedEntitiesOptions,
53+
});
54+
dispatch({
55+
type: 'UPDATE_CONTEXTUAL_ENTITIES_OPTIONS',
56+
contextualEntitiesOptions: entitiesOptions,
57+
});
58+
dispatch({
59+
type: 'UPDATE_ENTITIES_OPTIONS',
60+
entitiesOptions,
61+
});
62+
})
63+
.catch((error) => {
64+
console.warn(`Composite Entities by Kind: ${error}`);
6065
});
61-
});
6266
// eslint-disable-next-line react-hooks/exhaustive-deps
6367
}, []);
6468

@@ -118,19 +122,25 @@ export function CompositeEntitiesByKind<P, T>(
118122
}),
119123
]);
120124

121-
Promise.all(promises).then((result) => {
122-
const entitiesOptions = result[0] ?? OrderedSet([]);
123-
const selectedEntitiesOptions = result[1] ?? OrderedSet([]);
125+
Promise.all(promises)
126+
.then((result) => {
127+
const entitiesOptions = result[0] ?? OrderedSet([]);
128+
const selectedEntitiesOptions = result[1] ?? OrderedSet([]);
124129

125-
dispatch({
126-
type: 'UPDATE_SELECTED_ENTITIES_OPTIONS',
127-
selectedEntitiesOptions,
128-
});
129-
dispatch({
130-
type: 'UPDATE_ENTITIES_OPTIONS',
131-
entitiesOptions,
130+
dispatch({
131+
type: 'UPDATE_SELECTED_ENTITIES_OPTIONS',
132+
selectedEntitiesOptions,
133+
});
134+
dispatch({
135+
type: 'UPDATE_ENTITIES_OPTIONS',
136+
entitiesOptions,
137+
});
138+
})
139+
.catch((error) => {
140+
console.warn(
141+
`Composite Entities by Kind - on Change Entities: ${error}`
142+
);
132143
});
133-
});
134144
};
135145

136146
const onChangeKind = (kind: T) => {
@@ -145,7 +155,7 @@ export function CompositeEntitiesByKind<P, T>(
145155
})
146156
.then((result) => {
147157
dispatch({
148-
type: 'UPDATE_CONTEXUAL_ENTITIES_OPTIONS',
158+
type: 'UPDATE_CONTEXTUAL_ENTITIES_OPTIONS',
149159
contextualEntitiesOptions: result,
150160
});
151161
dispatch({
@@ -156,6 +166,11 @@ export function CompositeEntitiesByKind<P, T>(
156166
type: 'UPDATE_SELECTED_ENTITIES_OPTIONS',
157167
selectedEntitiesOptions: entities,
158168
});
169+
})
170+
.catch((error) => {
171+
console.warn(
172+
`Composite Entities by Kind - on Change Kind: ${error}`
173+
);
159174
});
160175
};
161176

@@ -177,30 +192,24 @@ export function CompositeEntitiesByKind<P, T>(
177192
onChange: onChangeKind,
178193
};
179194

180-
return (
181-
<>
182-
{props.children(
183-
entities,
184-
kind,
185-
// TODO Add debouncing to the `search` callback
186-
(phrase: SearchPhrase) => {
187-
const _phrase = extractPhrase(phrase);
188-
189-
setSearchPhrase(_phrase);
190-
191-
if (_phrase === '') {
192-
dispatch({
193-
type: 'UPDATE_ENTITIES_OPTIONS',
194-
entitiesOptions: state.contexualEntitiesOptions,
195-
});
196-
return;
197-
}
198-
199-
searchEntitiesByKind(_phrase, entitiesAndKind.kind);
200-
}
201-
)}
202-
</>
203-
);
195+
// TODO Add debouncing to the `search` callback
196+
const search = (phrase: SearchPhrase) => {
197+
const _phrase = extractPhrase(phrase);
198+
199+
setSearchPhrase(_phrase);
200+
201+
if (_phrase === '') {
202+
dispatch({
203+
type: 'UPDATE_ENTITIES_OPTIONS',
204+
entitiesOptions: state.contexualEntitiesOptions,
205+
});
206+
return;
207+
}
208+
209+
searchEntitiesByKind(_phrase, entitiesAndKind.kind);
210+
};
211+
212+
return <>{props.children(entities, kind, search)}</>;
204213
}
205214

206215
function extractPhrase(phraseOrEvent: SearchPhrase): string {

sources/js/src/components/entities-select-control.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export function EntitiesSelectControl(
1212
): JSX.Element {
1313
const className = classnames(
1414
props.className,
15-
'wz-entities-select-control',
16-
'wz-entities-select-control--entities'
15+
'wz-select-control',
16+
'wz-select-control--entities'
1717
);
1818

1919
if (props.options.size <= 0) {
@@ -36,7 +36,7 @@ export function EntitiesSelectControl(
3636
{props.options.map((option) => (
3737
<option
3838
key={option.value}
39-
className={`wz-entities-select-control-item wz-entities-select-control-item--${option.value}`}
39+
className={`wz-select-control-item wz-select-control-item--${option.value}`}
4040
value={option.value}
4141
>
4242
{option.label}

sources/js/src/components/entities-toggle-control.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,13 @@ export function EntitiesToggleControl(
3737
return (
3838
<div className={className}>
3939
{props.options.map((option) => (
40-
<div
41-
key={option.value}
42-
className="wz-entities-toggle-control-item"
43-
>
40+
<div key={option.value} className="wz-toggle-control-item">
4441
<label
45-
htmlFor={`wz-entities-toggle-control-item__input-${option.value}`}
42+
htmlFor={`wz-toggle-control-item__input-${option.value}`}
4643
>
4744
<input
4845
type="checkbox"
49-
id={`wz-entities-toggle-control-item__input-${option.value}`}
46+
id={`wz-toggle-control-item__input-${option.value}`}
5047
checked={props.value?.has(option.value)}
5148
value={option.value}
5249
onChange={onChange}

sources/js/src/storage/entities/reducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function reducer<P>(
55
action: EntitiesSearch.EntitiesAction<P>
66
): EntitiesSearch.EntitiesState<P> {
77
switch (action.type) {
8-
case 'UPDATE_CONTEXUAL_ENTITIES_OPTIONS':
8+
case 'UPDATE_CONTEXTUAL_ENTITIES_OPTIONS':
99
return {
1010
...state,
1111
contexualEntitiesOptions: action.contextualEntitiesOptions,

tests/js/unit/components/composite-entities-by-kind.test.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { CompositeEntitiesByKind } from '../../../../sources/js/src/components/c
1111
import { EntitiesSelectControl } from '../../../../sources/js/src/components/entities-select-control';
1212
import { KindSelectControl } from '../../../../sources/js/src/components/kind-select-control';
1313

14-
describe.skip('CompositeEntitiesByKind', () => {
14+
describe('CompositeEntitiesByKind', () => {
1515
/**
1616
* This test want to ensure it is possible to select a post type.
1717
*/
@@ -89,7 +89,7 @@ describe.skip('CompositeEntitiesByKind', () => {
8989
});
9090

9191
const postsSelect = rendered.container.querySelector(
92-
'.wz-entities-select-control'
92+
'.wz-select-control'
9393
) as HTMLSelectElement;
9494

9595
await userEvent.selectOptions(postsSelect, ['post-2']);
@@ -140,10 +140,10 @@ describe.skip('CompositeEntitiesByKind', () => {
140140
});
141141

142142
const postTypeSelect = rendered.container.querySelector(
143-
'.wz-select-control'
143+
'.wz-select-control--kind'
144144
) as HTMLSelectElement;
145145
const postsSelect = rendered.container.querySelector(
146-
'.wz-select-control'
146+
'.wz-select-control--entities'
147147
) as HTMLSelectElement;
148148

149149
await userEvent.selectOptions(postsSelect, ['post-2']);
@@ -242,7 +242,6 @@ describe.skip('CompositeEntitiesByKind', () => {
242242
>
243243
{(posts, postType) => {
244244
expectedPosts = posts.options;
245-
246245
return (
247246
<>
248247
<KindSelectControl {...postType} />
@@ -254,7 +253,7 @@ describe.skip('CompositeEntitiesByKind', () => {
254253
);
255254

256255
const postTypeSelect = rendered.container.querySelector(
257-
'.wz-select-control'
256+
'.wz-select-control--kind'
258257
) as HTMLSelectElement;
259258

260259
userEvent.selectOptions(postTypeSelect, 'page').then(() => {

tests/js/unit/components/entities-select-control.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('Posts Select', () => {
3333

3434
const valuesToSelect = [option.value, String(options.last()?.value)];
3535
const select = rendered.container.querySelector(
36-
'.wz-entities-select-control'
36+
'.wz-select-control'
3737
) as HTMLSelectElement;
3838

3939
/*

tests/js/unit/storage/reducer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('reducer', () => {
3030
},
3131
]);
3232
const newState = reducer(state, {
33-
type: 'UPDATE_CONTEXUAL_ENTITIES_OPTIONS',
33+
type: 'UPDATE_CONTEXTUAL_ENTITIES_OPTIONS',
3434
contextualEntitiesOptions: contextualPostsOptions,
3535
});
3636

0 commit comments

Comments
 (0)