mocks.ts
2.59 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
class ScopeWithEvents {
listeners = {};
constructor() {
}
public $on(eventName: string, func: Function) {
if ((<any>this.listeners)[eventName]) {
(<any>this.listeners)[eventName].push(func);
} else {
(<any>this.listeners)[eventName] = [func];
}
}
public $emit(message: string, arg?: any) {
console.log("Emitted " + message);
if ((<any>this.listeners)[message]) {
console.log("LISTENERS:", (<any>this.listeners)[message]);
(<any>this.listeners)[message].forEach((f: Function) => {
f(arg);
});
}
}
}
export var mocks = {
scopeWithEvents: new ScopeWithEvents(),
modalInstance: {
close: () => { }
},
$modal: {
open: (args: {}) => {
return this.modalInstance;
}
},
authService: {
logout: () => { }
},
articleService: {
getByProfile: (profileId: number, params?: any) => {
return {
then: (func?: Function) => {
if (func) func({
data: {
article: null
}
});
}
};
},
getChildren: (articleId: number, params?: any) => {
return {
then: (func?: Function) => { if (func) func(); }
};
}
},
profileService: {
getCurrentProfile: (profile: any) => {
return mocks.promiseResultTemplate({
profile: profile
});
},
instant: () => { }
},
sessionWithCurrentUser: (user: any) => {
return {
currentUser: () => { return user; }
};
},
$translate: {
use: (lang?: string) => {
return lang ? Promise.resolve(lang) : "en";
},
instant: (text: string) => { return text }
},
tmhDynamicLocale: {
get: () => { },
set: (lang: string) => { }
},
amMoment: {
changeLocale: () => { }
},
angularLoad: {
loadScript: (script?: string) => {
return Promise.resolve();
}
},
promiseResultTemplate: (response?: {}) => {
return {
then: (func?: (response: any) => void) => {
if (func) { return func(response); }
}
};
},
$log: {
debug: () => { }
},
languageService: {
currentLanguage: () => { },
changeLanguage: (lang: string) => { },
translate: (text: string) => { return text }
}
};