@@ -2,28 +2,60 @@ var app = require('../app'),
22 assert = require ( 'assert' ) ,
33 request = require ( 'supertest' ) ,
44 sinon = require ( 'sinon' ) ;
5- jsdom = require ( "jsdom" ) ;
5+ jsdom = require ( "jsdom" ) ;
66
77
88describe ( 'lirc_web' , function ( ) {
99
1010 describe ( 'routes' , function ( ) {
1111
12+ // Root route
1213 it ( 'should have an index route "/"' , function ( done ) {
1314 assert ( request ( app ) . get ( '/' ) . expect ( 200 , done ) ) ;
1415 } ) ;
1516
16- it ( 'should have a POST route for sending a command' , function ( done ) {
17+
18+ // JSON API
19+ it ( 'should have GET route for JSON list of macros' , function ( done ) {
20+ assert ( request ( app ) . get ( '/macros.json' ) . expect ( 200 , done ) ) ;
21+ } ) ;
22+
23+ it ( 'should have GET route for JSON list of remotes' , function ( done ) {
24+ assert ( request ( app ) . get ( '/remotes.json' ) . expect ( 200 , done ) ) ;
25+ } ) ;
26+
27+ it ( 'should have GET route for JSON list of commands for remote' , function ( done ) {
28+ assert ( request ( app ) . get ( '/remotes/Xbox360.json' ) . expect ( 200 , done ) ) ;
29+ } ) ;
30+
31+ it ( 'should have GET route for JSON list of commands for macro' , function ( done ) {
32+ assert ( request ( app ) . get ( '/macros/Play%20Xbox%20360.json' ) . expect ( 200 , done ) ) ;
33+ } ) ;
34+
35+ it ( 'should return 404 for unknown remote' , function ( done ) {
36+ assert ( request ( app ) . get ( '/remotes/DOES_NOT_EXIST.json' ) . expect ( 404 , done ) ) ;
37+ } ) ;
38+
39+
40+ // Sending commands
41+ it ( 'should have POST route for sending a command' , function ( done ) {
1742 assert ( request ( app ) . post ( '/remotes/tv/power' ) . expect ( 200 , done ) ) ;
1843 } ) ;
1944
20- it ( 'should have a POST route to start repeatedly sending a command' , function ( done ) {
45+ it ( 'should have POST route to start repeatedly sending a command' , function ( done ) {
2146 assert ( request ( app ) . post ( '/remotes/tv/volumeup/send_start' ) . expect ( 200 , done ) ) ;
2247 } ) ;
2348
24- it ( 'should have a POST route to stop repeatedly sending a command' , function ( done ) {
49+ it ( 'should have POST route to stop repeatedly sending a command' , function ( done ) {
2550 assert ( request ( app ) . post ( '/remotes/tv/volumeup/send_stop' ) . expect ( 200 , done ) ) ;
2651 } ) ;
52+
53+
54+ // Sending macros
55+ it ( 'should have POST route for sending a macro' , function ( done ) {
56+ assert ( request ( app ) . post ( '/macros/xbox_360' ) . expect ( 200 , done ) ) ;
57+ } ) ;
58+
2759 } ) ;
2860
2961 describe ( 'index action' , function ( ) {
@@ -32,52 +64,53 @@ describe('lirc_web', function() {
3264 assert ( request ( app ) . get ( '/' ) . expect ( 'Content-Type' , / h t m l / , done ) ) ;
3365 } ) ;
3466
35- it ( 'should return an HTML document in which all button elements of class command-link have an href of the form /remotes/:remote/:command' , function ( done ) {
36- request ( app )
37- . get ( '/' )
38- . end ( function ( err , res ) {
39- assert . equal ( err , null ) ;
40- jsdom . env ( res . text , [ "http://code.jquery.com/jquery.js" ] , function ( errors , window ) {
41- var $ = window . $ ;
42- $ ( "button.command-link" ) . each ( function ( idx , elem ) {
43- var s = $ ( elem ) . attr ( 'href' ) . split ( "/" ) ;
44- assert . equal ( 4 , s . length ) ;
45- assert . equal ( "" , s [ 0 ] ) ;
46- assert . equal ( "remotes" , s [ 1 ] ) ;
47- } ) ;
48- done ( ) ;
49- } ) ;
50- } ) ;
51- } ) ;
67+ it ( 'should return an HTML document in which all button elements of class command-link have an href of the form /remotes/:remote/:command' , function ( done ) {
68+ request ( app )
69+ . get ( '/' )
70+ . end ( function ( err , res ) {
71+ assert . equal ( err , null ) ;
72+ // TODO: Remove external dependency so offline development and testing is possible
73+ jsdom . env ( res . text , [ "http://code.jquery.com/jquery.js" ] , function ( errors , window ) {
74+ var $ = window . $ ;
75+ $ ( "button.command-link" ) . each ( function ( idx , elem ) {
76+ var s = $ ( elem ) . attr ( 'href' ) . split ( "/" ) ;
77+ assert . equal ( 4 , s . length ) ;
78+ assert . equal ( "" , s [ 0 ] ) ;
79+ assert . equal ( "remotes" , s [ 1 ] ) ;
80+ } ) ;
81+ done ( ) ;
82+ } ) ;
83+ } ) ;
84+ } ) ;
5285 } ) ;
5386
5487 describe ( 'json api' , function ( ) {
55- it ( 'should return a list of all remotes (and commands) when /remotes.json is accessed' , function ( done ) {
56- request ( app )
57- . get ( '/remotes.json' )
58- . end ( function ( err , res ) {
59- assert . equal ( res . status , 200 ) ;
60- done ( ) ;
61- } ) ;
62- } ) ;
63-
64- it ( 'should return a list of all commands for a remote when /remotes/:remote.json is accessed' , function ( done ) {
65- request ( app )
66- . get ( '/remotes/Microsoft_Xbox360.json' )
67- . end ( function ( err , res ) {
68- assert . equal ( res . status , 200 ) ;
69- done ( ) ;
70- } ) ;
71- } ) ;
88+ it ( 'should return a list of all remotes (and commands) when /remotes.json is accessed' , function ( done ) {
89+ request ( app )
90+ . get ( '/remotes.json' )
91+ . end ( function ( err , res ) {
92+ assert . equal ( res . status , 200 ) ;
93+ done ( ) ;
94+ } ) ;
95+ } ) ;
7296
73- it ( 'should return a 404 for an unknown remote' , function ( done ) {
97+ it ( 'should return a list of all commands for a remote when /remotes/: remote.json is accessed ' , function ( done ) {
7498 request ( app )
75- . get ( '/remotes/DOES_NOT_EXIST.json' )
76- . end ( function ( err , res ) {
77- assert . equal ( res . status , 404 ) ;
78- done ( ) ;
79- } ) ;
80- } ) ;
99+ . get ( '/remotes/Xbox360.json' )
100+ . end ( function ( err , res ) {
101+ assert . equal ( res . status , 200 ) ;
102+ done ( ) ;
103+ } ) ;
104+ } ) ;
105+
106+ it ( 'should return a 404 for an unknown remote' , function ( done ) {
107+ request ( app )
108+ . get ( '/remotes/DOES_NOT_EXIST.json' )
109+ . end ( function ( err , res ) {
110+ assert . equal ( res . status , 404 ) ;
111+ done ( ) ;
112+ } ) ;
113+ } ) ;
81114 } ) ;
82115
83116} ) ;
0 commit comments