UNPKG

8.46 kBPlain TextView Raw
1import * as chai from 'chai';
2import { Treelab } from './sdk';
3import { ColumnType, ViewType, Color, Icon } from './types';
4import { Workspace, WorkspaceArray } from './sdk/workspace';
5import { Core, CoreArray } from './sdk/core';
6import { Table, TableArray } from './sdk/table';
7import { View } from './sdk/view';
8
9chai.should();
10const treelab = new Treelab({ token: 'budTest' });
11
12let testCreateWorkspace: Workspace;
13let testCreateWorkspaces: WorkspaceArray;
14
15describe('workspace', () => {
16 describe('createWorkspace', () => {
17 it('ok', async () => {
18 testCreateWorkspace = await treelab.createWorkspace({ name: 'testCreateWorkspace' });
19 testCreateWorkspace.should.be.a('object');
20 testCreateWorkspace.should.have.property('id');
21 testCreateWorkspace.should.have.property('name', 'testCreateWorkspace');
22 });
23 });
24
25 describe('createWorkspaces', () => {
26 it('ok', async () => {
27 testCreateWorkspaces = await treelab.createWorkspaces([
28 { name: 'testCreateWorkspaces1' },
29 { name: 'testCreateWorkspaces2' },
30 ]);
31 testCreateWorkspaces.should.be.a('object');
32 testCreateWorkspaces.should.have.property('workspaces');
33 testCreateWorkspaces.workspaces.should.have.lengthOf(2);
34 });
35 });
36
37 describe('workspace', () => {
38 it('ok', async () => {
39 const workspace = await treelab.workspace(testCreateWorkspace.id);
40 workspace.should.be.a('object');
41 workspace.should.have.property('id');
42 workspace.should.have.property('name');
43 });
44 });
45
46 describe('getWorkspaces', () => {
47 it('ok', async () => {
48 const workspaces = await treelab.getWorkspaces();
49 workspaces.should.be.a('object');
50 workspaces.should.have.property('workspaces');
51 });
52 });
53
54 describe('select', () => {
55 it('ok', async () => {
56 const workspaces = await testCreateWorkspaces.select(
57 1,
58 i => i.name === 'testCreateWorkspaces2',
59 );
60 workspaces.should.be.a('object');
61 workspaces.should.have.property('workspaces');
62 workspaces.workspaces.should.have.lengthOf(1);
63 workspaces.workspaces[0].should.have.property('name', 'testCreateWorkspaces2');
64 });
65 });
66
67 describe('sort', () => {
68 it('ok', async () => {
69 const workspaces = await testCreateWorkspaces.sort((a, b) => b.name.localeCompare(a.name));
70 workspaces.should.be.a('object');
71 workspaces.should.have.property('workspaces');
72 workspaces.workspaces.should.have.lengthOf(2);
73 workspaces.workspaces[0].should.have.property('name', 'testCreateWorkspaces2');
74 workspaces.workspaces[1].should.have.property('name', 'testCreateWorkspaces1');
75 });
76 });
77});
78
79let testCreateCore: Core;
80let testCreateCores: CoreArray;
81
82describe('core', () => {
83 describe('createCore', () => {
84 it('ok', async () => {
85 testCreateCore = await testCreateWorkspace.createCore({
86 name: 'testCreateCore',
87 icon: Icon.calendar,
88 color: Color.blue,
89 });
90 testCreateCore.should.be.a('object');
91 testCreateCore.should.have.property('id');
92 testCreateCore.should.have.property('name', 'testCreateCore');
93 testCreateCore.should.have.property('icon', Icon.calendar);
94 testCreateCore.should.have.property('color', Color.blue);
95 });
96 });
97
98 describe('createCores', () => {
99 it('ok', async () => {
100 testCreateCores = await testCreateWorkspace.createCores([
101 { name: 'testCreateCores1', icon: Icon.calendar, color: Color.blue },
102 { name: 'testCreateCores2', icon: Icon.calendar, color: Color.blue },
103 ]);
104 testCreateCores.should.be.a('object');
105 testCreateCores.should.have.property('cores');
106 testCreateCores.cores.should.have.lengthOf(2);
107 });
108 });
109
110 describe('core', () => {
111 it('ok', async () => {
112 const core = await testCreateWorkspace.core(testCreateCore.id);
113 core.should.be.a('object');
114 core.should.have.property('id');
115 core.should.have.property('name');
116 core.should.have.property('icon');
117 core.should.have.property('color');
118 });
119 });
120
121 describe('getCores', () => {
122 it('ok', async () => {
123 const cores = await testCreateWorkspace.getCores();
124 cores.should.be.a('object');
125 cores.should.have.property('cores');
126 });
127 });
128
129 describe('select', () => {
130 it('ok', async () => {
131 const cores = await testCreateCores.select(1, i => i.name === 'testCreateCores2');
132 cores.should.be.a('object');
133 cores.should.have.property('cores');
134 cores.cores.should.have.lengthOf(1);
135 cores.cores[0].should.have.property('name', 'testCreateCores2');
136 });
137 });
138
139 describe('sort', () => {
140 it('ok', async () => {
141 const cores = await testCreateCores.sort((a, b) => b.name.localeCompare(a.name));
142 cores.should.be.a('object');
143 cores.should.have.property('cores');
144 cores.cores.should.have.lengthOf(2);
145 cores.cores[0].should.have.property('name', 'testCreateCores2');
146 cores.cores[1].should.have.property('name', 'testCreateCores1');
147 });
148 });
149});
150
151let testCreateTable: Table;
152let testCreateTables: TableArray;
153
154describe('table', () => {
155 describe('createTable', () => {
156 it('ok', async () => {
157 testCreateTable = await testCreateCore.createTable({
158 name: 'testCreateTable',
159 view: { name: 'testView', type: ViewType.GRID },
160 columns: [
161 { type: ColumnType.TEXT, name: 'f1' },
162 { type: ColumnType.TEXT, name: 'f2' },
163 { type: ColumnType.TEXT, name: 'f3' },
164 ],
165 data: [['1', '2', '3'], ['21', '22', '23'], ['31', '32', '33']],
166 });
167 testCreateTable.should.be.a('object');
168 testCreateTable.should.have.property('id');
169 testCreateTable.should.have.property('name', 'testCreateTable');
170 });
171 });
172
173 describe('createTables', () => {
174 it('ok', async () => {
175 testCreateTables = await testCreateCore.createTables([
176 {
177 name: 'testCreateTables1',
178 },
179 {
180 name: 'testCreateTables2',
181 },
182 ]);
183 testCreateTables.should.be.a('object');
184 testCreateTables.should.have.property('tables');
185 testCreateTables.tables.should.have.lengthOf(2);
186 });
187 });
188
189 describe('table', () => {
190 it('ok', async () => {
191 const table = await testCreateCore.table(testCreateTable.id);
192 table.should.be.a('object');
193 table.should.have.property('id');
194 table.should.have.property('name');
195 table.should.have.property('views');
196 table.should.have.property('rows');
197 });
198 });
199
200 describe('cells', () => {
201 it('ok', async () => {
202 const cells = await testCreateTable.getCells();
203 cells.should.be.a('object');
204 cells.should.have.property('cells');
205 });
206 });
207
208 describe('getRows', () => {
209 it('ok', async () => {
210 const rows = await testCreateTable.getRows();
211 rows.should.be.a('object');
212 rows.should.have.property('rows');
213 });
214 });
215
216 describe('getTables', () => {
217 it('ok', async () => {
218 const tables = await testCreateCore.getTables();
219 tables.should.be.a('object');
220 tables.should.have.property('tables');
221 });
222 });
223
224 let testView: View;
225 describe('addView', () => {
226 it('ok', async () => {
227 testView = await testCreateTable.addView({ name: 'testView1', type: ViewType.GRID });
228 testView.should.be.a('object');
229 testView.should.have.property('id');
230 });
231 });
232
233 describe('getColumns', () => {
234 it('ok', async () => {
235 const columns = await testView.getColumns();
236 columns.should.be.a('object');
237 columns.should.have.property('columns');
238 });
239 });
240
241 describe('select', () => {
242 it('ok', async () => {
243 const tables = await testCreateTables.select(1, i => i.name === 'testCreateTables2');
244 tables.should.be.a('object');
245 tables.should.have.property('tables');
246 tables.tables.should.have.lengthOf(1);
247 tables.tables[0].should.have.property('name', 'testCreateTables2');
248 });
249 });
250
251 describe('sort', () => {
252 it('ok', async () => {
253 const tables = await testCreateTables.sort((a, b) => b.name.localeCompare(a.name));
254 tables.should.be.a('object');
255 tables.should.have.property('tables');
256 tables.tables.should.have.lengthOf(2);
257 tables.tables[0].should.have.property('name', 'testCreateTables2');
258 tables.tables[1].should.have.property('name', 'testCreateTables1');
259 });
260 });
261});