summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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