This repository was archived by the owner on Dec 18, 2024. It is now read-only.
Commit 3ade702 1 parent 45c0d75 commit 3ade702 Copy full SHA for 3ade702
File tree 4 files changed +35
-5
lines changed
4 files changed +35
-5
lines changed Original file line number Diff line number Diff line change @@ -10,14 +10,21 @@ export class View {
10
10
}
11
11
12
12
activate ( params , routeConfig ) {
13
- return this . newsService . get ( params . id )
13
+ let user = this . authService . getMe ( )
14
+ . then ( user => {
15
+ this . user = user ;
16
+ } ) ;
17
+
18
+ let news = this . newsService . get ( params . id )
14
19
. then ( news => {
15
20
this . news = news ;
16
21
routeConfig . navModel . setTitle ( news . title ) ;
17
22
} )
18
23
. catch ( ( ) => {
19
24
this . news = null ;
20
25
} ) ;
26
+
27
+ return Promise . all ( [ user , news ] ) ;
21
28
}
22
29
23
30
get isAuthenticated ( ) {
Original file line number Diff line number Diff line change @@ -23,9 +23,8 @@ <h4><a href="#/news/view/${news.id}">${news.title}</a></h4>
23
23
</ div >
24
24
< div class ="card-footer " if.bind ="isAuthenticated ">
25
25
< div class ="news-card-comment " if.bind ="isAuthenticated ">
26
- <!-- Todo: add logged in user data -->
27
- < a href ="#/profiles/view/${news.user_id} " class ="pull-left ">
28
- < img alt ="${news.user.username} " src ="http://lr.local/img/avatar/${news.user.avatar} ">
26
+ < a href ="#/profiles/view/${user.user_id} " class ="pull-left ">
27
+ < img alt ="${user.username} " src ="http://lr.local/img/avatar/${user.avatar} ">
29
28
</ a >
30
29
< div class ="media-body ">
31
30
< textarea class ="form-control " placeholder ="Write comment... "> </ textarea >
Original file line number Diff line number Diff line change
1
+ export class AuthServiceStub {
2
+ requestDummy ;
3
+ reject = false ;
4
+
5
+ getMe ( resource , options = { } ) {
6
+ this . resource = resource ;
7
+ this . options = options ;
8
+
9
+ return new Promise ( ( resolve , reject ) => {
10
+ if ( this . reject == false ) {
11
+ resolve ( this . requestDummy ) ;
12
+ } else {
13
+ reject ( ) ;
14
+ }
15
+ } ) ;
16
+ }
17
+ }
Original file line number Diff line number Diff line change 1
1
import { Index } from '../../../src/view-models/news/index' ;
2
2
import { View } from '../../../src/view-models/news/view' ;
3
3
4
+ import { AuthServiceStub } from '../fixtures/AuthServiceStub' ;
4
5
import { NewsServiceStub } from '../fixtures/NewsServiceStub' ;
5
6
import { NavModelStub } from '../fixtures/NavModelStub' ;
6
7
@@ -50,20 +51,26 @@ describe('the News Index module', () => {
50
51
51
52
describe ( 'the News View module' , ( ) => {
52
53
var newsService ;
54
+ var authService ;
53
55
var sut ;
54
56
55
57
var itemStubs = [ 1 ] ;
56
58
var itemFake = [ 2 ] ;
57
59
58
60
beforeEach ( ( ) => {
61
+ authService = new AuthServiceStub ( ) ;
59
62
newsService = new NewsServiceStub ( ) ;
60
- sut = new View ( newsService ) ;
63
+ sut = new View ( newsService , authService ) ;
61
64
} ) ;
62
65
63
66
it ( 'contains a news service property' , ( ) => {
64
67
expect ( sut . newsService ) . toBeDefined ( ) ;
65
68
} ) ;
66
69
70
+ it ( 'contains an auth service property' , ( ) => {
71
+ expect ( sut . authService ) . toBeDefined ( ) ;
72
+ } ) ;
73
+
67
74
it ( 'sets fetch response to selected news' , done => {
68
75
newsService . itemStub = itemStubs ;
69
76
let navModelStub = new NavModelStub ( ) ;
You can’t perform that action at this time.
0 commit comments