1+ "use strict" ;
2+
3+ describe ( "Storyiew" , function ( ) {
4+ it ( "should exist" , function ( ) {
5+ StoryView . should . exist ;
6+ } ) ;
7+
8+ describe ( "Rendering the view" , function ( ) {
9+ before ( function ( ) {
10+ this . story = new Story ( {
11+ source : "TechKrunch" ,
12+ headline : "Every startups acquired by Yahoo!" ,
13+ lead : "This is the lead." ,
14+ title : "Every startups acquired by Yahoo! NOT!!" ,
15+ body : "All remote workers have been exiled to Ohio." ,
16+ pretty_date : "Mon July 1, 2013" ,
17+ permalink : "http://example.com/krunch" ,
18+ keep_unread : false ,
19+ is_read : false
20+ } ) ;
21+
22+ this . view = new StoryView ( { model : this . story } )
23+
24+ this . view . render ( ) ;
25+ } ) ;
26+
27+ it ( "should render li.story items" , function ( ) {
28+ this . view . $el . hasClass ( "story" ) . should . be . true ;
29+ } ) ;
30+
31+ var assertTagExists = function ( el , tagName ) {
32+ el . find ( tagName ) . should . have . length ( 1 ) ;
33+ } ;
34+
35+ var assertPropertyRendered = function ( el , model , propName ) {
36+ el . html ( ) . should . have . string ( model . get ( propName ) ) ;
37+ } ;
38+
39+ it ( "should render blog title" , function ( ) {
40+ assertTagExists ( this . view . $el , ".blog-title" ) ;
41+ assertPropertyRendered ( this . view . $el , this . story , "source" ) ;
42+ } ) ;
43+
44+ it ( "should render story headline" , function ( ) {
45+ assertTagExists ( this . view . $el , ".story-title" ) ;
46+ assertPropertyRendered ( this . view . $el , this . story , "headline" ) ;
47+ } ) ;
48+
49+ it ( "should render story lead" , function ( ) {
50+ assertTagExists ( this . view . $el , ".story-lead" ) ;
51+ assertPropertyRendered ( this . view . $el , this . story , "lead" ) ;
52+ } ) ;
53+
54+ it ( "should render story full title" , function ( ) {
55+ assertTagExists ( this . view . $el , ".story-body" ) ;
56+ assertPropertyRendered ( this . view . $el , this . story , "title" ) ;
57+ } ) ;
58+
59+ it ( "should render story full title as link" , function ( ) {
60+ assertTagExists ( this . view . $el , ".story-body h1 a" ) ;
61+ } ) ;
62+
63+ it ( "should render story full body" , function ( ) {
64+ assertTagExists ( this . view . $el , ".story-body" ) ;
65+ assertPropertyRendered ( this . view . $el , this . story , "body" ) ;
66+ } ) ;
67+
68+ it ( "should render story date" , function ( ) {
69+ assertTagExists ( this . view . $el , ".story-published" ) ;
70+ assertPropertyRendered ( this . view . $el , this . story , "pretty_date" ) ;
71+ } ) ;
72+
73+ it ( "should render story permalink" , function ( ) {
74+ assertTagExists ( this . view . $el , ".story-permalink" ) ;
75+ assertPropertyRendered ( this . view . $el , this . story , "permalink" ) ;
76+ } ) ;
77+
78+ it ( "should render keep as unread button" , function ( ) {
79+ assertTagExists ( this . view . $el , ".story-keep-unread" ) ;
80+ } ) ;
81+
82+ it ( "should autofill unread button based on item" , function ( ) {
83+ assertTagExists ( this . view . $el , ".story-keep-unread .icon-check-empty" ) ;
84+
85+ this . story . set ( "keep_unread" , true ) ;
86+ this . view . render ( ) ;
87+
88+ assertTagExists ( this . view . $el , ".story-keep-unread .icon-check" ) ;
89+ } ) ;
90+ } ) ;
91+ } ) ;
0 commit comments