-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcommon.js
89 lines (77 loc) · 2.13 KB
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
import { ReactiveVar } from 'meteor/reactive-var';
if (Meteor.isServer) {
return;
}
const defaultTitleStr = 'Default title';
const defaultNewTitleStr = 'Default NEW title';
const defaultReactiveTitle = new ReactiveVar(defaultTitleStr);
FlowRouter.globals.push({
title() {
return defaultReactiveTitle.get();
}
});
FlowRouter.route('/', {
name: 'index',
action() {
Meteor.setTimeout(() => {
defaultReactiveTitle.set(defaultNewTitleStr);
}, 50);
}
});
FlowRouter.route('/secondPage', {
name: 'secondPage',
title: 'Second Page title',
action() {}
});
FlowRouter.route('/thirdPage/:something', {
name: 'thirdPage',
title() {
return 'Third Page Title > ' + this.params.something;
},
action() {}
});
Tinytest.addAsync('COMMON - Global Defaults', function (test, next) {
FlowRouter.go('/');
test.equal(document.title, defaultTitleStr);
setTimeout(() => {
test.equal(document.title, defaultNewTitleStr);
next();
}, 100);
});
Tinytest.addAsync('COMMON - Title - String', function (test, next) {
FlowRouter.go('secondPage');
setTimeout(() => {
test.equal(document.title, 'Second Page title');
next();
}, 100);
});
Tinytest.addAsync('COMMON - Title - Function with dynamic data', function (test, next) {
const _str = Random.id();
FlowRouter.go('thirdPage', {something: _str});
setTimeout(() => {
test.equal(document.title, 'Third Page Title > ' + _str);
next();
}, 100);
});
Tinytest.addAsync('COMMON - 404 via FlowRouter.notFound', function (test, next) {
FlowRouter.go('/not/exists/for/sure');
setTimeout(() => {
test.equal(document.title, '404: Page not found');
next();
}, 100);
});
Tinytest.addAsync('COMMON - .set() Method', function (test, next) {
const _title = 'Title set via .set() method';
Meteor.__test.titleHandler.set(_title);
setTimeout(() => {
test.equal(document.title, _title);
next();
}, 25);
});
FlowRouter.route('*', {
action() {},
title: '404: Page not found'
});