2020-03-29 14:52:40 +00:00
|
|
|
import { expect } from 'chai';
|
2021-07-25 00:41:28 +00:00
|
|
|
import { array, constant, integer, record } from 'fast-check';
|
|
|
|
import { over } from 'mocha-foam';
|
2020-03-29 14:52:40 +00:00
|
|
|
|
2020-03-31 13:29:47 +00:00
|
|
|
import { Checklist, ChecklistMode } from '../../src/Checklist';
|
2020-03-29 14:52:40 +00:00
|
|
|
|
|
|
|
const EXISTING_ITEM = 'foo';
|
|
|
|
const MISSING_ITEM = 'bin';
|
|
|
|
const TEST_DATA = [EXISTING_ITEM, 'bar'];
|
|
|
|
|
|
|
|
// tslint:disable:no-duplicate-functions
|
2020-06-30 13:14:30 +00:00
|
|
|
describe('checklist', async () => {
|
|
|
|
describe('exclude mode', async () => {
|
|
|
|
it('should check for present values', async () => {
|
2020-03-29 14:52:40 +00:00
|
|
|
const list = new Checklist({
|
|
|
|
data: TEST_DATA,
|
|
|
|
mode: ChecklistMode.EXCLUDE,
|
|
|
|
});
|
|
|
|
expect(list.check(EXISTING_ITEM)).to.equal(false);
|
|
|
|
});
|
|
|
|
|
2020-06-30 13:14:30 +00:00
|
|
|
it('should check for missing values', async () => {
|
2020-03-29 14:52:40 +00:00
|
|
|
const list = new Checklist({
|
|
|
|
data: TEST_DATA,
|
|
|
|
mode: ChecklistMode.EXCLUDE,
|
|
|
|
});
|
|
|
|
expect(list.check(MISSING_ITEM)).to.equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-30 13:14:30 +00:00
|
|
|
describe('include mode', async () => {
|
|
|
|
it('should check for present values', async () => {
|
2020-03-29 14:52:40 +00:00
|
|
|
const list = new Checklist<string>({
|
|
|
|
data: TEST_DATA,
|
|
|
|
mode: ChecklistMode.INCLUDE,
|
|
|
|
});
|
|
|
|
expect(list.check(EXISTING_ITEM)).to.equal(true);
|
|
|
|
});
|
|
|
|
|
2020-06-30 13:14:30 +00:00
|
|
|
it('should check for missing values', async () => {
|
2020-03-29 14:52:40 +00:00
|
|
|
const list = new Checklist<string>({
|
|
|
|
data: TEST_DATA,
|
|
|
|
mode: ChecklistMode.INCLUDE,
|
|
|
|
});
|
|
|
|
expect(list.check(MISSING_ITEM)).to.equal(false);
|
|
|
|
});
|
|
|
|
});
|
2021-07-25 00:41:28 +00:00
|
|
|
|
|
|
|
over('arrays of numbers', record({
|
|
|
|
data: array(integer()),
|
|
|
|
mode: constant(ChecklistMode.EXCLUDE),
|
|
|
|
}), (it) => {
|
|
|
|
it('should exclude the data items', (options) => {
|
|
|
|
const list = new Checklist(options);
|
|
|
|
for (const val of options.data) {
|
|
|
|
expect(list.check(val)).to.equal(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2020-03-29 14:52:40 +00:00
|
|
|
});
|