import * as chai from 'chai'; import { Treelab } from './sdk'; import { ColumnType, ViewType, Color, Icon } from './types'; import { Workspace, WorkspaceArray } from './sdk/workspace'; import { Core, CoreArray } from './sdk/core'; import { Table, TableArray } from './sdk/table'; import { View } from './sdk/view'; chai.should(); const treelab = new Treelab({ token: 'budTest' }); let testCreateWorkspace: Workspace; let testCreateWorkspaces: WorkspaceArray; describe('workspace', () => { describe('createWorkspace', () => { it('ok', async () => { testCreateWorkspace = await treelab.createWorkspace({ name: 'testCreateWorkspace' }); testCreateWorkspace.should.be.a('object'); testCreateWorkspace.should.have.property('id'); testCreateWorkspace.should.have.property('name', 'testCreateWorkspace'); }); }); describe('createWorkspaces', () => { it('ok', async () => { testCreateWorkspaces = await treelab.createWorkspaces([ { name: 'testCreateWorkspaces1' }, { name: 'testCreateWorkspaces2' }, ]); testCreateWorkspaces.should.be.a('object'); testCreateWorkspaces.should.have.property('workspaces'); testCreateWorkspaces.workspaces.should.have.lengthOf(2); }); }); describe('workspace', () => { it('ok', async () => { const workspace = await treelab.workspace(testCreateWorkspace.id); workspace.should.be.a('object'); workspace.should.have.property('id'); workspace.should.have.property('name'); }); }); describe('getWorkspaces', () => { it('ok', async () => { const workspaces = await treelab.getWorkspaces(); workspaces.should.be.a('object'); workspaces.should.have.property('workspaces'); }); }); describe('select', () => { it('ok', async () => { const workspaces = await testCreateWorkspaces.select( 1, i => i.name === 'testCreateWorkspaces2', ); workspaces.should.be.a('object'); workspaces.should.have.property('workspaces'); workspaces.workspaces.should.have.lengthOf(1); workspaces.workspaces[0].should.have.property('name', 'testCreateWorkspaces2'); }); }); describe('sort', () => { it('ok', async () => { const workspaces = await testCreateWorkspaces.sort((a, b) => b.name.localeCompare(a.name)); workspaces.should.be.a('object'); workspaces.should.have.property('workspaces'); workspaces.workspaces.should.have.lengthOf(2); workspaces.workspaces[0].should.have.property('name', 'testCreateWorkspaces2'); workspaces.workspaces[1].should.have.property('name', 'testCreateWorkspaces1'); }); }); }); let testCreateCore: Core; let testCreateCores: CoreArray; describe('core', () => { describe('createCore', () => { it('ok', async () => { testCreateCore = await testCreateWorkspace.createCore({ name: 'testCreateCore', icon: Icon.calendar, color: Color.blue, }); testCreateCore.should.be.a('object'); testCreateCore.should.have.property('id'); testCreateCore.should.have.property('name', 'testCreateCore'); testCreateCore.should.have.property('icon', Icon.calendar); testCreateCore.should.have.property('color', Color.blue); }); }); describe('createCores', () => { it('ok', async () => { testCreateCores = await testCreateWorkspace.createCores([ { name: 'testCreateCores1', icon: Icon.calendar, color: Color.blue }, { name: 'testCreateCores2', icon: Icon.calendar, color: Color.blue }, ]); testCreateCores.should.be.a('object'); testCreateCores.should.have.property('cores'); testCreateCores.cores.should.have.lengthOf(2); }); }); describe('core', () => { it('ok', async () => { const core = await testCreateWorkspace.core(testCreateCore.id); core.should.be.a('object'); core.should.have.property('id'); core.should.have.property('name'); core.should.have.property('icon'); core.should.have.property('color'); }); }); describe('getCores', () => { it('ok', async () => { const cores = await testCreateWorkspace.getCores(); cores.should.be.a('object'); cores.should.have.property('cores'); }); }); describe('select', () => { it('ok', async () => { const cores = await testCreateCores.select(1, i => i.name === 'testCreateCores2'); cores.should.be.a('object'); cores.should.have.property('cores'); cores.cores.should.have.lengthOf(1); cores.cores[0].should.have.property('name', 'testCreateCores2'); }); }); describe('sort', () => { it('ok', async () => { const cores = await testCreateCores.sort((a, b) => b.name.localeCompare(a.name)); cores.should.be.a('object'); cores.should.have.property('cores'); cores.cores.should.have.lengthOf(2); cores.cores[0].should.have.property('name', 'testCreateCores2'); cores.cores[1].should.have.property('name', 'testCreateCores1'); }); }); }); let testCreateTable: Table; let testCreateTables: TableArray; describe('table', () => { describe('createTable', () => { it('ok', async () => { testCreateTable = await testCreateCore.createTable({ name: 'testCreateTable', view: { name: 'testView', type: ViewType.GRID }, columns: [ { type: ColumnType.TEXT, name: 'f1' }, { type: ColumnType.TEXT, name: 'f2' }, { type: ColumnType.TEXT, name: 'f3' }, ], data: [['1', '2', '3'], ['21', '22', '23'], ['31', '32', '33']], }); testCreateTable.should.be.a('object'); testCreateTable.should.have.property('id'); testCreateTable.should.have.property('name', 'testCreateTable'); }); }); describe('createTables', () => { it('ok', async () => { testCreateTables = await testCreateCore.createTables([ { name: 'testCreateTables1', }, { name: 'testCreateTables2', }, ]); testCreateTables.should.be.a('object'); testCreateTables.should.have.property('tables'); testCreateTables.tables.should.have.lengthOf(2); }); }); describe('table', () => { it('ok', async () => { const table = await testCreateCore.table(testCreateTable.id); table.should.be.a('object'); table.should.have.property('id'); table.should.have.property('name'); table.should.have.property('views'); table.should.have.property('rows'); }); }); describe('cells', () => { it('ok', async () => { const cells = await testCreateTable.getCells(); cells.should.be.a('object'); cells.should.have.property('cells'); }); }); describe('getRows', () => { it('ok', async () => { const rows = await testCreateTable.getRows(); rows.should.be.a('object'); rows.should.have.property('rows'); }); }); describe('getTables', () => { it('ok', async () => { const tables = await testCreateCore.getTables(); tables.should.be.a('object'); tables.should.have.property('tables'); }); }); let testView: View; describe('addView', () => { it('ok', async () => { testView = await testCreateTable.addView({ name: 'testView1', type: ViewType.GRID }); testView.should.be.a('object'); testView.should.have.property('id'); }); }); describe('getColumns', () => { it('ok', async () => { const columns = await testView.getColumns(); columns.should.be.a('object'); columns.should.have.property('columns'); }); }); describe('select', () => { it('ok', async () => { const tables = await testCreateTables.select(1, i => i.name === 'testCreateTables2'); tables.should.be.a('object'); tables.should.have.property('tables'); tables.tables.should.have.lengthOf(1); tables.tables[0].should.have.property('name', 'testCreateTables2'); }); }); describe('sort', () => { it('ok', async () => { const tables = await testCreateTables.sort((a, b) => b.name.localeCompare(a.name)); tables.should.be.a('object'); tables.should.have.property('tables'); tables.tables.should.have.lengthOf(2); tables.tables[0].should.have.property('name', 'testCreateTables2'); tables.tables[1].should.have.property('name', 'testCreateTables1'); }); }); });