<commit_before>/* File: images.js
 *
 * Copyright (c) 2014
 * Centre National d’Enseignement à Distance (Cned), <NAME>, 86360 CHASSENEUIL-DU-POITOU, France
 * (<EMAIL>)
 *
 * GNU Affero General Public License (AGPL) version 3.0 or later version
 *
 * This file is part of a program which is free software: you can
 * redistribute it and/or modify it under the terms of the
 * GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
 *
 */

'use strict';
/* global pdfdata, jasmine */

describe('Controller:ImagesCtrl', function() {
  beforeEach(module('cnedApp'));
  var scope, controller;

  /*Tags de test*/
  var tags = [{
    _id: '52c588a861485ed41c000001',
    libelle: 'Exercice'
  }, {
    _id: '52c588a861485ed41c000002',
    libelle: 'Cours'
  }];

  /*Profils de test*/
  var profils = [{
    nom: 'profil 1',
    descriptif: 'desc profil 1',
    type: 'Dyslexie N1',
    niveauScolaire: 'CP',
    photo: '',
    _id: '52d1429458e68dbb0c000004'
  }];

  /*Zones de test*/
  var zones = [{
    x: 0,
    y: 0,
    w: 100,
    h: 100,
    source: './files/image.png'
  }];

  // Sources des fichiers uploadés
  /*var srcs = [{
    path: './files/image.png',
    extension: '.png'
  }, {
    path: './files/multipages.pdf',
    extension: '.pdf'
  }];*/

  // Retour service download pdf
  var base64 = pdfdata;

  var profile = {
    _id: '532328858785a8e31b786238',
    dropbox: {
      'accessToken': '<KEY>',
      'country': 'MA',
      'display_name': '<NAME>',
      'emails': '<EMAIL>',
      'referral_link': 'https://db.tt/8yRfYgRM',
      'uid': '274702674'
    },
    local: {
      'role': 'user',
      'prenom': 'aaaaaaa',
      'nom': 'aaaaaaaa',
      'password': <PASSWORD>.',
      'email': '<EMAIL>'
    }
  };

  beforeEach(inject(function($controller, $rootScope, $httpBackend, configuration) {
    scope = $rootScope.$new();
    controller = $controller('ImagesCtrl', {
      $scope: scope
    });
    scope.apercuName = 'K-L-1234567.html';
    scope.manifestName = 'K-L-1234567.manifest';
    scope.currentImage = {
      source: './files/image.png',
      originalSource: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAApwAAAAoCAYAAABTjyrvAAAV40lEQVR4Xu2dBbAcRReFOzjBgjskuLu7uxfu7u7w0ODB3d1dggUI7u7uVri7/T9fV92t+zozs7P7Nm93H+dWUSTZnpbTPdOnr3Wv//0rQSIEhIAQEAJCQAgIASEgBIYSAr1qIZxffPHFUOqGqhUCQkAICAEhIASEgBBoRQTGG2+8LnerNOGEbE444YRhnHHG6XKjqkAICAEhIASEgBAQAkKg9RH4+eefw3777Rc6Ojq61NmaCOfMM88cPv/88y41qIeFgBAQAkJACAgBISAE2gOBAw88MIw00kginO0xXeqlEBACQkAICAEhIATaDwERzvabM/VYCAgBISAEhIAQEAJthYAIZ1tNlzorBISAEBACQkAICIH2Q0CEs/3mTD0WAkJACAgBISAEhEBbISDC2VbTpc4KASEgBISAEBACQqD9EGgpwvnZZ5+F22+/Pdxyyy3h5ptvjmjOMsssYd555w0rr7xyWHLJJUPv3r0LUf7111/DbbfdFi655JIwcODAStm11147LL/88mHFFVcM4447btWZeuihh+LzgwcPDs8++2wsv/TSS4ellloq9mX66aevWocv8NJLL4WrrroqDDfccGH77bcP448/fk3PZxW+9dZbw4ABAwJ9RRgbbYw66qhdrruogieffDIMGjQoRpuVlZ9++ilsttlmoW/fvmUfKV2O/tx0002hX79+Ycsttwy9evWqPPvXX3+F33//PYwyyiil6+upBb/99tsw5phjNmR4rD3ei8knnzxssskmDakzr5Jmz+GPP/4YRh555PjuSoSAEBACQqA+BFqGcEISV1pppcJRkDD0/vvvzyV7jzzySFhjjTVCtcTyRx99dNhzzz3DsMMOO0R7P/zwQ1hhhRUCdRUJwB1yyCFhmGGGKYX8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JCQAgIASEgBNoPgf8DKi1Glwo7kDcAAAAASUVORK5CYII=',
      level: 0,
      text: 'test',
      synthese: 'data:audio/mpeg;base64,//NAxAAAAANIAUAAAN4JfOX//btmp/7f/vb//tuo0b//t7reWUp//yZ9R9zM88eJC8FjhKVFwkjRyRP//5jWPeY3bOMGpAHo3LkSQtMdRHVP//+r/',
      children: []
    };

    scope.dataRecu = {
      __v: 0,
      _id: '5329acd20c5ebdb429b2ec66',
      dropbox: {
        accessToken: '<KEY>',
        country: 'MA',
        display_name: '<NAME>', // jshint ignore:line
        emails: '<EMAIL>',
        referral_link: 'https://db.tt/wW61wr2c', // jshint ignore:line
        uid: '264998156'
      },
      local: {
        email: '<EMAIL>',
        nom: 'youbi',
        password: <PASSWORD>',
        prenom: 'anas',
        role: 'admin'
      }
    };

    scope.blocks = {
      children: []
    };
    scope.canvas = document.createElement('canvas');
    scope.context = scope.canvas.getContext('2d');

    scope.pdflinkTaped = 'http://info.sio2.be/tdtooo/sostdt.pdf';

    //scope.pdflinkTaped = 'http://info.sio2.be/tdtooo/sostdt.pdf';


    /*mock OCR web service*/
    $httpBackend.whenPOST(configuration.URL_REQUEST + '/oceriser/').respond(angular.toJson('text oceriser'));

    /*mock redTags web service*/
    $httpBackend.whenGET(configuration.URL_REQUEST + '/readTags').respond(tags);

    /*mock listerProfil web service*/
    $httpBackend.whenGET(configuration.URL_REQUEST + '/listerProfil').respond(profils);

    /*mock Crop Images web service*/
    $httpBackend.whenPOST(configuration.URL_REQUEST + '/images').respond(angular.toJson('./files/img_cropped.png'));

    /*mock webservice de la synthese vocale*/
    $httpBackend.whenPOST(configuration.URL_REQUEST + '/texttospeech').respond(angular.toJson('//NAxAAAAANIAUAAAN4JfOX//btmp/7f/vb//tuo0b//t7reWUp//yZ9R9zM88eJC8FjhKVFwkjRyRP//<KEY>//+r/'));

    /*mock webservice enregistrement des blocks structurés*/
    $httpBackend.whenPOST(configuration.URL_REQUEST + '/ajouterDocStructure').respond(angular.toJson('52e24471be3a449a2988a0e9'));

    /*mock */
    $httpBackend.whenPOST(configuration.URL_REQUEST + '/pdfimage').respond(angular.toJson({
      path: './files/image.png',
      extension: '.png'
    }));

    $httpBackend.whenPOST(configuration.URL_REQUEST + '/sendPdf').respond(base64);

    $httpBackend.whenPOST(configuration.URL_REQUEST + '/sendPdfHTTPS').respond(base64);

    /* mock les services de stockage dans dropbox */
    $httpBackend.whenGET(configuration.URL_REQUEST + '/profile').respond(profile);
    $httpBackend.whenGET(configuration.URL_REQUEST + '/index.html').respond('<htlm manifest=""><head><script> var profilId = null; var blocks = []; </script></head><body></body></html>');
    $httpBackend.whenPUT('https://api-content.dropbox.com/1/files_put/' + configuration.DROPBOX_TYPE + '/' + scope.apercuName + '?access_token=' + profile.dropbox.accessToken).respond({});
    $httpBackend.whenGET('/profile').respond(scope.dataRecu);
    $httpBackend.whenPOST('https://api.dropbox.com/1/shares/?access_token=' + profile.dropbox.accessToken + '&path=' + scope.apercuName + '&root=' + configuration.DROPBOX_TYPE + '&short_url=false').respond({
      url: 'https://www.dropbox.com/s/gdhgsjdggd/' + scope.apercuName
    });
    $httpBackend.whenPUT('https://api-content.dropbox.com/1/files_put/' + configuration.DROPBOX_TYPE + '/' + scope.manifestName + '?access_token=' + profile.dropbox.accessToken).respond({});
    $httpBackend.whenPOST('https://api.dropbox.com/1/shares/?access_token=' + profile.dropbox.accessToken + '&path=' + scope.manifestName + '&root=' + configuration.DROPBOX_TYPE + '&short_url=false').respond({
      url: 'http://dl.dropboxusercontent.com/s/sy4g4yn0qygxhs5/K-L-1234567.manifest'
    });
  }));

  it('ImagesCtrl: oceriser le texte d\'une image', inject(function($httpBackend) {
    $httpBackend.flush();

    scope.oceriser();

    expect(scope.textes).toBeDefined();
    expect(scope.currentImage.text).toBe('test');

  }));

  it('ImagesCtrl: initialisation des variable pour l\'espace de travail', inject(function() {

    var image = {
      'source': './files/image.png',
      'level': 0
    };

    scope.workspace(image);
    expect(scope.currentImage.originalSource).toBe('./files/image.png');
    expect(scope.textes).toEqual({});
    expect(scope.showEditor).not.toBeTruthy();
  }));

  it('ImagesCtrl: selection d\'une zone', inject(function() {
    scope.selected(zones[0]);
  }));

  it('ImagesCtrl: supression d\'une zone', inject(function() {
    scope.removeZone(zones[0]);
  }));

  it('ImagesCtrl: Selection de la liste des tags', inject(function($httpBackend) {
    scope.afficherTags();
    $httpBackend.flush();
    expect(scope.listTags.length).toBe(2);
    expect(scope.listTags).toEqual(tags);
  }));

  it('ImagesCtrl: découpage des images', inject(function($httpBackend) {
    // scope.affectSrcValue(srcs);
    scope.zones = zones;
    scope.sendCrop();
    $httpBackend.flush();
    expect(scope.cropedImages.length).toBe(1);
  }));

  it('ImagesCtrl: test de l\'upload de Fichiers', function() {
    scope.xhrObj = jasmine.createSpyObj('xhrObj', ['addEventListener', 'open', 'send']);
    spyOn(window, 'XMLHttpRequest').andReturn(scope.xhrObj);
    scope.files.length = 1;
    scope.uploadFile();
    expect(scope.xhrObj.addEventListener).toHaveBeenCalled();
    expect(scope.xhrObj.addEventListener.calls.length).toBe(2);
  });

  /*it('ImagesCtrl: test uploadComplete', function() {
    var evt = {
      target: {
        responseText: ''
      }
    };
    evt.target.responseText = angular.toJson(pdfdata);
    scope.uploadComplete(evt);
  });*/

  // it('ImagesCtrl: initialiser la source aprés upload', inject(function() {
  //   scope.affectSrcValue(srcs);
  // }));

  it('ImagesCtrl: enlever un block de l\'espace de travail', inject(function() {
    scope.remove(scope.currentImage);
  }));

  it('ImagesCtrl: Appeler mdification du texte', inject(function() {
    scope.modifierTexte();
  }));

  it('ImagesCtrl: Avoir le texte du WYSIWYG', inject(function($rootScope) {
    $rootScope.ckEditorValue = '<p>text oceriser</p>';
    scope.getOcrText();
  }));

  it('ImagesCtrl: Generation de la synthese vocale', inject(function($httpBackend) {
    scope.blocks.children[0] = scope.currentImage;
    scope.textToSpeech();
    $httpBackend.flush();
    expect(scope.currentImage.synthese).toEqual('data:audio/mpeg;base64,//NAxAAAAANIAUAAAN4JfOX//<KEY>
  }));

  it('ImagesCtrl: Activation de l\'enregistrement des blocks', inject(function() {
    scope.permitSaveblocks();
  }));

  it('ImagesCtrl: Ajout des blocks structurés', inject(function($httpBackend) {
    scope.saveblocks();
    $httpBackend.flush();
    expect(scope.listProfils).toEqual(profils);
    // expect($rootScope.idDocument).toEqual('52e24471be3a449a2988a0e9');
  }));

  it('ImagesCtrl: Stockage dans Dropbox et Redirection automatique vers l\'aperçu', inject(function($httpBackend) {
    scope.showlocks();
    $httpBackend.flush();
    expect(scope.loader).toEqual(false);
  }));

  it('ImagesCtrl: Modification du type du document', inject(function() {
    scope.tagSelected = tags[1];
    scope.blocks.children[0] = scope.currentImage;
    scope.updateBlockType();
    expect(scope.blocks.children[0].tag).toEqual(tags[1]);
  }));

  it('ImagesCtrl: Afficher le bouton prévisualisation synthese vocale', inject(function() {
    scope.showPlaySong();
  }));

  /*it('ImagesCtrl: Convertion de PDF en Images', inject(function($httpBackend) {

  }));*/
  it('ImagesCtrl: loadPdfLink pass le lien du fichier pdf au serveur pour le telecharger et le recupere', inject(function($httpBackend) {
    var data = {
      lien: 'http://info.sio2.be/tdtooo/sostdt.pdf'
    };
    $httpBackend.flush();
    scope.loadPdfLink();
    expect(scope.pdflink).toBe('http://info.sio2.be/tdtooo/sostdt.pdf');
    expect(scope.pdferrLien).toEqual(false);
    expect(data.lien).toEqual(scope.pdflink);
    expect(scope.pdfinfo).toEqual(true);
    expect(scope.showPdfCanvas).toEqual(true);

    expect(scope.showPdfCanvas).toEqual(true);
    //expect(scope.flagUint8Array).toEqual(true);
  }));

  it('ImagesCtrl: cverifie le lien si il est valide', inject(function() {
    var lien = 'http://localhost:3000/#/';
    var tmp = scope.verifLink(lien);
    expect(tmp).toEqual(false);
    lien = 'http://info.sio2.be/tdtooo/sostdt.pdf';
    tmp = scope.verifLink(lien);
    expect(tmp).toEqual(true);
    lien = 'https://info.sio2.be/tdtooo/sostdt.pdf';
    tmp = scope.verifLink(lien);
    expect(tmp).toEqual(true);
  }));

  it('ImagesCtrl:canvasToImage change image background', inject(function() {
    var tmp = scope.canvasToImage('#FFFFFF');
    expect(tmp).not.toBe(null);
  }));

  it('ImagesCtrl:base64ToUint8Array converte base64 to uint8', inject(function() {
    var tmp = scope.base64ToUint8Array(base64);
    expect(tmp).not.toBe(null);
  }));

  it('ImagesCtrl: initImage', inject(function($httpBackend) {
    expect(scope.initImage).toBeDefined();
    scope.initImage();
    $httpBackend.flush();

  }));

  it('ImagesCtrl: Test toggleMinimized', inject(function() {
    scope.toggleMinimized(scope.currentImage);
  }));

  it('ImagesCtrl: vocalised should be defined', inject(function() {
    expect(scope.vocalised).toBeDefined();
    var param = 'test';
    scope.vocalised(param);
    expect(scope.vocalised(param)).toBeTruthy();
    param = null;
    expect(scope.vocalised(param)).toBeFalsy();

  }));

  it('ImagesCtrl: ocerised should be defined', inject(function() {
    expect(scope.ocerised).toBeDefined();
    var param = 'test';
    scope.flagOcr = true;
    scope.ocerised(param);
    expect(scope.ocerised(param)).toBeTruthy();
    param = null;
    expect(scope.ocerised(param)).toBeFalsy();

  }));

  it('ImagesCtrl: initCkEditorChange should be defined', inject(function() {
    expect(scope.initCkEditorChange).toBeDefined();
  }));

});<commit_msg>Mettre à jour les tests unitaires frontend de l'images suite aux derniers changements.<commit_after>/* File: images.js
 *
 * Copyright (c) 2014
 * Centre National d’Enseignement à Distance (Cned), <NAME>, 86360 CHASSENEUIL-DU-POITOU, France
 * (<EMAIL>)
 *
 * GNU Affero General Public License (AGPL) version 3.0 or later version
 *
 * This file is part of a program which is free software: you can
 * redistribute it and/or modify it under the terms of the
 * GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
 *
 */

'use strict';
/* global pdfdata, jasmine */

describe('Controller:ImagesCtrl', function() {
  beforeEach(module('cnedApp'));
  var scope, controller;

  /*Tags de test*/
  var tags = [{
    _id: '52c588a861485ed41c000001',
    libelle: 'Exercice'
  }, {
    _id: '52c588a861485ed41c000002',
    libelle: 'Cours'
  }];

  /*Profils de test*/
  var profils = [{
    nom: 'profil 1',
    descriptif: 'desc profil 1',
    type: 'Dyslexie N1',
    niveauScolaire: 'CP',
    photo: '',
    _id: '52d1429458e68dbb0c000004'
  }];

  /*Zones de test*/
  var zones = [{
    x: 0,
    y: 0,
    w: 100,
    h: 100,
    source: './files/image.png'
  }];

  // Sources des fichiers uploadés
  /*var srcs = [{
    path: './files/image.png',
    extension: '.png'
  }, {
    path: './files/multipages.pdf',
    extension: '.pdf'
  }];*/

  // Retour service download pdf
  var base64 = pdfdata;

  var profile = {
    _id: '532328858785a8e31b786238',
    dropbox: {
      'accessToken': '<KEY>',
      'country': 'MA',
      'display_name': '<NAME>',
      'emails': '<EMAIL>',
      'referral_link': 'https://db.tt/8yRfYgRM',
      'uid': '274702674'
    },
    local: {
      'role': 'user',
      'prenom': 'aaaaaaa',
      'nom': 'aaaaaaaa',
      'password': <PASSWORD>.',
      'email': '<EMAIL>'
    }
  };

  beforeEach(inject(function($controller, $rootScope, $httpBackend, configuration) {
    scope = $rootScope.$new();
    controller = $controller('ImagesCtrl', {
      $scope: scope
    });

    scope.docTitre = 'K-L-1234567';

    scope.currentImage = {
      source: './files/image.png',
      originalSource: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAApwAAAAoCAYAAABTjyrvAAAV40lEQVR4Xu2dBbAcRReFOzjBgjskuLu7uxfu7u7w0ODB3d1dggUI7u7uVri7/T9fV92t+zozs7P7Nm93H+dWUSTZnpbTPdOnr3Wv//0rQSIEhIAQEAJCQAgIASEgBIYSAr1qIZxffPHFUOqGqhUCQkAICAEhIASEgBBoRQTGG2+8LnerNOGEbE444YRhnHHG6XKjqkAICAEhIASEgBAQAkKg9RH4+eefw3777Rc6Ojq61NmaCOfMM88cPv/88y41qIeFgBAQAkJACAgBISAE2gOBAw88MIw00kginO0xXeqlEBACQkAICAEhIATaDwERzvabM/VYCAgBISAEhIAQEAJthYAIZ1tNlzorBISAEBACQkAICIH2Q0CEs/3mTD0WAkJACAgBISAEhEBbISDC2VbTpc4KASEgBISAEBACQqD9EGgpwvnZZ5+F22+/Pdxyyy3h5ptvjmjOMsssYd555w0rr7xyWHLJJUPv3r0LUf7111/DbbfdFi655JIwcODAStm11147LL/88mHFFVcM4447btWZeuihh+LzgwcPDs8++2wsv/TSS4ellloq9mX66aevWocv8NJLL4WrrroqDDfccGH77bcP448/fk3PZxW+9dZbw4ABAwJ9RRgbbYw66qhdrruogieffDIMGjQoRpuVlZ9++ilsttlmoW/fvmUfKV<KEY>BIdBWCIhwttV0qbNCQAgIASEgBISAEGg/BEQ422/O1GMhIASEgBAQAkJACLQVAiKcbTVd6qwQEAJCQAgIASEgBNoPgf8DKi1Glwo7kDcAAAAASUVORK5CYII=',
      level: 0,
      text: 'test',
      synthese: 'data:audio/mpeg;base64,//NAxAAAAANIAUAAAN4JfOX//btmp/7f/vb//tuo0b//t7reWUp//yZ9R9zM88eJC8FjhKVFwkjRyRP//5jWPeY3bOMGpAHo3LkSQtMdRHVP//+r/',
      children: []
    };

    scope.dataRecu = {
      __v: 0,
      _id: '5329acd20c5ebdb429b2ec66',
      dropbox: {
        accessToken: '<KEY>',
        country: 'MA',
        display_name: '<NAME>', // jshint ignore:line
        emails: '<EMAIL>',
        referral_link: 'https://db.tt/wW61wr2c', // jshint ignore:line
        uid: '264998156'
      },
      local: {
        email: '<EMAIL>',
        nom: 'youbi',
        password: <PASSWORD>',
        prenom: 'anas',
        role: 'admin'
      }
    };

    scope.blocks = {
      children: []
    };
    scope.canvas = document.createElement('canvas');
    scope.context = scope.canvas.getContext('2d');

    scope.pdflinkTaped = 'http://info.sio2.be/tdtooo/sostdt.pdf';

    //scope.pdflinkTaped = 'http://info.sio2.be/tdtooo/sostdt.pdf';


    /*mock OCR web service*/
    $httpBackend.whenPOST(configuration.URL_REQUEST + '/oceriser/').respond(angular.toJson('text oceriser'));

    /*mock redTags web service*/
    $httpBackend.whenGET(configuration.URL_REQUEST + '/readTags').respond(tags);

    /*mock listerProfil web service*/
    $httpBackend.whenGET(configuration.URL_REQUEST + '/listerProfil').respond(profils);

    /*mock Crop Images web service*/
    $httpBackend.whenPOST(configuration.URL_REQUEST + '/images').respond(angular.toJson('./files/img_cropped.png'));

    /*mock webservice de la synthese vocale*/
    $httpBackend.whenPOST(configuration.URL_REQUEST + '/texttospeech').respond(angular.toJson('//NAxAAAAANIAUAAAN4JfOX//btmp/7f/vb//tuo0b//t7reWUp//yZ9R9zM88eJC8FjhKVFwkjRyRP//5jWPeY3bOMGpAHo3LkSQtMdRHVP//+r/'));

    /*mock webservice enregistrement des blocks structurés*/
    $httpBackend.whenPOST(configuration.URL_REQUEST + '/ajouterDocStructure').respond(angular.toJson('52e24471be3a449a2988a0e9'));

    /*mock */
    $httpBackend.whenPOST(configuration.URL_REQUEST + '/pdfimage').respond(angular.toJson({
      path: './files/image.png',
      extension: '.png'
    }));

    $httpBackend.whenPOST(configuration.URL_REQUEST + '/sendPdf').respond(base64);

    $httpBackend.whenPOST(configuration.URL_REQUEST + '/sendPdfHTTPS').respond(base64);

    /* mock les services de stockage dans dropbox */
    $httpBackend.whenGET(configuration.URL_REQUEST + '/profile').respond(profile);
    $httpBackend.whenGET(configuration.URL_REQUEST + '/index.html').respond('<htlm manifest=""><head><script> var profilId = null; var blocks = []; </script></head><body></body></html>');
    $httpBackend.whenPOST('https://api.dropbox.com/1/search/?access_token=' + profile.dropbox.accessToken + '&query=' + scope.docTitre + '.html&root=' + configuration.DROPBOX_TYPE).respond({});
    $httpBackend.whenPUT('https://api-content.dropbox.com/1/files_put/' + configuration.DROPBOX_TYPE + '/' + scope.docTitre + '.appcache?access_token=' + profile.dropbox.accessToken).respond({});
    $httpBackend.whenPOST('https://api.dropbox.com/1/shares/?access_token=' + profile.dropbox.accessToken + '&path=' + scope.docTitre + '.appcache&root=' + configuration.DROPBOX_TYPE + '&short_url=false').respond({
      url: 'http://dl.dropboxusercontent.com/s/sy4g4yn0qygxhs5/K-L-1234567.appcache'
    });
    $httpBackend.whenPUT('https://api-content.dropbox.com/1/files_put/' + configuration.DROPBOX_TYPE + '/' + scope.docTitre + '.html?access_token=' + profile.dropbox.accessToken).respond({});
    $httpBackend.whenPOST('https://api.dropbox.com/1/shares/?access_token=' + profile.dropbox.accessToken + '&path=' + scope.docTitre + '.html&root=' + configuration.DROPBOX_TYPE + '&short_url=false').respond({
      url: 'https://www.dropbox.com/s/gdhgsjdggd/' + scope.docTitre
    });
    $httpBackend.whenGET('/profile').respond(scope.dataRecu);

  }));

  it('ImagesCtrl: oceriser le texte d\'une image', inject(function($httpBackend) {
    $httpBackend.flush();

    scope.oceriser();

    expect(scope.textes).toBeDefined();
    expect(scope.currentImage.text).toBe('test');

  }));

  it('ImagesCtrl: initialisation des variable pour l\'espace de travail', inject(function() {

    var image = {
      'source': './files/image.png',
      'level': 0
    };

    scope.workspace(image);
    expect(scope.currentImage.originalSource).toBe('./files/image.png');
    expect(scope.textes).toEqual({});
    expect(scope.showEditor).not.toBeTruthy();
  }));

  it('ImagesCtrl: selection d\'une zone', inject(function() {
    scope.selected(zones[0]);
  }));

  it('ImagesCtrl: supression d\'une zone', inject(function() {
    scope.removeZone(zones[0]);
  }));

  it('ImagesCtrl: Selection de la liste des tags', inject(function($httpBackend) {
    scope.afficherTags();
    $httpBackend.flush();
    expect(scope.listTags.length).toBe(2);
    expect(scope.listTags).toEqual(tags);
  }));

  it('ImagesCtrl: découpage des images', inject(function($httpBackend) {
    // scope.affectSrcValue(srcs);
    scope.zones = zones;
    scope.sendCrop();
    $httpBackend.flush();
    expect(scope.cropedImages.length).toBe(1);
  }));

  it('ImagesCtrl: test de l\'upload de Fichiers', function() {
    scope.xhrObj = jasmine.createSpyObj('xhrObj', ['addEventListener', 'open', 'send']);
    spyOn(window, 'XMLHttpRequest').andReturn(scope.xhrObj);
    scope.files.length = 1;
    scope.uploadFile();
    expect(scope.xhrObj.addEventListener).toHaveBeenCalled();
    expect(scope.xhrObj.addEventListener.calls.length).toBe(2);
  });

  /*it('ImagesCtrl: test uploadComplete', function() {
    var evt = {
      target: {
        responseText: ''
      }
    };
    evt.target.responseText = angular.toJson(pdfdata);
    scope.uploadComplete(evt);
  });*/

  // it('ImagesCtrl: initialiser la source aprés upload', inject(function() {
  //   scope.affectSrcValue(srcs);
  // }));

  it('ImagesCtrl: enlever un block de l\'espace de travail', inject(function() {
    scope.remove(scope.currentImage);
  }));

  it('ImagesCtrl: Appeler mdification du texte', inject(function() {
    scope.modifierTexte();
  }));

  it('ImagesCtrl: Avoir le texte du WYSIWYG', inject(function($rootScope) {
    $rootScope.ckEditorValue = '<p>text oceriser</p>';
    scope.getOcrText();
  }));

  it('ImagesCtrl: Generation de la synthese vocale', inject(function($httpBackend) {
    scope.blocks.children[0] = scope.currentImage;
    scope.textToSpeech();
    $httpBackend.flush();
    expect(scope.currentImage.synthese).toEqual('data:audio/mpeg;base64,//NAxAAAAANIAUAAAN4JfOX//btmp/7f/vb//tuo0b//t7reWUp//yZ9R9zM88eJC8FjhKVFwkjRyRP//5jWPeY3bOMGpAHo3LkSQtMdRHVP//+r/');
  }));

  it('ImagesCtrl: Activation de l\'enregistrement des blocks', inject(function() {
    scope.permitSaveblocks();
  }));

  it('ImagesCtrl: Ajout des blocks structurés', inject(function($httpBackend) {
    scope.saveblocks();
    $httpBackend.flush();
    expect(scope.listProfils).toEqual(profils);
    // expect($rootScope.idDocument).toEqual('52e24471be3a449a2988a0e9');
  }));

  it('ImagesCtrl: Stockage dans Dropbox et Redirection automatique vers l\'aperçu', inject(function($httpBackend) {
    scope.showlocks();
    $httpBackend.flush();
    expect(scope.loader).toEqual(false);
  }));

  it('ImagesCtrl: Modification du type du document', inject(function() {
    scope.tagSelected = tags[1];
    scope.blocks.children[0] = scope.currentImage;
    scope.updateBlockType();
    expect(scope.blocks.children[0].tag).toEqual(tags[1]);
  }));

  it('ImagesCtrl: Afficher le bouton prévisualisation synthese vocale', inject(function() {
    scope.showPlaySong();
  }));

  /*it('ImagesCtrl: Convertion de PDF en Images', inject(function($httpBackend) {

  }));*/
  it('ImagesCtrl: loadPdfLink pass le lien du fichier pdf au serveur pour le telecharger et le recupere', inject(function($httpBackend) {
    var data = {
      lien: 'http://info.sio2.be/tdtooo/sostdt.pdf'
    };
    $httpBackend.flush();
    scope.loadPdfLink();
    expect(scope.pdflink).toBe('http://info.sio2.be/tdtooo/sostdt.pdf');
    expect(scope.pdferrLien).toEqual(false);
    expect(data.lien).toEqual(scope.pdflink);
    expect(scope.pdfinfo).toEqual(true);
    expect(scope.showPdfCanvas).toEqual(true);

    expect(scope.showPdfCanvas).toEqual(true);
    //expect(scope.flagUint8Array).toEqual(true);
  }));

  it('ImagesCtrl: cverifie le lien si il est valide', inject(function() {
    var lien = 'http://localhost:3000/#/';
    var tmp = scope.verifLink(lien);
    expect(tmp).toEqual(false);
    lien = 'http://info.sio2.be/tdtooo/sostdt.pdf';
    tmp = scope.verifLink(lien);
    expect(tmp).toEqual(true);
    lien = 'https://info.sio2.be/tdtooo/sostdt.pdf';
    tmp = scope.verifLink(lien);
    expect(tmp).toEqual(true);
  }));

  it('ImagesCtrl:canvasToImage change image background', inject(function() {
    var tmp = scope.canvasToImage('#FFFFFF');
    expect(tmp).not.toBe(null);
  }));

  it('ImagesCtrl:base64ToUint8Array converte base64 to uint8', inject(function() {
    var tmp = scope.base64ToUint8Array(base64);
    expect(tmp).not.toBe(null);
  }));

  it('ImagesCtrl: initImage', inject(function($httpBackend) {
    expect(scope.initImage).toBeDefined();
    scope.initImage();
    $httpBackend.flush();

  }));

  it('ImagesCtrl: Test toggleMinimized', inject(function() {
    scope.toggleMinimized(scope.currentImage);
  }));

  it('ImagesCtrl: vocalised should be defined', inject(function() {
    expect(scope.vocalised).toBeDefined();
    var param = 'test';
    scope.vocalised(param);
    expect(scope.vocalised(param)).toBeTruthy();
    param = null;
    expect(scope.vocalised(param)).toBeFalsy();

  }));

  it('ImagesCtrl: ocerised should be defined', inject(function() {
    expect(scope.ocerised).toBeDefined();
    var param = 'test';
    scope.flagOcr = true;
    scope.ocerised(param);
    expect(scope.ocerised(param)).toBeTruthy();
    param = null;
    expect(scope.ocerised(param)).toBeFalsy();

  }));

  it('ImagesCtrl: initCkEditorChange should be defined', inject(function() {
    expect(scope.initCkEditorChange).toBeDefined();
  }));

});
{'fraction_non_alphanumeric': 0.132855110267963, 'fraction_numerical': 0.05365188522646431, 'mean_word_length': 5.1451730418943535, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 52, 'https://': 17, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2986161', 'n_tokens_mistral': 15546, 'n_tokens_neox': 14672, 'n_words': 1500}