summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@codeispoetry.ru>2017-06-07 21:02:17 +0300
committerAndrej Mihajlov <and@codeispoetry.ru>2017-06-07 21:02:17 +0300
commit829a8cee89d35b1e485849fa3d2459fa45ab59db (patch)
treed5d428b2e22a6e7c12b8685738ccc323284cf645
parent796c4a4503568f7a25a55960ff236c22072e81a7 (diff)
parent073f5e242261acaaad1aecb00b1301b34c073db1 (diff)
downloadmullvadvpn-829a8cee89d35b1e485849fa3d2459fa45ab59db.tar.xz
mullvadvpn-829a8cee89d35b1e485849fa3d2459fa45ab59db.zip
Merge branch 'feature/transition-rule-tests'
-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