Socialify

Folder ..

Viewing data.test.ts
89 lines (88 loc) • 2.3 KB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { Frame } from '../src/index';
import { expect } from 'chai';
import JSONData from './support/users.json';
import { data, header } from './support/people';
import path = require('path');

describe('data.ts', () => {
  describe('load frame from json file', () => {
    it('should load the frame from json file', () => {
      const dataToExpect = [
        [
          1,
          'Jeanette',
          'Penddreth',
          '[email protected]',
          'Female',
          '26.58.193.2'
        ],
        [
          2,
          'Giavani',
          'Frediani',
          '[email protected]',
          'Male',
          '229.179.4.212'
        ],
        [3, 'Noell', 'Bea', '[email protected]', 'Female', '180.66.162.255'],
        [4, 'Willard', 'Valek', '[email protected]', 'Male', '67.76.188.26']
      ];
      const headerToExpect = [
        'id',
        'first_name',
        'last_name',
        'email',
        'gender',
        'ip_address'
      ];
      expect(new Frame().fromJSON(JSONData).columns).to.deep.equal(
        headerToExpect
      );
      expect(new Frame().fromJSON(JSONData).rowdata).to.deep.equal(
        dataToExpect
      );
    });
  });
  describe('load data from a CSV file', () => {
    it('should load data from a CSV file', () => {
      const csvPath = path.join(__dirname, 'support', 'users.csv');
      const firstRow = [
        '1',
        'Durante',
        'Toma',
        '[email protected]',
        'Female',
        '55.96.246.188'
      ];
      const lastRow = [
        '10',
        'Niki',
        'Ruos',
        '[email protected]',
        'Female',
        '110.74.213.22'
      ];
      const header = [
        'id',
        'first_name',
        'last_name',
        'email',
        'gender',
        'ip_address'
      ];
      expect(new Frame().fromCSV(csvPath).rowdata[0]).to.deep.equal(firstRow);
      expect(new Frame().fromCSV(csvPath).rowdata[9]).to.deep.equal(lastRow);
      expect(new Frame().fromCSV(csvPath).columns).to.deep.equal(header);
    });
  });
  describe('find', () => {
    it('should search for a specific value', () => {
      const frame = new Frame(data, header).find('Victor', {
        column: 'Name',
        row: 6,
        strict: false
      });
      expect(frame.rowdata).to.deep.equal([data[6]]);
      expect(frame.columns).to.deep.equal(header);
    });
  });
});