summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@codeispoetry.ru>2017-06-05 14:51:29 +0300
committerAndrej Mihajlov <and@codeispoetry.ru>2017-06-05 19:19:04 +0300
commit073f5e242261acaaad1aecb00b1301b34c073db1 (patch)
treed5d428b2e22a6e7c12b8685738ccc323284cf645 /test
parent796c4a4503568f7a25a55960ff236c22072e81a7 (diff)
downloadmullvadvpn-073f5e242261acaaad1aecb00b1301b34c073db1.tar.xz
mullvadvpn-073f5e242261acaaad1aecb00b1301b34c073db1.zip
Add tests for TransitionRule
Diffstat (limited to 'test')
-rw-r--r--test/transition-rule.spec.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/transition-rule.spec.js b/test/transition-rule.spec.js
new file mode 100644
index 0000000000..ba5ea15e64
--- /dev/null
+++ b/test/transition-rule.spec.js
@@ -0,0 +1,48 @@
+// @flow
+import { expect } from 'chai';
+import TransitionRule from '../app/lib/transition-rule';
+
+describe('TransitionRule', () => {
+ const testTransition = {
+ forward: { name: 'forward', duration: 0.25 },
+ backward: { name: 'backward', duration: 0.25 }
+ };
+
+ it('should match wildcard rule', () => {
+ const rule = new TransitionRule(null, '/route', testTransition);
+
+ expect(rule.match(null, '/route')).to.be.true;
+ expect(rule.transitionDescriptor().name).to.be.equal('forward');
+
+ expect(rule.match('/somewhere', '/route')).to.be.true;
+ expect(rule.transitionDescriptor().name).to.be.equal('forward');
+ });
+
+ it('should match wildcard rule reversion', () => {
+ const rule = new TransitionRule(null, '/route', testTransition);
+
+ expect(rule.match('/route', '/other')).to.be.true;
+ expect(rule.transitionDescriptor().name).to.be.equal('backward');
+ });
+
+ it('should match exact rule', () => {
+ const rule = new TransitionRule('/route1', '/route2', testTransition);
+
+ expect(rule.match('/other', '/route1')).to.be.false;
+ expect(rule.match('/other', '/route2')).to.be.false;
+
+ expect(rule.match('/route1', '/route2')).to.be.true;
+ expect(rule.transitionDescriptor().name).to.be.equal('forward');
+ });
+
+ it('should match exact rule reversion', () => {
+ const rule = new TransitionRule('/route1', '/route2', testTransition);
+
+ expect(rule.match('/route1', '/other')).to.be.false;
+ expect(rule.match('/route2', '/other')).to.be.false;
+
+ expect(rule.match('/route2', '/route1')).to.be.true;
+ expect(rule.transitionDescriptor().name).to.be.equal('backward');
+ });
+
+}); \ No newline at end of file