import {ISuperdeskGlobalConfig} from 'superdesk-api'; import {appConfig} from 'appConfig'; describe('Embed Code Handlers', () => { var ctrl, scope; beforeEach(() => { const testConfig: Partial = { server: {url: undefined, ws: undefined}, iframely: {key: '123'}, editor: {}, }; Object.assign(appConfig, testConfig); }); beforeEach(window.module('superdesk.apps.editor2')); beforeEach(window.module('superdesk.apps.vocabularies')); beforeEach(window.module('superdesk.apps.searchProviders')); beforeEach(inject(($controller, $rootScope) => { var element = angular.element('
'); scope = $rootScope.$new(); ctrl = $controller('SdAddEmbedController', {$scope: scope, $element: element}); })); it('match a twitter url', inject(($rootScope, $q, $httpBackend, embedService) => { ctrl.input = 'https://twitter.com/letzi83/status/764062125996113921'; jasmine.createSpy(embedService, 'get').and.returnValue($q.when({ meta: {site: 'Twitter'}, html: 'embed', })); $httpBackend.whenJSONP(/https:\/\/iframe\.ly\/api\/.*/).respond(400); $httpBackend.whenGET(/https:\/\/iframe\.ly\/api\/.*/).respond(400); ctrl.retrieveEmbed().then((d) => { expect(d).toEqual({ body: 'embed', provider: 'Twitter', }); }); $rootScope.$digest(); })); it('match a twitter embed', () => { ctrl.input = '

' + 'A bit old, but I just got around to ready it: "This Is What a Feminist Looks Like"' + ' according to #Obama: https://t.co/GLm1YW1U0o

— Letizia Gambini (@letzi83) ' + '12 août 2016
' + ''; ctrl.retrieveEmbed().then((d) => { expect(d).toEqual({ body: ctrl.input, provider: 'Twitter', }); }); scope.$digest(); }); it('match a vidible embed', inject(($httpBackend) => { ctrl.input = '
' + '
'; // retrieve embed with Vidible disabled ctrl.retrieveEmbed().then((d) => { expect(d).toEqual({ body: ctrl.input, provider: 'Custom', }); }); scope.$digest(); const testConfig: Partial = { editor: { ...appConfig.editor, // retrieve embed with Vidible enabled vidible: true, }, }; Object.assign(appConfig, testConfig); var apiResponse = { height: 360, mimeType: 'video/ogg', size: 2004079, type: 'video', url: 'http://delivery.vidible.tv/video/redirect/56bb4688e4b0b6448ed479dd' + '?bcid=538612f0e4b00fbb8e898655&w=640&h=360', width: 640, }; $httpBackend .expectGET(appConfig.server.url + '/vidible/bcid/538612f0e4b00fbb8e898655/pid/56bb474de4b0568f54a23ed7') .respond(apiResponse); ctrl.retrieveEmbed().then((d) => { expect(d).toEqual({ body: ctrl.input, provider: 'Vidible', association: apiResponse, }); }); $httpBackend.flush(); scope.$digest(); })); });