@dxos/react-client 2.31.1-dev.b7e357e5 → 2.31.2-dev.ab9a89e2

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/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "@dxos/react-client",
3
- "version": "2.31.1-dev.b7e357e5",
3
+ "version": "2.31.2-dev.ab9a89e2",
4
4
  "description": "React client API",
5
5
  "license": "MIT",
6
6
  "author": "DXOS.org",
7
7
  "main": "dist/src/index.js",
8
8
  "types": "dist/src/index.d.ts",
9
9
  "dependencies": {
10
- "@dxos/async": "2.31.1-dev.b7e357e5",
11
- "@dxos/bot-factory-client": "2.31.1-dev.b7e357e5",
12
- "@dxos/client": "2.31.1-dev.b7e357e5",
13
- "@dxos/config": "2.31.1-dev.b7e357e5",
14
- "@dxos/credentials": "2.31.1-dev.b7e357e5",
15
- "@dxos/crypto": "2.31.1-dev.b7e357e5",
16
- "@dxos/debug": "2.31.1-dev.b7e357e5",
17
- "@dxos/echo-db": "2.31.1-dev.b7e357e5",
18
- "@dxos/network-manager": "2.31.1-dev.b7e357e5",
19
- "@dxos/util": "2.31.1-dev.b7e357e5",
10
+ "@dxos/async": "2.31.2-dev.ab9a89e2",
11
+ "@dxos/bot-factory-client": "2.31.2-dev.ab9a89e2",
12
+ "@dxos/client": "2.31.2-dev.ab9a89e2",
13
+ "@dxos/config": "2.31.2-dev.ab9a89e2",
14
+ "@dxos/credentials": "2.31.2-dev.ab9a89e2",
15
+ "@dxos/crypto": "2.31.2-dev.ab9a89e2",
16
+ "@dxos/debug": "2.31.2-dev.ab9a89e2",
17
+ "@dxos/echo-db": "2.31.2-dev.ab9a89e2",
18
+ "@dxos/network-manager": "2.31.2-dev.ab9a89e2",
19
+ "@dxos/util": "2.31.2-dev.ab9a89e2",
20
20
  "assert": "^2.0.0",
21
21
  "debug": "^4.3.3",
22
22
  "use-subscription": "^1.4.1"
@@ -24,7 +24,7 @@
24
24
  "devDependencies": {
25
25
  "@dxos/esbuild-plugins": "~2.28.7",
26
26
  "@dxos/eslint-plugin": "~1.0.27",
27
- "@dxos/protocols-toolchain": "2.31.0",
27
+ "@dxos/protocols-toolchain": "2.31.1",
28
28
  "@mui/material": "^5.4.2",
29
29
  "@testing-library/react": "^11.0.4",
30
30
  "@testing-library/react-hooks": "5.1.2",
@@ -33,19 +33,23 @@
33
33
  "@types/mocha": "~8.2.2",
34
34
  "@types/node": "^14.0.9",
35
35
  "@types/react": "^17.0.24",
36
+ "@types/react-dom": "^17.0.9",
36
37
  "@types/testing-library__jest-dom": "~5.9.5",
37
38
  "@types/use-subscription": "^1.0.0",
38
39
  "eslint": "^7.12.1",
39
40
  "expect": "~27.0.2",
40
41
  "fork-ts-checker-webpack-plugin": "~6.2.5",
41
42
  "level-js": "^5.0.2",
43
+ "raf": "^3.4.1",
42
44
  "react": "^17.0.2",
43
45
  "react-dom": "^17.0.2",
44
46
  "react-test-renderer": "^17.0.2",
45
- "typescript": "^4.5.2"
47
+ "typescript": "^4.5.2",
48
+ "wait-for-expect": "^3.0.2"
46
49
  },
47
50
  "peerDependencies": {
48
- "react": "*"
51
+ "react": "*",
52
+ "react-dom": "*"
49
53
  },
50
54
  "publishConfig": {
51
55
  "access": "public"
@@ -0,0 +1,74 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import expect from 'expect';
6
+ import 'raf/polyfill';
7
+ import React from 'react';
8
+ import ReactDOM from 'react-dom';
9
+ import { act } from 'react-dom/test-utils';
10
+ import waitForExpect from 'wait-for-expect';
11
+
12
+ import { Client, Party } from '@dxos/client';
13
+
14
+ import { useSelection } from './useSelection';
15
+
16
+ const count = 10;
17
+ const TYPE_EXAMPLE = 'example:type/org';
18
+
19
+ const useTestComponents = async () => {
20
+ const config = {};
21
+ const client = new Client(config);
22
+ await client.initialize();
23
+ await client.halo.createProfile();
24
+
25
+ const party = await client.echo.createParty();
26
+ const items = await Promise.all(Array.from({ length: count }).map(async () => {
27
+ return await party.database.createItem({ type: TYPE_EXAMPLE });
28
+ }));
29
+ expect(items.length).toBe(count);
30
+
31
+ return { client, party };
32
+ };
33
+
34
+ const UseSelectionTestComponent = ({ party }: { party: Party}) => {
35
+ const items = useSelection(party?.select().filter({ type: TYPE_EXAMPLE }), []);
36
+
37
+ const addItem = async () => await party.database.createItem({ type: TYPE_EXAMPLE });
38
+
39
+ return (
40
+ <ul onClick={addItem}>
41
+ {items?.map(item => <li key={item.id}>{item.id}</li>)}
42
+ </ul>
43
+ );
44
+ };
45
+
46
+ let rootContainer: any;
47
+
48
+ beforeEach(() => {
49
+ rootContainer = document.createElement('div');
50
+ document.body.appendChild(rootContainer);
51
+ });
52
+
53
+ afterEach(() => {
54
+ document.body.removeChild(rootContainer);
55
+ rootContainer = null;
56
+ });
57
+
58
+ describe.only('useSelection', () => {
59
+ it('gets updated items selection', async () => {
60
+ const { party } = await useTestComponents();
61
+ act(() => {
62
+ ReactDOM.render(<UseSelectionTestComponent party={party} />, rootContainer);
63
+ });
64
+
65
+ const ul = rootContainer.querySelector('ul');
66
+ await waitForExpect(() => {
67
+ expect(ul.childNodes.length).toEqual(count);
68
+ });
69
+ ul.click();
70
+ await waitForExpect(() => {
71
+ expect(ul.childNodes.length).toEqual(count + 1);
72
+ });
73
+ });
74
+ });