blob: 4ce26be249d6b70efec37903c77174e8567c3ce8 [file] [log] [blame]
Matteo Scandoloef969922016-08-11 13:49:12 -07001'use strict';
2
3describe('The ResponseHandler service', () => {
4
5 var ResponseHandler, done;
6
7 beforeEach(module('xos.UITutorial'));
8 beforeEach(module('templates'));
9
10 beforeEach(inject(function (_ResponseHandler_) {
11 // The injector unwraps the underscores (_) from around the parameter names when matching
12 ResponseHandler = _ResponseHandler_;
13 done = jasmine.createSpy('done');
14 }));
15
16 describe('the parse method', () => {
17 it('should return an html template for a collection', () => {
18 const collection = [
19 {id: 1, deleted: true, name: 'one'},
20 {id: 2, deleted: true, name: 'two'}
21 ];
22
23 const collectionHtml = `
24 <div>
25 <p>Corresponding js code: <code>jsCode</code></p>
26 <div class="json"><div class="jsonCollection">[<div class="jsonObject">{"id":1,"name":"one"},</code></div><div class="jsonObject">{"id":2,"name":"two"}</code></div>]</div></div>
27 </div>
28 `;
29 ResponseHandler.parse(collection, 'jsCode', done);
30 expect(done).toHaveBeenCalledWith(collectionHtml)
31 });
32
33 it('should return an html template for an object', () => {
34 const object = {id: 1, deleted: true, name: 'one'};
35
36 const objectHtml = `
37 <div>
38 <p>Corresponding js code: <code></code></p>
39 <div class="json"><div class="jsonObject">{"id":1,"name":"one"}</code></div></div>
40 </div>
41 `;
42 ResponseHandler.parse(object, '', done);
43 expect(done).toHaveBeenCalledWith(objectHtml)
44 });
45 });
46});