UNPKG

lamed_table

Version:
155 lines (132 loc) 7.5 kB
// 'use strict' // Comment out in test functions console.log(`Starting ${__filename}...`) // comment line to remove simple logging /* ------------------------------------------------------ * edit.test.js * Purpose: The purpose of this module is to test table edit operations * Date Created: 2019/12/11 * Created by : Perez Lamed van Niekerk --------------------------------------------------------- */ /* jshint esversion: 6 */ const _test = require('lamed_test') const { Ok, notOk, notOk_Then, Equal, notEqual, con, testAND, unZip, unThrow } = _test // eslint-disable-line con.useChalk(require('chalk')) // con.traceSet(0) // const _str = require('lamed_string') const _table = require('../src/table') // eslint-disable-line function editTest (show) { let error = con.traceFunction(arguments.callee.name) // eslint-disable-line // Create sample table const result = new _table.TableDef( ['Ticket #', 'Assigned/Close Group', 'Assignee', 'Open Date and Time', 'Last Modified Date', 'SLA', 'Summary', 'End User', 'Close Date and Time', '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.show(show) result.stats(show) unZip(() => result.DATA.cols.toString(), 'ticket #,assigned/close group,assignee,open date and time,last modified date,sla,summary,end user,close date and time,value') // change field names unThrow(() => result.Cols.NameDef('Ticket #2', 'id')) result.Cols.NameDef('Ticket #', 'id') result.Cols.NameDefs([ 'Assigned/Close Group-->department', 'Open Date and Time-->open', 'Last Modified Date-->modified', 'End User-->user', 'Close Date and Time-->closed'], false) result.stats(show) unZip(() => result.DATA.cols.toString(), 'id,department,assignee,open,modified,sla,summary,user,closed,value') // Set field types (date, int, float, bool, string) result.Cols.Convert.toInt('id') result.Cols.Convert.toFloat('value') result.Cols.Convert.toDate(['open', 'closed']) result.Cols.Convert.toBool('SLA') result.show(show) // add duration, month, week result.Cols.Convert.addDuration('open', 'closed') result.Cols.Convert.addMonth('closed') result.Cols.Convert.addWeek('closed') unZip(() => result.DATA.cols.toString(), 'id,department,assignee,open,modified,sla,summary,user,closed,value,duration,month,week') result.Cols.Drop(['modified', 'open', 'closed']) unZip(() => result.DATA.cols.toString(), 'id,department,assignee,sla,summary,user,value,duration,month,week') result.show(show) // add type(email, password, 3G, print) when word was found in text result.Cols.Convert.compress('summary', [ 'password', 'print', 'teams', 'phone', '3G -->phone', 'mail', 'notes-->mail', 'lotus-->mail' ]) const stats = result.stats(show, true) stats.tableStats.fields.show(show) stats.dataStats.show(show) unZip(() => result.DATA.rows, [ [1, 'IT', 'Daan', true, 'mail', 'Daan', 10.5, 0.2, 'Jan', 'week 1'], [2, 'IT', 'Ben', true, 'password', 'Piet', 12.5, 0.03333333333333333, 'Jan', 'week 1'], [3, 'IT', 'Bobo', true, 'teams', 'Koos', 15.5, 21.916666666666668, 'Jan', 'week 1'], [4, 'IT', 'Bobo', true, 'print', 'Hennie', 14.1, 1.15, 'Jan', 'week 1'], [5, 'IT', 'Bobo', true, 'password', 'Neda', 17.4, 21.833333333333332, 'Jan', 'week 1'], [6, 'IT', 'Bobo', true, 'phone', 'Aaron', 12.9, 0.5666666666666667, 'Jan', 'week 1'], [7, 'IT', 'Bobo', true, 'mail', 'Cele', 19, 1.65, 'Jan', 'week 1'], [8, 'IT', 'Bobo', true, 'print', 'Emile', 13.3, 4.8, 'Jan', 'week 1'], [9, 'IT', 'Bobo', true, 'phone', 'Bettie', 18.4, 16.466666666666665, 'Jan', 'week 1'], [10, 'IT', 'Ben', true, 'teams', 'Emile', 12.7, 21.566666666666666, 'Jan', 'week 1'], [11, 'IT', 'Daan', true, 'mail', 'Carl', 33, 0.06666666666666667, 'Jan', 'week 1'], [12, 'IT', 'Bobo', true, 'mail', 'Slime', 35, 1.7, 'Jan', 'week 1'], [13, 'IT', 'Bobo', true, 'phone', 'Baba', 45, 3.3333333333333335, 'Feb', 'week 6']]) result.show(show) // Duration averages // id,department,assignee,sla,summary,user,value,duration,month,week // ----------------------------------- // ['Field', 'value', 'duration_avg'] result.statsDuration(['Assignee', 'Month', 'summary', 'user'], show) result.statsDuration2Fields([ 'Assignee-->month', 'Assignee-->week', 'Assignee-->summary' ], show) return true } /** * Test all functions * @param done - callback function to indicate failure or completion */ function TestAll (done) { let error = con.traceFunction(arguments.callee.name) // eslint-disable-line // if (false) done(new Error(error)) const result0 = editTest(!_test.isRootFolder()) con.logGreen('Success!!!') return testAND(module.filename, result0) // eslint-disable-line } /** * Execute the tests manually */ function testRunner (traceLevel = 0) { const done2 = (err) => { if (err !== undefined) { throw err } } // let isRoot = require('lamed_core').isRootFolder() const isRoot = _test.isRootFolder() if (isRoot) return // Only run if not executed from the root folder // Only run if not executed from the root folder // Limit lines reported as not tested con.traceSet(traceLevel); TestAll(done2) // ------------------------------------------- // 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) // Generate readme & help } testRunner(0) // Exports -------------------------- module.exports = { TestAll }