Matteo Scandolo | 7dea243 | 2016-03-24 15:11:29 -0700 | [diff] [blame] | 1 | /** |
| 2 | * © OpenCORD |
| 3 | * |
| 4 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 5 | * |
| 6 | * Created by teone on 3/24/16. |
| 7 | */ |
| 8 | |
| 9 | (function () { |
| 10 | 'use strict'; |
| 11 | |
Matteo Scandolo | 9e6c6fc | 2016-04-14 14:59:09 -0700 | [diff] [blame] | 12 | describe('The xos.helper module', function(){ |
| 13 | describe('The NoHyperlinks factory', () => { |
Matteo Scandolo | 7dea243 | 2016-03-24 15:11:29 -0700 | [diff] [blame] | 14 | |
Matteo Scandolo | 9e6c6fc | 2016-04-14 14:59:09 -0700 | [diff] [blame] | 15 | let httpProviderObj, httpBackend, http, noHyperlinks; |
Matteo Scandolo | 7dea243 | 2016-03-24 15:11:29 -0700 | [diff] [blame] | 16 | |
Matteo Scandolo | 9e6c6fc | 2016-04-14 14:59:09 -0700 | [diff] [blame] | 17 | beforeEach(() => { |
| 18 | module( |
| 19 | 'xos.helpers', |
| 20 | ($httpProvider) => { |
| 21 | //save our interceptor |
| 22 | httpProviderObj = $httpProvider; |
| 23 | } |
| 24 | ); |
Matteo Scandolo | 7dea243 | 2016-03-24 15:11:29 -0700 | [diff] [blame] | 25 | |
Matteo Scandolo | 9e6c6fc | 2016-04-14 14:59:09 -0700 | [diff] [blame] | 26 | inject(function (_$httpBackend_, _$http_, _NoHyperlinks_) { |
| 27 | httpBackend = _$httpBackend_; |
| 28 | http = _$http_; |
| 29 | noHyperlinks = _NoHyperlinks_ |
| 30 | }); |
| 31 | |
| 32 | httpProviderObj.interceptors.push('NoHyperlinks'); |
| 33 | |
Matteo Scandolo | 7dea243 | 2016-03-24 15:11:29 -0700 | [diff] [blame] | 34 | }); |
| 35 | |
Matteo Scandolo | 9e6c6fc | 2016-04-14 14:59:09 -0700 | [diff] [blame] | 36 | it('should set NoHyperlinks interceptor', () => { |
| 37 | expect(httpProviderObj.interceptors).toContain('NoHyperlinks'); |
| 38 | }); |
| 39 | |
| 40 | it('should attach ?no_hyperlinks=1 to the request url', () => { |
| 41 | let result = noHyperlinks.request({url: 'sample.url'}); |
| 42 | expect(result.url).toEqual('sample.url?no_hyperlinks=1'); |
| 43 | }); |
| 44 | |
| 45 | it('should NOT attach ?no_hyperlinks=1 to the request url if is HTML', () => { |
| 46 | let result = noHyperlinks.request({url: 'sample.html'}); |
| 47 | expect(result.url).toEqual('sample.html'); |
| 48 | }); |
Matteo Scandolo | 7dea243 | 2016-03-24 15:11:29 -0700 | [diff] [blame] | 49 | |
| 50 | }); |
Matteo Scandolo | 7dea243 | 2016-03-24 15:11:29 -0700 | [diff] [blame] | 51 | }); |
| 52 | })(); |
| 53 | |