Permalink
Browse files

Filtering and grouping tests

  • Loading branch information...
energydrink9 committed Oct 9, 2018
1 parent cb6c3ea commit a7b794c6444c2251cf3047927f11ff1017908bdc
Showing with 96 additions and 8 deletions.
  1. +96 −8 __tests__/tests.js
View
@@ -1,8 +1,10 @@
import Engine from '../src/Engine'
import { List } from 'immutable';
import Sort from '../src/Sort';
import BaseColumn from '../src/BaseColumn';
import { List } from 'immutable'
import Sort from '../src/Sort'
import Filter from '../src/Filter';
import BaseColumn from '../src/BaseColumn'
import Group from '../src/Group';
test('elements are sorted correctly', () => {
@@ -22,15 +24,101 @@ test('elements are sorted correctly', () => {
})
)])
let result = Engine.computeElements(data, List(), sort, List(), columns, false)
let result = Engine.computeElements(data, List(), sort, List(), columns, false, false, null)
expect(result.get(0).content.position).toBe(1)
expect(result.get(1).content.position).toBe(2)
expect(result.get(2).content.position).toBe(3)
})
// test('elements are filtered correctly', () => {
// })
// test('elements are grouped correctly', () => {
test('elements are filtered correctly', () => {
// })
let data = List([
{ name: 'Jack' },
{ name: 'Mark' },
{ name: 'Alice' }
])
let filters = List([new Filter(
'name',
(value) => (value == null ? '' : value.toString()).toUpperCase().includes('Ja'.toUpperCase())
)])
let columns = List([new BaseColumn(
new BaseColumn({
id: 'name',
valueGetter: (e) => e.name
})
)])
let result = Engine.computeElements(data, List(), List(), filters, columns, false, false, null)
expect(result.size).toBe(1)
expect(result.get(0).content.name).toBe('Jack')
})
test('elements are filtered correctly with two filters', () => {
let data = List([
{ name: 'Jack' },
{ name: 'Mark' },
{ name: 'Alice' }
])
let filters = List([
new Filter(
'name',
(value) => (value == null ? '' : value.toString()).toUpperCase().includes('a'.toUpperCase())
),
new Filter(
'name',
(value) => (value == null ? '' : value.toString()).toUpperCase().includes('k'.toUpperCase())
),
])
let columns = List([new BaseColumn(
new BaseColumn({
id: 'name',
valueGetter: (e) => e.name
})
)])
let result = Engine.computeElements(data, List(), List(), filters, columns, false, false, null)
expect(result.size).toBe(2)
expect(result.get(0).content.name).toBe('Jack')
expect(result.get(1).content.name).toBe('Mark')
})
test('elements are grouped correctly', () => {
let data = List([
{ name: 'Jack', gender: 'Male' },
{ name: 'Alice', gender: 'Female' },
{ name: 'Mark', gender: 'Male' }
])
let groups = List([
new Group({
id: 'gender',
groupingFunction: e => e.gender
})
])
let columns = List([new BaseColumn(
new BaseColumn({
id: 'name',
valueGetter: (e) => e.position
}),
new BaseColumn({
id: 'gender',
valueGetter: (e) => e.gender
})
)])
let result = Engine.computeElements(data, groups, List(), List(), columns, false, false, null)
expect(result.get(0).content.name).toBe('Alice')
expect(result.get(1).content.name).toBe('Jack')
expect(result.get(2).content.name).toBe('Mark')
})

0 comments on commit a7b794c

Please sign in to comment.