piral-core 0.15.0-alpha.3905 → 0.15.0-alpha.4005
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/esm/components/ExtensionSlot.js +2 -1
- package/esm/components/ExtensionSlot.js.map +1 -1
- package/esm/modules/element.js +15 -12
- package/esm/modules/element.js.map +1 -1
- package/esm/utils/media.js +1 -2
- package/esm/utils/media.js.map +1 -1
- package/lib/components/ExtensionSlot.js +2 -1
- package/lib/components/ExtensionSlot.js.map +1 -1
- package/lib/modules/element.js +15 -12
- package/lib/modules/element.js.map +1 -1
- package/lib/utils/media.js +1 -2
- package/lib/utils/media.js.map +1 -1
- package/package.json +4 -4
- package/src/RootListener.test.tsx +45 -0
- package/src/actions/app.test.ts +90 -2
- package/src/actions/portal.test.ts +53 -8
- package/src/components/ExtensionSlot.test.tsx +56 -5
- package/src/components/ExtensionSlot.tsx +3 -4
- package/src/components/ForeignComponentContainer.test.tsx +119 -0
- package/src/components/PiralView-server.test.tsx +60 -0
- package/src/components/PiralView.test.tsx +1 -1
- package/src/components/PiralView.tsx +1 -1
- package/src/components/SwitchErrorInfo.test.tsx +38 -0
- package/src/createInstance.test.tsx +10 -0
- package/src/hooks/globalState-server.test.ts +41 -0
- package/src/hooks/setter-server.test.ts +22 -0
- package/src/hooks/setter.test.ts +19 -0
- package/src/modules/element-server.test.ts +29 -0
- package/src/modules/element.test.ts +77 -0
- package/src/modules/element.ts +16 -12
- package/src/state/withApi.test.tsx +28 -9
- package/src/utils/extension.test.tsx +11 -1
- package/src/utils/foreign.test.ts +22 -4
- package/src/utils/guid.test.ts +6 -1
- package/src/utils/helpers.test.ts +52 -0
- package/src/utils/media-server.test.ts +13 -0
- package/src/utils/media.ts +1 -2
- package/src/utils/state.test.ts +39 -0
|
@@ -8,9 +8,61 @@ import {
|
|
|
8
8
|
prependItems,
|
|
9
9
|
appendItems,
|
|
10
10
|
updateKey,
|
|
11
|
+
replaceOrAddItem,
|
|
12
|
+
includeItem,
|
|
13
|
+
tryParseJson,
|
|
14
|
+
removeNested,
|
|
11
15
|
} from './helpers';
|
|
12
16
|
|
|
13
17
|
describe('Helpers Module', () => {
|
|
18
|
+
it('removeNested removes keys values', () => {
|
|
19
|
+
const obj = { d: 'test', z: ['test arr'] };
|
|
20
|
+
const result = removeNested(obj, () => true);
|
|
21
|
+
const expectedResult = { d: {}, z: {} };
|
|
22
|
+
expect(result).toEqual(expectedResult);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('removeNested removes keys values with nested arrays', () => {
|
|
26
|
+
const obj = { z: [['test arr'], ['test arr2']] };
|
|
27
|
+
const result = removeNested(obj, () => true);
|
|
28
|
+
const expectedResult = { z: { '0': [], '1': [] } };
|
|
29
|
+
expect(result).toEqual(expectedResult);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('removeNested splits keys values', () => {
|
|
33
|
+
const obj = { d: 'test', z: ['test arr'] };
|
|
34
|
+
const result = removeNested(obj, () => false);
|
|
35
|
+
const expectedResult = { d: { '0': 't', '1': 'e', '2': 's', '3': 't' }, z: { '0': 'test arr' } };
|
|
36
|
+
expect(result).toEqual(expectedResult);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('tryParseJson parses a JSON string', () => {
|
|
40
|
+
const content = '{"result":true, "count":42}';
|
|
41
|
+
const result = tryParseJson(content);
|
|
42
|
+
expect(result).toEqual({ result: true, count: 42 });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('tryParseJson return empty object if the content is not valid', () => {
|
|
46
|
+
const content = '"result":true, "count":42';
|
|
47
|
+
const result = tryParseJson(content);
|
|
48
|
+
expect(result).toEqual({});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('includeItem adds an item to array', () => {
|
|
52
|
+
const result = includeItem([1, 2, 3], 4);
|
|
53
|
+
expect(result).toEqual([1, 2, 3, 4]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('replaceOrAddItem replaces the first item', () => {
|
|
57
|
+
const result = replaceOrAddItem([1, 2, 3], 4, () => true);
|
|
58
|
+
expect(result).toEqual([4, 2, 3]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('replaceOrAddItem adds the item the end', () => {
|
|
62
|
+
const result = replaceOrAddItem([1, 2, 3], 4, () => false);
|
|
63
|
+
expect(result).toEqual([1, 2, 3, 4]);
|
|
64
|
+
});
|
|
65
|
+
|
|
14
66
|
it('prependItem works with an existing array', () => {
|
|
15
67
|
const result = prependItem([1, 2, 3], 4);
|
|
16
68
|
expect(result).toEqual([4, 1, 2, 3]);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
import { getCurrentLayout } from './media';
|
|
5
|
+
|
|
6
|
+
describe('Media Module', () => {
|
|
7
|
+
it('in here window should be undefined', () => {
|
|
8
|
+
expect(typeof window).toBe('undefined');
|
|
9
|
+
const breakpoints = ['min-width: 200px', 'max-width: 199px'];
|
|
10
|
+
const result = getCurrentLayout(breakpoints, ['foo', 'bar'], 'qxz');
|
|
11
|
+
expect(result).toBe('qxz');
|
|
12
|
+
});
|
|
13
|
+
});
|
package/src/utils/media.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isfunc } from 'piral-base';
|
|
2
|
-
import { none } from './helpers';
|
|
3
2
|
import { LayoutTypes, LayoutBreakpoints } from '../types';
|
|
4
3
|
|
|
5
4
|
export const defaultLayouts: LayoutTypes = ['desktop', 'tablet', 'mobile'];
|
|
@@ -8,7 +7,7 @@ export const defaultBreakpoints: LayoutBreakpoints = ['(min-width: 991px)', '(mi
|
|
|
8
7
|
|
|
9
8
|
const mm =
|
|
10
9
|
typeof window === 'undefined' || !isfunc(window.matchMedia)
|
|
11
|
-
? () => ({ matches:
|
|
10
|
+
? () => ({ matches: undefined })
|
|
12
11
|
: (q: string) => window.matchMedia(q);
|
|
13
12
|
|
|
14
13
|
export function getCurrentLayout<T>(breakpoints: Array<string>, layouts: Array<T>, defaultLayout: T) {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as hooks from '../hooks';
|
|
2
|
+
import { withAll, withRootExtension } from './state';
|
|
3
|
+
import { RootListener } from '../RootListener';
|
|
4
|
+
import { createGlobalState } from '../state';
|
|
5
|
+
|
|
6
|
+
describe('State Module', () => {
|
|
7
|
+
it('withRootExtension should create an extension key', () => {
|
|
8
|
+
const dispatch = withRootExtension('test', RootListener);
|
|
9
|
+
const result = dispatch({ registry: { extensions: {} } });
|
|
10
|
+
expect(result['registry']['extensions']['test']).toBeTruthy();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('withAll should return identity state with no dispatcher', () => {
|
|
14
|
+
const dispatchers = withAll();
|
|
15
|
+
const result = dispatchers({ state: ['foo', 'boo'] });
|
|
16
|
+
expect(result).toEqual({ state: ['foo', 'boo'] });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('withAll should return identity state with identity dispatcher', () => {
|
|
20
|
+
const dispatchers = withAll((s) => s);
|
|
21
|
+
const result = dispatchers({ state: ['foo', 'boo'] });
|
|
22
|
+
expect(result).toEqual({ state: ['foo', 'boo'] });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('withAll should return empty state with blank dispatcher', () => {
|
|
26
|
+
const dispatchers = withAll((s) => ({}));
|
|
27
|
+
const result = dispatchers({ state: ['foo', 'boo'] });
|
|
28
|
+
expect(result).toEqual({});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('withAll should return mutated state of all dispatchers', () => {
|
|
32
|
+
const dispatchers = withAll(
|
|
33
|
+
(s) => ({ ...s, foo: 'bar' }),
|
|
34
|
+
(s) => ({ ...s, bar: 'qxz' }),
|
|
35
|
+
);
|
|
36
|
+
const result = dispatchers({ state: ['foo', 'boo'] });
|
|
37
|
+
expect(result).toEqual({ state: ['foo', 'boo'], foo: 'bar', bar: 'qxz' });
|
|
38
|
+
});
|
|
39
|
+
});
|