UNPKG

lamed_table

Version:
94 lines (84 loc) 4.73 kB
// Add module to test.runner.js // 'use strict' // Comment out in test functions console.log(`Starting ${__filename}...`) // comment line to remove simple logging // ------------------------------------------------------ // filter.test.js // Purpose: The purpose of this to test filter // Date Created: 2019/12/27 // Created by : Perez Lamed van Niekerk // ------------------------------------------------------ /* jshint esversion: 6 */ const _table = require('../src/table') // eslint-disable-line const _test = require('lamed_test') const { con, unZip, unThrow } = _test // eslint-disable-line // --------------------------------------------------- // Setup unit test const show = !_test.isTestRunner() if (show) { con.traceSet(0) // Activate trace when not run from test runner // con.useChalk(require('chalk')) // Give us some colour } con.logLine() con.log(` --> ${__filename}`) // Show test case function sampleData (show = true) { // Create sample table const result = new _table.TableDef( ['Id', 'Group', 'Assignee', 'Open', 'Modified', 'SLA', 'Summary', 'User', 'Closed', 'value'], 'csv') result.Rows.Add(['1', 'IT', 'Daan', '2019/01/02 10:47', '2019/01/02 10:59', 'OK', 'Lotus Notes bla bla', 'Daan', '2019/01/02 10:59', '10.5']) result.Rows.Add(['2', 'IT', 'Ben', '2019/01/03 7:11', '2019/01/03 7:13', 'OK', 'password reset', 'Piet', '2019/01/03 7:13', '12.5']) // password result.Rows.Add(['3', 'IT', 'Bobo', '2019/01/02 9:45', '2019/01/03 7:40', 'OK', 'Microsoft teams set up', 'Koos', '2019/01/03 7:40', '15.5']) result.Rows.Add(['4', 'IT', 'Bobo', '2019/01/03 6:32', '2019/01/03 7:41', 'OK', 'pin for the printer', 'Hennie', '2019/01/03 7:41', '14.1']) // printer result.Rows.Add(['5', 'IT', 'Bobo', '2019/01/02 9:51', '2019/01/03 7:41', 'OK', 'password reset', 'Neda', '2019/01/03 7:41', '17.4']) // password result.Rows.Add(['6', 'IT', 'Bobo', '2019/01/03 9:53', '2019/01/03 10:27', 'OK', '3G data reached', 'Aaron', '2019/01/03 10:27', '12.9']) // 3G result.Rows.Add(['7', 'IT', 'Bobo', '2019/01/03 12:15', '2019/01/03 13:54', 'OK', 'Lotus bla bla bla', 'Cele', '2019/01/03 13:54', '19']) result.Rows.Add(['8', 'IT', 'Bobo', '2019/01/03 9:14', '2019/01/04 6:40', 'OK', 'Re Access to print for', 'Emile', '2019/01/03 14:02', '13.3']) // print result.Rows.Add(['9', 'IT', 'Bobo', '2019/01/03 13:06', '2019/01/04 5:34', 'OK', '3G not working', 'Bettie', '2019/01/04 5:34', '18.4']) // 3G result.Rows.Add(['10', 'IT', 'Ben', '2019/01/03 8:37', '2019/01/04 6:11', 'OK', 'msTeams', 'Emile', '2019/01/04 6:11', '12.7']) result.Rows.Add(['11', 'IT', 'Daan', '2019/01/04 6:41', '2019/01/04 6:45', 'OK', 'Junk mail', 'Carl', '2019/01/04 6:45', '33']) // mail result.Rows.Add(['12', 'IT', 'Bobo', '2019/01/04 7:42', '2019/01/04 9:24', 'OK', 'EMAIL ISSUE', 'Slime', '2019/01/04 9:24', '35']) // email result.Rows.Add(['13', 'IT', 'Bobo', '2019/02/04 7:48', '2019/02/04 11:08', 'OK', 'phone not working', 'Baba', '2019/02/04 11:08', '45']) result.Rows.Add(['14', 'IT', 'Bobo', '2019/02/04 7:48', '2019/02/04 11:08', 'OK', 'phone not working', 'Baba', '2019/02/04 11:08', '45']) result.show(show) result.stats(show) return result } // unique() & merge ------------------------------------------- const tableEmpty = new _table.TableDef(['Id', 'Value']) tableEmpty.show() const rows = tableEmpty.DATA.Rows con.log({ rows }) tableEmpty.unique() const filterEmpty = tableEmpty.filterNew() filterEmpty.add('Id', 0, '>') filterEmpty.add('Value', 0, '>', true) filterEmpty.add('Value', 10, '>', false) const empty = tableEmpty.filter(filterEmpty) empty.show() const table = sampleData(true) table.Cols.Drop(['id', 'Open', 'Modified', 'Closed', 'Summary', 'value', 'user']) const table2 = table.unique() table2.show() // merge const table3 = table2.merge(table2, true) table3.show() // filter const filter = table3.filterNew() filter.add('assignee', 'Daan', '=') filter.add('assignee', 'Ben', '=', false) filter.add('assignee', 'Bobo', '=', false) const table4 = table3.filter(filter, [], true, true, true) //, [] , true, false, true) table4.show(true) unZip(() => table4.value('assignee', 0), 'Daan') // ------------------------------------------------ con.logGreen(` √ ${__filename}`) // Success!!! con.traceLine() // ------------------------------------------------ // Code to generate 'readme' and 'help' when run directly by node // // Add to bottom of testRunner() // Generating readme & help // npm uninstall -g lamed_readme // npm i -g lamed_readme // npm link lamed_readme // const _gen = require('lamed_readme'); _gen.genReadme(__dirname); _gen.genHelp(__dirname) // Uncomment line to generate readme & help // ------------------------------------------------