/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, describe, it, expect, beforeEach, afterEach, waits, waitsFor, runs, $, waitsForDone, spyOn */

// see main.js for path mapping config
define(['jquery', 'text!spec/test-files/markup.html', 'CSSShapesEditor', 'PolygonEditor', 'CircleEditor'],
function($, markup, CSSShapesEditor, PolygonEditor, CircleEditor){
    
    // create fixture placeholder for other suites
    $('body').append($('<div id="test-fixture"></div>'))
    
    describe('CSSShapesEditor', function(){
        var editor, 
            target, 
            value = 'polygon(nonzero, 0 0, 100px 0, 100px 100px)',
            $fixture = $('#test-fixture').html(markup);
            
        beforeEach(function(){
            // inject markup for test
            $fixture.html(markup)
            target = $('#test-shape')[0]
        })
        
        afterEach(function(){
            editor.remove()
            $fixture.empty()
        })

        it('should be defined', function(){
            editor = new CSSShapesEditor(target, value);
            expect(editor).toBeDefined();
        });
        
        it('should return throw error when setup with undefined value', function(){
            function setupWithUndefined(){
                editor = new CSSShapesEditor(undefined, undefined);
            }
            
            function setupWithNull(){
                editor = new CSSShapesEditor(null, null);
            }
            
            expect(setupWithUndefined).toThrow();
            expect(setupWithNull).toThrow();
        });

        it('should return instance of polygon editor', function(){
            var value = 'polygon(nonzero, 0 0, 100px 0, 100px 100px)';
            
            editor = new CSSShapesEditor(target, value);
            expect(editor instanceof PolygonEditor).toBe(true);
        });

        it('should return instance of polygon editor with type polygon', function(){
            var value = 'polygon(nonzero, 0 0, 100px 0, 100px 100px)';
            
            editor = new CSSShapesEditor(target, value);
            expect(editor instanceof PolygonEditor).toBe(true);
            expect(editor.type).toBe('polygon');
        });

        it('should return instance of circle editor', function(){
            var value = 'circle(50%, 50%, 50%)';
            
            editor = new CSSShapesEditor(target, value);
            expect(editor instanceof CircleEditor).toBe(true);
        });

        it('should throw error for unknown shape in value', function(){
            var value = 'fake-shape()';

            var setup = function() {
                editor = new CSSShapesEditor(target, value);
            };

            expect(setup).toThrow();
        });
        
        it('should throw error for invalid value', function(){
            var setupWithUndefined = function() {
                editor = new CSSShapesEditor(target, undefined);
            };

            var setupWithNull = function() {
                editor = new CSSShapesEditor(target, null);
            };

            var setupWithEmpty = function() {
                editor = new CSSShapesEditor(target, '');
            };

            var setupWithZero = function() {
                editor = new CSSShapesEditor(target, 0);
            };

            expect(setupWithUndefined).toThrow();
            expect(setupWithNull).toThrow();
            expect(setupWithEmpty).toThrow();
            expect(setupWithZero).toThrow();
        })

        it('should throw error for invalid target', function(){
            var setupWithUndefined = function() {
                editor = new CSSShapesEditor(undefined, value);
            };

            var setupWithNull = function() {
                editor = new CSSShapesEditor(null, value);
            };

            var setupWithEmpty = function() {
                editor = new CSSShapesEditor('', value);
            };

            var setupWithZero = function() {
                editor = new CSSShapesEditor(0, value);
            }; 
            
            
            expect(setupWithUndefined).toThrow();
            expect(setupWithNull).toThrow();
            expect(setupWithEmpty).toThrow();
            expect(setupWithZero).toThrow();
        });
    });
});


@@ -421,21 +421,17 @@
 ditor)%7B%0A
-    
 %0A
+
     // c
@@ -530,21 +530,17 @@
 div%3E'))%0A
-    
 %0A
+
     desc
@@ -594,17 +594,16 @@
  editor,
- 
 %0A       
@@ -614,17 +614,16 @@
  target,
- 
 %0A       
@@ -738,29 +738,17 @@
 arkup);%0A
-            
 %0A
+
         
@@ -894,25 +894,17 @@
      %7D)%0A
-        
 %0A
+
         
@@ -1145,33 +1145,25 @@
         %7D);%0A
-        
 %0A
+
         it('
@@ -1355,37 +1355,25 @@
           %7D%0A
-            
 %0A
+
             
@@ -1470,29 +1470,17 @@
       %7D%0A
-            
 %0A
+
         
@@ -1713,37 +1713,25 @@
 px 100px)';%0A
-            
 %0A
+
             
@@ -2004,37 +2004,25 @@
 px 100px)';%0A
-            
 %0A
+
             
@@ -2297,22 +2297,23 @@
 (50%25
-,
+ at
  50%25
-,
  50%25)';%0A
     
@@ -2308,28 +2308,16 @@
  50%25)';%0A
-            
 %0A       
@@ -2718,25 +2718,17 @@
     %7D);%0A
-        
 %0A
+
         
@@ -3460,32 +3460,33 @@
 ow();%0A        %7D)
+;
 %0A%0A        it('sh
@@ -4023,35 +4023,10 @@
   %7D;
- %0A            %0A            
+%0A%0A
 %0A   
@@ -4228,13 +4228,12 @@
     %7D);%0A
+
 %7D);%0A
-%0A

replace legacy notation for CircleEditor instance