1 | import { expect } from 'chai';
|
2 | import { component, ReduxApp, connect } from 'src';
|
3 | import { Component } from 'src/components';
|
4 |
|
5 |
|
6 |
|
7 | describe("playground", () => {
|
8 | it("it is a place to run wild", () => {
|
9 |
|
10 | const testAppName = 'connect-test-2';
|
11 |
|
12 | @component
|
13 | class MyComponent {
|
14 | public value = 0;
|
15 |
|
16 | public increment() {
|
17 | this.value = this.value + 1;
|
18 | }
|
19 | }
|
20 |
|
21 | @component
|
22 | class Page1 {
|
23 | @connect({ app: testAppName })
|
24 | public comp1: MyComponent;
|
25 | }
|
26 |
|
27 | class Page2 {
|
28 | @connect({ app: testAppName })
|
29 | public comp2: MyComponent;
|
30 | }
|
31 |
|
32 | @component
|
33 | class App {
|
34 |
|
35 | public page1 = new Page1();
|
36 | public page2 = new Page2();
|
37 |
|
38 | public warehouse = {
|
39 | components: {
|
40 | comp: new MyComponent()
|
41 | }
|
42 | };
|
43 | }
|
44 |
|
45 |
|
46 | const plainApp = new App();
|
47 |
|
48 | expect(plainApp.warehouse.components.comp.value).to.eql(0);
|
49 | expect(plainApp.page1.comp1).to.be.undefined;
|
50 | expect(plainApp.page2.comp2).to.be.undefined;
|
51 |
|
52 |
|
53 | const reduxApp = new ReduxApp(plainApp, { name: testAppName });
|
54 |
|
55 | debugger;
|
56 |
|
57 |
|
58 | expect(reduxApp.root.page1.comp1).to.equal(reduxApp.root.warehouse.components.comp);
|
59 | expect(reduxApp.root.page1.comp1).to.be.instanceOf(Component);
|
60 | expect(reduxApp.root.page1.comp1).to.equal(reduxApp.root.page2.comp2);
|
61 |
|
62 |
|
63 | expect(reduxApp.root.page1.comp1.value).to.eql(0);
|
64 |
|
65 |
|
66 | reduxApp.root.page1.comp1.increment();
|
67 | expect(reduxApp.root.page1.comp1.value).to.eql(1);
|
68 | expect(reduxApp.root.page2.comp2.value).to.eql(1);
|
69 | expect(reduxApp.root.warehouse.components.comp.value).to.eql(1);
|
70 |
|
71 | reduxApp.dispose();
|
72 | });
|
73 | }); |
\ | No newline at end of file |