From 181e1f11cbe2e493c97d2c9db1c721d7d2497ad7 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Thu, 31 Jan 2019 07:59:24 -0800 Subject: [PATCH] chore(context): add more unit tests for binding filters --- .../context/test/unit/binding-filter.unit.ts | 66 ++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/packages/context/test/unit/binding-filter.unit.ts b/packages/context/test/unit/binding-filter.unit.ts index 7d7ae14ac645..af414352ec3c 100644 --- a/packages/context/test/unit/binding-filter.unit.ts +++ b/packages/context/test/unit/binding-filter.unit.ts @@ -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', () => { @@ -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() {