<commit_before>/* File: apercu.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/>.
 *
 */

/*global $:false, blocks*/

'use strict';

describe('Controller:ApercuCtrl', function() {

	var scope, controller;
	blocks = {
		'children': [{
			'id': 461.5687490440905,
			'originalSource': 'data:image/png;base64,',
			'source': {},
			'text': '',
			'level': 0,
			'children': [{
				'id': '139482262782797',
				'text': 'Un titre',
				'source': {},
				'children': [],
				'originalSource': 'data:image/png;base64,jhdsghfsdhhtd',
				'tag': '52d0598c563380592bc1d704'
			}, {
				'id': '1394822627845718',
				'text': 'Un example de texte',
				'source': {},
				'children': [],
				'originalSource': 'data:image/png;base64,dgshgdhgsdggd',
				'tag': '52e940536f86d29e28f930fb'
			}]
		}]
	};

	var profilTags = [{
		'__v': 0,
		'_id': '52fb65eb8856dce835c2ca87',
		'coloration': 'Colorer les lignes',
		'interligne': '18',
		'police': 'opendyslexicregular',
		'profil': '<KEY>',
		'styleValue': 'Normal',
		'tag': '52e8d60cc6180eb9163fa064',
		'tagName': 'Titre 01',
		'taille': '12',
		'texte': '<p data-font=\'opendyslexicregular\' data-size=\'12\' data-lineheight=\'18\' data-weight=\'Normal\' data-coloration=\'Colorer les lignes\'> </p>'
	}, {
		'tag': '52e940686f86d29e28f930fe',
		'texte': '<p data-font=\'opendyslexicregular\' data-size=\'14\' data-lineheight=\'18\' data-weight=\'Normal\' data-coloration=\'Surligner les lignes\'> </p>',
		'profil': '<KEY>',
		'tagName': 'Solution',
		'police': 'opendyslexicregular',
		'taille': '14',
		'interligne': '18',
		'styleValue': 'Normal',
		'coloration': 'Surligner les lignes',
		'_id': '52fb65eb8856dce835c2ca8d',
		'__v': 0
	}];

	var tags = [{
		_id: '52c588a861485ed41c000001',
		libelle: 'Exercice'
	}, {
		_id: '52d0598c563380592bc1d704',
		libelle: 'Titre'
	}];

	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>'
		}
	};

	var profilActuel = {
		nom: 'Nom1',
		descriptif: 'Descriptif1',
		photo: '',
		owner: '5325aa33a21f887257ac2995',
		_id: '52fb65eb8856dce835c2ca86'
	};

	//var source = './files/audio.mp3';

	beforeEach(module('cnedApp'));

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

		controller = $controller('ApercuCtrl', {
			$scope: scope
		});

		$rootScope.currentUser = profile;

		// Mocker le service de recherche des tags  
		$httpBackend.whenPOST(configuration.URL_REQUEST + '/chercherProfilActuel').respond(profilActuel);
		$httpBackend.whenPOST(configuration.URL_REQUEST + '/chercherTagsParProfil').respond(profilTags);
		$httpBackend.whenGET(configuration.URL_REQUEST + '/readTags').respond(tags);

		scope.manifestName = 'doc01.appcache';
		scope.apercuName = 'doc01.html';
		scope.url = 'http://dl.dropboxusercontent.com/s/vnmvpqykdwn7ekq/' + scope.apercuName;
		scope.listDocumentDropbox = 'test.html';
		scope.listDocumentManifest = 'listDocument.appcache';

		$httpBackend.whenGET(configuration.URL_REQUEST + '/document.appcache').respond({
			data: ''
		});
		$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/' + scope.manifestName
		});

		$httpBackend.whenPUT('https://api-content.dropbox.com/1/files_put/' + configuration.DROPBOX_TYPE + '/' + scope.apercuName + '?access_token=' + profile.dropbox.accessToken).respond({});
		$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: 'http://dl.dropboxusercontent.com/s/sy4g4yn0qygxhs5/' + scope.apercuName
		});

		$httpBackend.whenGET(scope.url).respond('<html manifest=""><head><script> var ownerId = null; var blocks = []; </script></head><body></body></html>');
		$httpBackend.whenGET('https://api-content.dropbox.com/1/files/' + configuration.DROPBOX_TYPE + '/' + scope.listDocumentDropbox + '?access_token=' + profile.dropbox.accessToken).respond('<htlm manifest=""><head><script> var profilId = null; var blocks = []; var listDocument= []; </script></head><body></body></html>');
		$httpBackend.whenPUT('https://api-content.dropbox.com/1/files_put/' + configuration.DROPBOX_TYPE + '/' + scope.listDocumentDropbox + '?access_token=' + profile.dropbox.accessToken).respond({});
		$httpBackend.whenGET('https://api-content.dropbox.com/1/files/' + configuration.DROPBOX_TYPE + '/' + scope.listDocumentManifest + '?access_token=' + profile.dropbox.accessToken).respond('');
        $httpBackend.whenPUT('https://api-content.dropbox.com/1/files_put/' + configuration.DROPBOX_TYPE + '/' + scope.listDocumentManifest + '?access_token=' + profile.dropbox.accessToken).respond({});
	}));

	/* ApercuCtrl:init */
	it('ApercuCtrl:init', function() {
		localStorage.setItem('compteId', profile._id);
		localStorage.setItem('listTagsByProfil', JSON.stringify(profilTags));
		localStorage.setItem('listTags', JSON.stringify(tags));
		scope.init();
		//$httpBackend.flush();
		expect(scope.profiltags).toBeDefined();
		expect(scope.profiltags.length).toEqual(profilTags.length);
		expect(scope.plans).toBeDefined();
		expect(scope.plans.length).toEqual(2);
		expect(scope.loader).toBeDefined();
		expect(scope.loader).toBe(false);
		scope.setActive(0, '52cb095fa8551d800b000012');
		expect(scope.blocksPlan[1].active).toBe(true);
		expect(true).toBe(true);
	});

	it('ApercuCtrl:verifProfil', inject(function($httpBackend) {
		scope.verifProfil();
		$httpBackend.flush();
		expect(scope.verifProfil).toBeDefined();
		expect(localStorage.getItem('profilActuel')).toBe(angular.toJson(profilActuel));
		expect(localStorage.getItem('listTagsByProfil')).toBe(angular.toJson(profilTags));
		expect(localStorage.getItem('listTags')).toBe(angular.toJson(tags));
	}));

	it('ApercuCtrl:dupliquerDocument', inject(function($httpBackend) {
		scope.dupliquerDocument();
		$httpBackend.flush();
		expect(scope.dupliquerDocument).toBeDefined();
		expect(scope.showMsgSuccess).toBe(true);
	}));

	/* ApercuCtrl:setActive */
	it('ApercuCtrl:setActive', function() {
		scope.setActive(0, '52cb095fa8551d800b000012');
		expect(scope.blocksPlan[1].active).toBe(true);<commit_msg>Mettre à jour les tests unitaires de l'apercu suite aux derniers changements.<commit_after>/* File: apercu.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/>.
 *
 */

/*global $:false, blocks*/

'use strict';

describe('Controller:ApercuCtrl', function() {

	var scope, controller;
	blocks = {
		'children': [{
			'id': 461.5687490440905,
			'originalSource': 'data:image/png;base64,',
			'source': {},
			'text': '',
			'level': 0,
			'children': [{
				'id': '139482262782797',
				'text': 'Un titre',
				'source': {},
				'children': [],
				'originalSource': 'data:image/png;base64,jhdsghfsdhhtd',
				'tag': '52d0598c563380592bc1d704'
			}, {
				'id': '1394822627845718',
				'text': 'Un example de texte Un example de texte Un example de texte Un example de texte Un example de texte Un example de texte Un example de texte Un example de texte Un example de texte Un example de texte Un example de texte ',
				'source': {},
				'children': [],
				'originalSource': 'data:image/png;base64,dgshgdhgsdggd',
				'tag': '52c588a861485ed41c000001'
			}]
		}]
	};

	var profilTags = [{
		'__v': 0,
		'_id': '52fb65eb8856dce835c2ca87',
		'coloration': 'Colorer les lignes',
		'interligne': '18',
		'police': 'opendyslexicregular',
		'profil': '<KEY>',
		'styleValue': 'Normal',
		'tag': '52d0598c563380592bc1d704',
		'tagName': 'Titre 01',
		'taille': '12',
		'texte': '<p data-font=\'opendyslexicregular\' data-size=\'12\' data-lineheight=\'18\' data-weight=\'Normal\' data-coloration=\'Colorer les lignes\'> </p>'
	}, {
		'tag': '52c588a861485ed41c000001',
		'texte': '<p data-font=\'opendyslexicregular\' data-size=\'14\' data-lineheight=\'18\' data-weight=\'Normal\' data-coloration=\'Surligner les lignes\'> </p>',
		'profil': '<KEY>',
		'tagName': 'Solution',
		'police': 'opendyslexicregular',
		'taille': '14',
		'interligne': '18',
		'styleValue': 'Normal',
		'coloration': 'Surligner les lignes',
		'_id': '52fb65eb8856dce835c2ca8d',
		'__v': 0
	}];

	var tags = [{
		_id: '52c588a861485ed41c000001',
		libelle: 'Exercice'
	}, {
		_id: '52d0598c563380592bc1d704',
		libelle: 'Titre 01'
	}];

	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>'
		}
	};

	var profilActuel = {
		nom: 'Nom1',
		descriptif: 'Descriptif1',
		photo: '',
		owner: '5325aa33a21f887257ac2995',
		_id: '52fb65eb8856dce835c2ca86'
	};

	//var source = './files/audio.mp3';

	beforeEach(module('cnedApp'));

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

		controller = $controller('ApercuCtrl', {
			$scope: scope
		});

		$rootScope.currentUser = profile;

		// Mocker le service de recherche des tags  
		$httpBackend.whenPOST(configuration.URL_REQUEST + '/chercherProfilActuel').respond(profilActuel);
		$httpBackend.whenPOST(configuration.URL_REQUEST + '/chercherTagsParProfil').respond(profilTags);
		$httpBackend.whenGET(configuration.URL_REQUEST + '/readTags').respond(tags);

		scope.manifestName = 'doc01.appcache';
		scope.apercuName = 'doc01.html';
		scope.url = 'http://dl.dropboxusercontent.com/s/vnmvpqykdwn7ekq/' + scope.apercuName;
		scope.listDocumentDropbox = 'test.html';
		scope.listDocumentManifest = 'listDocument.appcache';

		$httpBackend.whenGET(configuration.URL_REQUEST + '/document.appcache').respond({
			data: ''
		});
		$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/' + scope.manifestName
		});

		$httpBackend.whenPUT('https://api-content.dropbox.com/1/files_put/' + configuration.DROPBOX_TYPE + '/' + scope.apercuName + '?access_token=' + profile.dropbox.accessToken).respond({});
		$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: 'http://dl.dropboxusercontent.com/s/sy4g4yn0qygxhs5/' + scope.apercuName
		});

		$httpBackend.whenGET(scope.url).respond('<html manifest=""><head><script> var ownerId = null; var blocks = []; </script></head><body></body></html>');
		$httpBackend.whenGET('https://api-content.dropbox.com/1/files/' + configuration.DROPBOX_TYPE + '/' + scope.listDocumentDropbox + '?access_token=' + profile.dropbox.accessToken).respond('<htlm manifest=""><head><script> var profilId = null; var blocks = []; var listDocument= []; </script></head><body></body></html>');
		$httpBackend.whenPUT('https://api-content.dropbox.com/1/files_put/' + configuration.DROPBOX_TYPE + '/' + scope.listDocumentDropbox + '?access_token=' + profile.dropbox.accessToken).respond({});
		$httpBackend.whenGET('https://api-content.dropbox.com/1/files/' + configuration.DROPBOX_TYPE + '/' + scope.listDocumentManifest + '?access_token=' + profile.dropbox.accessToken).respond('');
        $httpBackend.whenPUT('https://api-content.dropbox.com/1/files_put/' + configuration.DROPBOX_TYPE + '/' + scope.listDocumentManifest + '?access_token=' + profile.dropbox.accessToken).respond({});
	}));

	/* ApercuCtrl:init */
	it('ApercuCtrl:init', function() {
		localStorage.setItem('compteId', profile._id);
		localStorage.setItem('listTagsByProfil', JSON.stringify(profilTags));
		localStorage.setItem('listTags', JSON.stringify(tags));
		scope.init();
		//$httpBackend.flush();
		expect(scope.profiltags).toBeDefined();
		expect(scope.profiltags.length).toEqual(profilTags.length);
		expect(scope.plans).toBeDefined();
		expect(scope.plans.length).toEqual(2);
		expect(scope.loader).toBeDefined();
		expect(scope.loader).toBe(false);
		scope.setActive(0, '52cb095fa8551d800b000012');
		expect(scope.blocksPlan[1].active).toBe(true);
		expect(true).toBe(true);
	});

	it('ApercuCtrl:verifProfil', inject(function($httpBackend) {
		scope.verifProfil();
		$httpBackend.flush();
		expect(scope.verifProfil).toBeDefined();
		expect(localStorage.getItem('profilActuel')).toBe(angular.toJson(profilActuel));
		expect(localStorage.getItem('listTagsByProfil')).toBe(angular.toJson(profilTags));
		expect(localStorage.getItem('listTags')).toBe(angular.toJson(tags));
	}));

	it('ApercuCtrl:dupliquerDocument', inject(function($httpBackend) {
		scope.dupliquerDocument();
		$httpBackend.flush();
		expect(scope.dupliquerDocument).toBeDefined();
		expect(scope.showMsgSuccess).toBe(true);
	}));

	it('ApercuCtrl:restructurer', inject(function($httpBackend, $rootScope) {
		scope.escapeTest = false;
		scope.restructurer();
		expect($rootScope.restructedBlocks).toBeDefined();
	}));

	/* ApercuCtrl:setActive */
	it('ApercuCtrl:setActive', function() {
		scope.setActive(0, '52cb095fa8551d800b000012');
		expect(scope.blocksPlan[1].active).toBe(true);
{'fraction_non_alphanumeric': 0.178325868920709, 'fraction_numerical': 0.04447107802939507, 'mean_word_length': 5.014415781487101, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 63, 'https://': 18, 'lorem ipsum': 0, 'www.': 2, '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': '2986160', 'n_tokens_mistral': 6347, 'n_tokens_neox': 5617, 'n_words': 954}