Skip to content

Commit

Permalink
chore(context): add more unit tests for binding filters
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Jan 31, 2019
1 parent 0121c10 commit 181e1f1
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions packages/context/test/unit/binding-filter.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,51 @@ describe('BindingFilter', () => {
expect(filter(binding)).to.be.false();
});

// TODO: filter by tag map, filter by regexp
it('accepts bindings MATCHING the provided tag regexp', () => {
const filter = filterByTag(/^c/);
binding.tag('controller');
expect(filter(binding)).to.be.true();
});

it('rejects bindings NOT MATCHING the provided tag regexp', () => {
const filter = filterByTag(/^c/);
binding.tag('dataSource');
expect(filter(binding)).to.be.false();
});

it('accepts bindings MATCHING the provided tag map', () => {
const filter = filterByTag({controller: 'my-controller'});
binding.tag({controller: 'my-controller'});
binding.tag({name: 'my-controller'});
expect(filter(binding)).to.be.true();
});

it('accepts bindings MATCHING the provided tag map with multiple tags', () => {
const filter = filterByTag({
controller: 'my-controller',
name: 'my-name',
});
binding.tag({controller: 'my-controller'});
binding.tag({name: 'my-name'});
expect(filter(binding)).to.be.true();
});

it('rejects bindings NOT MATCHING the provided tag map', () => {
const filter = filterByTag({controller: 'your-controller'});
binding.tag({controller: 'my-controller'});
binding.tag({name: 'my-controller'});
expect(filter(binding)).to.be.false();
});

it('rejects bindings NOT MATCHING the provided tag map with multiple tags', () => {
const filter = filterByTag({
controller: 'my-controller',
name: 'my-name',
});
binding.tag({controller: 'my-controller'});
binding.tag({name: 'my-controller'});
expect(filter(binding)).to.be.false();
});
});

describe('filterByKey', () => {
Expand All @@ -39,7 +83,25 @@ describe('BindingFilter', () => {
expect(filter(binding)).to.be.false();
});

// TODO: filter by regexp, filter by BindingFunction
it('accepts bindings MATCHING the provided key regexp', () => {
const filter = filterByKey(/f.*/);
expect(filter(binding)).to.be.true();
});

it('rejects bindings NOT MATCHING the provided key regexp', () => {
const filter = filterByKey(/^ba/);
expect(filter(binding)).to.be.false();
});

it('accepts bindings MATCHING the provided filter', () => {
const filter = filterByKey(b => b.key === key);
expect(filter(binding)).to.be.true();
});

it('rejects bindings NOT MATCHING the provided filter', () => {
const filter = filterByKey(b => b.key !== key);
expect(filter(binding)).to.be.false();
});
});

function givenBinding() {
Expand Down

0 comments on commit 181e1f1

Please sign in to comment.