mocks.ts
3.47 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const DEBUG = false;
let log = (message: string, ...args: any[]) => {
if (DEBUG) {
console.log(message);
}
};
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, ...args: any[]) {
log("Emitted " + message);
if ((<any>this.listeners)[message]) {
log("LISTENERS:", (<any>this.listeners)[message]);
(<any>this.listeners)[message].forEach((f: Function) => {
f.apply(this, args);
});
}
}
}
export var mocks = {
scopeWithEvents: (): 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
}
});
}
};
},
getArticleByProfileAndPath: (profile: noosfero.Profile, path: string) => {
return {
then: (func?: Function) => {
if (func) func({
data: {
article: null
}
});
}
};
},
getChildren: (articleId: number, params?: any) => {
return {
then: (func?: Function) => { if (func) func(); }
};
}
},
environmentService: {
getEnvironmentPeople: (params: any) => {
return mocks.promiseResultTemplate({
people: {}
});
}
},
profileService: {
getCurrentProfile: (profile: any) => {
return mocks.promiseResultTemplate({
profile: profile
});
},
instant: () => { }
},
commentService: {
getByArticle: (article: noosfero.Article) => {
return Promise.resolve({ data: {} });
}
},
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: () => { }
},
translatorService: {
currentLanguage: () => { },
changeLanguage: (lang: string) => { },
translate: (text: string) => { return text; }
},
notificationService: {
success: () => { }
}
};