{"size": 2304, "ext": "js", "max_stars_repo_path": "spec/classes/editorPanelSpec.js", "max_stars_repo_name": "partnermarketing/pm-image-crop", "max_stars_repo_stars_event_min_datetime": "2016-03-30T14:59:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-29T14:13:43.000Z", "max_issues_repo_path": "spec/classes/editorPanelSpec.js", "max_issues_repo_name": "vidhema/pm-image-editor", "max_issues_repo_issues_event_min_datetime": "2016-01-20T07:37:11.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-01T10:45:18.000Z", "max_forks_repo_path": "spec/classes/editorPanelSpec.js", "max_forks_repo_name": "vidhema/pm-image-editor", "max_forks_repo_forks_event_min_datetime": "2016-01-20T09:06:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-11T17:11:21.000Z"}
{"max_stars_count": 25, "max_issues_count": 19, "max_forks_count": 13, "avg_line_length": 34.9090909091, "max_line_length": 92, "alphanum_fraction": 0.5672743056}
describe('Editor panel', function () {
    'use strict';

    beforeEach(function () {
        module('pmImageEditor');
    });

    describe('directive', function() {
        var element, scope;

        beforeEach(inject(function($rootScope, $compile) {
            scope = $rootScope.$new();

            element = angular.element('<editor-panel editor-id="editor-1"></editor-panel>');

            element = $compile(element)(scope);
            scope.$digest();
        }));

        it('should have required buttons', function() {
            var buttonNames = 'crop,rotate-cw,rotate-acw,flip-h,flip-v';
            buttonNames.split(',').forEach(function(name) {
                expect(element.html()).toContain('<span class="image-editor-'+name+'"');
            });
        });

        it('should disable undo and redo by default', function() {
            expect(element.html()).toContain('<span class="image-editor-undo disabled"');
            expect(element.html()).toContain('<span class="image-editor-redo disabled"');
        });

        it('should allow to disable button', function() {
            scope.$broadcast('disableButton', 'editor-1', 'crop');

            expect(element.html()).toContain('<span class="image-editor-crop disabled"');
        });

        it('should allow to enable button', function() {
            scope.$broadcast('disableButton', 'editor-1', 'crop');
            scope.$broadcast('enableButton', 'editor-1', 'crop');

            expect(element.html()).toContain('<span class="image-editor-crop"');
        });

        it('should skip enable/disable button if editor id is not match', function() {
            scope.$broadcast('disableButton', 'editor-2', 'crop');

            expect(element.html()).toContain('<span class="image-editor-crop"');

            scope.$broadcast('enableButton', 'editor-2', 'redo');

            expect(element.html()).toContain('<span class="image-editor-redo disabled"');
        });

        it('should emit editorButtonClick when button clicked', function() {
            scope = scope.$$childHead;

            spyOn(scope, '$emit');

            element.find('span').eq(0).triggerHandler('click');

            expect(scope.$emit).toHaveBeenCalledWith('editorButtonClick', { name: 'crop' });
        });
    });
});
