forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunittests.js
More file actions
1 lines (1 loc) · 26.9 KB
/
Copy pathunittests.js
File metadata and controls
1 lines (1 loc) · 26.9 KB
1
define(function(require,exports,module){var SpecRunnerUtils=brackets.getModule("spec/SpecRunnerUtils"),KeyEvent=brackets.getModule("utils/KeyEvent"),testContentCSS=require("text!unittest-files/unittests.css"),provider=require("main").inlineTimingFunctionEditorProvider,TimingFunctionUtils=require("TimingFunctionUtils"),BezierCurveEditor=require("BezierCurveEditor").BezierCurveEditor,StepEditor=require("StepEditor").StepEditor;describe("unit:Inline Timing Function Editor",function(){var testDocument,testEditor,inline;async function makeTimingFunctionEditor(cursor){var promise=provider(testEditor,cursor);promise&&(promise.done(function(inlineResult){inlineResult.onAdded(),inline=inlineResult}),await awaitsForDone(promise,"open timing function editor"))}function expectArraysToBeEqual(a1,a2,len){expect(a2.length).toEqual(a1.length),a2.forEach(function(entry,index){expect(entry).toEqual(a1[index])})}describe("TimingFunctionUtils for bezier curve functions",function(){var match;function testInvalidBezier(str,expectedArray){var match=TimingFunctionUtils.timingFunctionMatch(str,!1);expectArraysToBeEqual(match,expectedArray),expect(match.originalString).toEqual(str)}it("should match bezier curve function in strict mode",function(){match=TimingFunctionUtils.timingFunctionMatch("cubic-bezier(.1, .2, .3, .4)",!1),expect(match).toBeTruthy(),expectArraysToBeEqual(match,["cubic-bezier(.1, .2, .3, .4)",".1",".2",".3",".4"]),expect(match.originalString).toBeFalsy()}),it("should match bezier curve function in lax mode",function(){match=TimingFunctionUtils.timingFunctionMatch("cubic-bezier(.1, .2, .3, .4)",!0),expect(match).toBeTruthy(),expectArraysToBeEqual(match,["cubic-bezier(.1, .2, .3, .4)",".1",".2",".3",".4"]),expect(match.originalString).toBeFalsy()}),it("should match bezier curve function with negative value",function(){expectArraysToBeEqual(match=TimingFunctionUtils.timingFunctionMatch("cubic-bezier(0, -.2, 1, 1.2)",!1),["cubic-bezier(0, -.2, 1, 1.2)","0","-.2","1","1.2"]),expect(match.originalString).toBeFalsy()}),it("should match bezier curve function in full line of longhand css",function(){expectArraysToBeEqual(match=TimingFunctionUtils.timingFunctionMatch(" transition-timing-function: cubic-bezier(.37, .28, .83, .94);",!1),["cubic-bezier(.37, .28, .83, .94)",".37",".28",".83",".94"]),expect(match.originalString).toBeFalsy()}),it("should match bezier curve function in full line of shorthand css",function(){expectArraysToBeEqual(match=TimingFunctionUtils.timingFunctionMatch(" transition: top 100ms cubic-bezier(.37, .28, .83, .94) 0;",!1),["cubic-bezier(.37, .28, .83, .94)",".37",".28",".83",".94"]),expect(match.originalString).toBeFalsy()}),it("should match bezier curve function with leading zeros",function(){expectArraysToBeEqual(match=TimingFunctionUtils.timingFunctionMatch("cubic-bezier(0.1, 0.2, 0.3, 0.4)",!1),["cubic-bezier(0.1, 0.2, 0.3, 0.4)","0.1","0.2","0.3","0.4"]),expect(match.originalString).toBeFalsy()}),it("should match bezier curve function with no optional whitespace",function(){expectArraysToBeEqual(match=TimingFunctionUtils.timingFunctionMatch("cubic-bezier(.1,.2,.3,.4)",!1),["cubic-bezier(.1,.2,.3,.4)",".1",".2",".3",".4"]),expect(match.originalString).toBeFalsy()}),it("should match bezier curve function with extra optional whitespace",function(){expectArraysToBeEqual(match=TimingFunctionUtils.timingFunctionMatch("cubic-bezier( .1 , .2 , .3 , .4 )",!1),["cubic-bezier( .1 , .2 , .3 , .4 )",".1",".2",".3",".4"]),expect(match.originalString).toBeFalsy()}),it("should match linear animation function in declaration in strict mode",function(){match=TimingFunctionUtils.timingFunctionMatch("animation-timing-function: linear;",!1),expect(match.length).toEqual(1),expect(match[0]).toEqual("linear"),expect(match.originalString).toBeFalsy()}),it("should match ease animation function in declaration in strict mode",function(){match=TimingFunctionUtils.timingFunctionMatch("animation-timing-function: ease;",!1),expect(match.length).toEqual(1),expect(match[0]).toEqual("ease"),expect(match.originalString).toBeFalsy()}),it("should match ease-in animation function in declaration in strict mode",function(){match=TimingFunctionUtils.timingFunctionMatch("animation-timing-function: ease-in;",!1),expect(match.length).toEqual(1),expect(match[0]).toEqual("ease-in"),expect(match.originalString).toBeFalsy()}),it("should match ease-out animation function in declaration in strict mode",function(){match=TimingFunctionUtils.timingFunctionMatch("animation-timing-function: ease-out;",!1),expect(match.length).toEqual(1),expect(match[0]).toEqual("ease-out"),expect(match.originalString).toBeFalsy()}),it("should match ease-in-out animation function in declaration in strict mode",function(){match=TimingFunctionUtils.timingFunctionMatch("animation-timing-function: ease-in-out;",!1),expect(match.length).toEqual(1),expect(match[0]).toEqual("ease-in-out"),expect(match.originalString).toBeFalsy()}),it("should match linear function in declaration in strict mode",function(){match=TimingFunctionUtils.timingFunctionMatch("transition-timing-function: linear;",!1),expect(match.length).toEqual(1),expect(match[0]).toEqual("linear"),expect(match.originalString).toBeFalsy()}),it("should match linear function value in lax mode",function(){match=TimingFunctionUtils.timingFunctionMatch("linear",!0),expect(match.length).toEqual(1),expect(match[0]).toEqual("linear"),expect(match.originalString).toBeFalsy()}),it("should match ease function in declaration in strict mode",function(){match=TimingFunctionUtils.timingFunctionMatch("transition-timing-function: ease;",!1),expect(match.length).toEqual(1),expect(match[0]).toEqual("ease"),expect(match.originalString).toBeFalsy()}),it("should match ease function value in lax mode",function(){match=TimingFunctionUtils.timingFunctionMatch("ease",!0),expect(match.length).toEqual(1),expect(match[0]).toEqual("ease"),expect(match.originalString).toBeFalsy()}),it("should match ease-in function in declaration in strict mode",function(){match=TimingFunctionUtils.timingFunctionMatch("transition-timing-function: ease-in;",!1),expect(match.length).toEqual(1),expect(match[0]).toEqual("ease-in"),expect(match.originalString).toBeFalsy()}),it("should match ease-in function value in lax mode",function(){match=TimingFunctionUtils.timingFunctionMatch("ease-in",!0),expect(match.length).toEqual(1),expect(match[0]).toEqual("ease-in"),expect(match.originalString).toBeFalsy()}),it("should match ease-out function in declaration in strict mode",function(){match=TimingFunctionUtils.timingFunctionMatch("transition-timing-function: ease-out;",!1),expect(match.length).toEqual(1),expect(match[0]).toEqual("ease-out"),expect(match.originalString).toBeFalsy()}),it("should match ease-out function value in lax mode",function(){match=TimingFunctionUtils.timingFunctionMatch("ease-out",!0),expect(match.length).toEqual(1),expect(match[0]).toEqual("ease-out"),expect(match.originalString).toBeFalsy()}),it("should match ease-in-out function in declaration in strict mode",function(){match=TimingFunctionUtils.timingFunctionMatch("transition-timing-function: ease-in-out;",!1),expect(match.length).toEqual(1),expect(match[0]).toEqual("ease-in-out"),expect(match.originalString).toBeFalsy()}),it("should match ease-in-out function value in lax mode",function(){match=TimingFunctionUtils.timingFunctionMatch("ease-in-out",!0),expect(match.length).toEqual(1),expect(match[0]).toEqual("ease-in-out"),expect(match.originalString).toBeFalsy()}),it("should correct cubic-bezier function with out-of-range X parameters",function(){testInvalidBezier("cubic-bezier(-.2, 0, 1.2, 1)",["cubic-bezier(0, 0, 1, 1)","0","0","1","1"])}),it("should correct cubic-bezier function with Infinity parameters",function(){testInvalidBezier("cubic-bezier(0, Infinity, 1, -Infinity)",["cubic-bezier(0, 0, 1, 1)","0","0","1","1"])}),it("should correct cubic-bezier function with non-numeric parameters",function(){testInvalidBezier("cubic-bezier(x1, y1, x2, y2)",["cubic-bezier(.42, 0, .58, 1)",".42","0",".58","1"])}),it("should correct cubic-bezier function with no parameters",function(){testInvalidBezier("cubic-bezier()",["cubic-bezier(.42, 0, .58, 1)",".42","0",".58","1"])}),it("should correct cubic-bezier function with 3 parameters",function(){testInvalidBezier("cubic-bezier(0, 0, 1)",["cubic-bezier(0, 0, 1, 1)","0","0","1","1"])}),it("should correct cubic-bezier function with 5 parameters",function(){testInvalidBezier("cubic-bezier(0, 0, 1, 1, 1)",["cubic-bezier(0, 0, 1, 1)","0","0","1","1"])}),it("should correct cubic-bezier function with trailing comma",function(){testInvalidBezier("cubic-bezier(.42, 0, .58, .5,)",["cubic-bezier(.42, 0, .58, .5)",".42","0",".58",".5"])}),it("should not match cubic-bezier function with invalid whitespace",function(){match=TimingFunctionUtils.timingFunctionMatch("cubic-bezier (0, 0, 1, 1)",!1),expect(match).toBeFalsy()}),it("should not match cubic-bezier function with UPPER-CASE",function(){match=TimingFunctionUtils.timingFunctionMatch("CUBIC-BEZIER(0, 0, 1, 1)",!1),expect(match).toBeFalsy()}),it("should not match unknown timing function",function(){match=TimingFunctionUtils.timingFunctionMatch("ease-out-in",!1),expect(match).toBeFalsy()}),it("should not match linear when not a timing function",function(){match=TimingFunctionUtils.timingFunctionMatch("background: linear-gradient(to bottom, blue, white);",!1),expect(match).toBeFalsy()})}),describe("TimingFunctionUtils for step functions",function(){var match;function testInvalidStep(str,expectedArray){var match=TimingFunctionUtils.timingFunctionMatch(str,!1);expectArraysToBeEqual(match,expectedArray),expect(match.originalString).toEqual(str)}it("should match steps function in strict mode",function(){match=TimingFunctionUtils.timingFunctionMatch("steps(3, start)",!1),expect(match).toBeTruthy(),expectArraysToBeEqual(match,["steps(3, start)","3","start"]),expect(match.originalString).toBeFalsy()}),it("should match steps function in lax mode",function(){match=TimingFunctionUtils.timingFunctionMatch("steps(3, start)",!0),expect(match).toBeTruthy(),expectArraysToBeEqual(match,["steps(3, start)","3","start"]),expect(match.originalString).toBeFalsy()}),it("should match steps function with second parameter of end",function(){expectArraysToBeEqual(match=TimingFunctionUtils.timingFunctionMatch("steps(12, end)",!1),["steps(12, end)","12","end"]),expect(match.originalString).toBeFalsy()}),it("should match steps function with only 1 parameter",function(){expectArraysToBeEqual(match=TimingFunctionUtils.timingFunctionMatch("steps(8)",!1),["steps(8)","8",void 0]),expect(match.originalString).toBeFalsy()}),it("should match steps function in full line of longhand css",function(){expectArraysToBeEqual(match=TimingFunctionUtils.timingFunctionMatch(" transition-timing-function: steps(5, start);",!1),["steps(5, start)","5","start"]),expect(match.originalString).toBeFalsy()}),it("should match steps function in full line of shorthand css",function(){expectArraysToBeEqual(match=TimingFunctionUtils.timingFunctionMatch(" transition: top 100ms steps(10) 0;",!1),["steps(10)","10",void 0]),expect(match.originalString).toBeFalsy()}),it("should match steps function with leading zeros",function(){expectArraysToBeEqual(match=TimingFunctionUtils.timingFunctionMatch("steps(04, end)",!1),["steps(04, end)","04","end"]),expect(match.originalString).toBeFalsy()}),it("should match steps function with no optional whitespace with 1 param",function(){expectArraysToBeEqual(match=TimingFunctionUtils.timingFunctionMatch("steps(3)",!1),["steps(3)","3",void 0]),expect(match.originalString).toBeFalsy()}),it("should match steps function with no optional whitespace with 2 params",function(){expectArraysToBeEqual(match=TimingFunctionUtils.timingFunctionMatch("steps(3,end)",!1),["steps(3,end)","3","end"]),expect(match.originalString).toBeFalsy()}),it("should match steps function with extra optional whitespace with 1 param",function(){expectArraysToBeEqual(match=TimingFunctionUtils.timingFunctionMatch("steps( 7 )",!1),["steps( 7 )","7",void 0]),expect(match.originalString).toBeFalsy()}),it("should match steps function with extra optional whitespace with 2 params",function(){expectArraysToBeEqual(match=TimingFunctionUtils.timingFunctionMatch("steps( 8 , start )",!1),["steps( 8 , start )","8","start"]),expect(match.originalString).toBeFalsy()}),it("should match step-start function in declaration in strict mode",function(){match=TimingFunctionUtils.timingFunctionMatch("transition-timing-function: step-start;",!1),expect(match.length).toEqual(1),expect(match[0]).toEqual("step-start"),expect(match.originalString).toBeFalsy()}),it("should match step-start function value in lax mode",function(){match=TimingFunctionUtils.timingFunctionMatch("step-start",!0),expect(match.length).toEqual(1),expect(match[0]).toEqual("step-start"),expect(match.originalString).toBeFalsy()}),it("should match step-end function in declaration in strict mode",function(){match=TimingFunctionUtils.timingFunctionMatch("transition-timing-function: step-end;",!1),expect(match.length).toEqual(1),expect(match[0]).toEqual("step-end"),expect(match.originalString).toBeFalsy()}),it("should match step-end function value in lax mode",function(){match=TimingFunctionUtils.timingFunctionMatch("step-end",!0),expect(match.length).toEqual(1),expect(match[0]).toEqual("step-end"),expect(match.originalString).toBeFalsy()}),it("should correct steps function with zero steps",function(){testInvalidStep("steps(0)",["steps(5, end)","5","end"])}),it("should correct steps function with a non-integer number of steps",function(){testInvalidStep("steps(3.0)",["steps(3, end)","3","end"])}),it("should correct steps function with a negative number of steps",function(){testInvalidStep("steps(-2)",["steps(5, end)","5","end"])}),it("should correct steps function with an infinite number of steps",function(){testInvalidStep("steps(Infinity,)",["steps(5, end)","5","end"])}),it("should correct steps function with NaN number of steps",function(){testInvalidStep("steps(NaN,)",["steps(5, end)","5","end"])}),it("should correct steps function with non-numeric number of steps",function(){testInvalidStep("steps(x)",["steps(5, end)","5","end"])}),it("should correct steps function with a string-value number of steps",function(){testInvalidStep("steps('3')",["steps(3, end)","3","end"])}),it("should correct steps function with no parameters",function(){testInvalidStep("steps()",["steps(5, end)","5","end"])}),it("should correct steps function with empty second parameter",function(){testInvalidStep("steps(1,)",["steps(1, end)","1","end"])}),it("should correct steps function with undefined second parameter",function(){testInvalidStep("steps(1, middle)",["steps(1, end)","1","end"])}),it("should correct steps function with typo in second parameter",function(){testInvalidStep("steps(1, satrt)",["steps(1, start)","1","start"])}),it("should correct steps function with a string as second parameter",function(){testInvalidStep("steps(1, 'start')",["steps(1, start)","1","start"])}),it("should correct steps function with 3 parameters",function(){testInvalidStep("steps(1, start, end)",["steps(1, start)","1","start"])}),it("should not match steps function with no parens",function(){match=TimingFunctionUtils.timingFunctionMatch("steps",!1),expect(match).toBeFalsy()}),it("should not match steps function with invalid whitespace",function(){match=TimingFunctionUtils.timingFunctionMatch("steps (1, end)",!1),expect(match).toBeFalsy()}),it("should not match steps function with UPPER-CASE",function(){match=TimingFunctionUtils.timingFunctionMatch("STEPS(12)",!1),expect(match).toBeFalsy()}),it("should not match unknown timing function",function(){match=TimingFunctionUtils.timingFunctionMatch("step",!1),expect(match).toBeFalsy()})}),describe("Bookmark Timing Function",function(){async function testOpenTimingFunction(cursor,start,end){await makeTimingFunctionEditor(cursor),expect(inline).toBeTruthy(),expect(inline._startBookmark.find().ch).toBe(start),expect(inline._endBookmark.find().ch).toBe(end)}beforeEach(function(){var mock=SpecRunnerUtils.createMockEditor(testContentCSS,"css");testDocument=mock.doc,testEditor=mock.editor}),afterEach(function(){SpecRunnerUtils.destroyMockEditor(testDocument),testEditor=null,testDocument=null,inline=null}),it("should bookmark cubic-bezier() function when opened in inline editor",async function(){await testOpenTimingFunction({line:3,ch:34},32,60)}),it("should bookmark linear function when opened in inline editor",async function(){await testOpenTimingFunction({line:5,ch:35},32,38)}),it("should bookmark second cubic-bezier() function when opened in inline editor",async function(){await testOpenTimingFunction({line:13,ch:80},75,107)}),it("should bookmark steps() function when opened in inline editor",async function(){await testOpenTimingFunction({line:17,ch:37},32,45)}),it("should bookmark step-start function when opened in inline editor",async function(){await testOpenTimingFunction({line:20,ch:40},32,42)}),it("should bookmark long, invalid cubic-bezier() function when opened in inline editor",async function(){await testOpenTimingFunction({line:25,ch:52},32,74)}),it("should bookmark empty, invalid cubic-bezier() function when opened in inline editor",async function(){await testOpenTimingFunction({line:26,ch:47},32,46)}),it("should bookmark long, invalid steps() function when opened in inline editor",async function(){await testOpenTimingFunction({line:30,ch:44},32,50)}),it("should bookmark empty, invalid steps() function when opened in inline editor",async function(){await testOpenTimingFunction({line:31,ch:45},32,39)})}),describe("TimingFunction editor UI",function(){var timingFuncEditor;function makeTimingFuncUI(initialTimingFunction,callback){var parent=$(window.document.body),match=TimingFunctionUtils.timingFunctionMatch(initialTimingFunction,!0),cb=callback||function(){};match.isBezier?timingFuncEditor=new BezierCurveEditor(parent,match,cb):match.isStep&&(timingFuncEditor=new StepEditor(parent,match,cb)),timingFuncEditor.getRootElement().css("display","none")}afterEach(function(){timingFuncEditor.getRootElement().remove(),timingFuncEditor=null}),describe("Initial Load and External Update",function(){it("should load the initial cubic-bezier function correctly",async function(){makeTimingFuncUI("cubic-bezier(.2, .3, .4, .5)"),expect(timingFuncEditor).toBeTruthy(),expect(timingFuncEditor._cubicBezierCoords).toBeTruthy(),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,[".2",".3",".4",".5"])}),it("should load externally updated cubic-bezier function correctly",function(){makeTimingFuncUI("cubic-bezier(.1, .3, .5, .7)");var matchUpdate=TimingFunctionUtils.timingFunctionMatch("cubic-bezier(.2, .4, .6, .8)",!0);timingFuncEditor.handleExternalUpdate(matchUpdate),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,[".2",".4",".6",".8"])}),it("should load the initial steps function correctly",function(){makeTimingFuncUI("steps(5, start)"),expect(timingFuncEditor).toBeTruthy(),expect(timingFuncEditor._stepParams).toBeTruthy(),expect(timingFuncEditor._stepParams.count).toEqual(5),expect(timingFuncEditor._stepParams.timing).toEqual("start")}),it("should load externally updated steps function correctly",function(){makeTimingFuncUI("steps(5, start)");var matchUpdate=TimingFunctionUtils.timingFunctionMatch("steps(6, end)",!0);timingFuncEditor.handleExternalUpdate(matchUpdate),expect(timingFuncEditor._stepParams.count).toEqual(6),expect(timingFuncEditor._stepParams.timing).toEqual("end")})}),describe("Conversions",function(){it("should convert linear function to cubic-bezier function parameters",function(){makeTimingFuncUI("linear"),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,["0","0","1","1"])}),it("should convert ease function to cubic-bezier function parameters",function(){makeTimingFuncUI("ease"),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,[".25",".1",".25","1"])}),it("should convert ease-in function to cubic-bezier function parameters",function(){makeTimingFuncUI("ease-in"),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,[".42","0","1","1"])}),it("should convert ease-out function to cubic-bezier function parameters",function(){makeTimingFuncUI("ease-out"),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,["0","0",".58","1"])}),it("should convert ease-in-out function to cubic-bezier function parameters",function(){makeTimingFuncUI("ease-in-out"),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,[".42","0",".58","1"])}),it("should convert step-start function to steps function parameters",function(){makeTimingFuncUI("step-start"),expect(timingFuncEditor).toBeTruthy(),expect(timingFuncEditor._stepParams).toBeTruthy(),expect(timingFuncEditor._stepParams.count).toEqual(1),expect(timingFuncEditor._stepParams.timing).toEqual("start")}),it("should convert step-end function to steps function parameters",function(){makeTimingFuncUI("step-end"),expect(timingFuncEditor._stepParams.count).toEqual(1),expect(timingFuncEditor._stepParams.timing).toEqual("end")})}),describe("Editing with Mouse",function(){function translatePointFromBezierToCanvas(bezierPoint){return[Math.round(150*bezierPoint[0]),Math.round(150*(1-bezierPoint[1])+75)]}function eventAtOffset(event,$item,offsets){$item.trigger($.Event(event,{pageX:$item.offset().left+offsets[0],pageY:$item.offset().top+offsets[1],which:1}))}function testCubicBezierClick(opts){var $item;makeTimingFuncUI("cubic-bezier(.42, 0, .58 ,1)"),eventAtOffset("click",$(timingFuncEditor[opts.item]),opts.clickAt),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,opts.expected)}function testCubicBezierDrag(opts){makeTimingFuncUI("cubic-bezier(.42, 0, .58 ,1)");var $downItem=$(timingFuncEditor[opts.downItem]),$dragItem=$(timingFuncEditor[opts.dragItem]);eventAtOffset("mousedown",$downItem,opts.clickAt),eventAtOffset("mousemove",$dragItem,opts.dragTo),$downItem.trigger("mouseup"),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,opts.expected)}it("should move point P1 on mousedown in curve",function(){testCubicBezierClick({item:"curve",clickAt:translatePointFromBezierToCanvas([.5,.1]),expected:[".5",".1",".58","1"]})}),it("should move point P2 on mousedown in curve",function(){testCubicBezierClick({item:"curve",clickAt:translatePointFromBezierToCanvas([.6,1.2]),expected:[".42","0",".6","1.2"]})}),it("should move point P1 on drag",function(){testCubicBezierDrag({downItem:"P1",clickAt:[5,5],dragItem:"curve",dragTo:translatePointFromBezierToCanvas([.6,-.1]),expected:[".6","-0.1",".58","1"]})}),it("should move point P2 on drag",function(){testCubicBezierDrag({downItem:"P2",clickAt:[5,5],dragItem:"curve",dragTo:translatePointFromBezierToCanvas([.8,.9]),expected:[".42","0",".8",".9"]})}),it("should not move point P2 x-value out-of-range on drag",function(){testCubicBezierDrag({downItem:"P2",clickAt:[5,5],dragItem:"curve",dragTo:translatePointFromBezierToCanvas([1.1,1]),expected:[".42","0","1","1"]})})}),describe("Editing with Keyboard",function(){function makeKeyEvent(opts){return $.Event("keydown",{keyCode:opts.key,shiftKey:!!opts.shift})}function triggerTimingFunctionEditorKey(opts){makeTimingFuncUI(opts.func,opts.callback);var $item=$(timingFuncEditor[opts.item]);$item.focus(),$item.trigger(makeKeyEvent(opts))}it("should increase P1 x-value by .02 on right arrow in cubic-bezier()",function(){triggerTimingFunctionEditorKey({func:"cubic-bezier(.42, 0, .58, 1)",item:"P1",key:KeyEvent.DOM_VK_RIGHT,shift:!1}),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,[".44","0",".58","1"])}),it("should increase P1 y-value by .1 on shift up arrow in cubic-bezier()",function(){triggerTimingFunctionEditorKey({func:"cubic-bezier(.42, 0, .58, 1)",item:"P1",key:KeyEvent.DOM_VK_UP,shift:!0}),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,[".42",".1",".58","1"])}),it("should decrease P2 x-value by .02 on left arrow in cubic-bezier()",function(){triggerTimingFunctionEditorKey({func:"cubic-bezier(.42, 0, .58, 1)",item:"P2",key:KeyEvent.DOM_VK_LEFT,shift:!1}),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,[".42","0",".56","1"])}),it("should decrease P2 y-value by .1 on shift down arrow in cubic-bezier()",function(){triggerTimingFunctionEditorKey({func:"cubic-bezier(.42, 0, .58 ,1)",item:"P2",key:KeyEvent.DOM_VK_DOWN,shift:!0}),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,[".42","0",".58",".9"])}),it("should not decrease P1 x-value below 0 on left arrow in cubic-bezier()",function(){triggerTimingFunctionEditorKey({func:"cubic-bezier(0, 0, 1, 1)",item:"P1",key:KeyEvent.DOM_VK_LEFT,shift:!1}),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,["0","0","1","1"])}),it("should not increase P2 x-value above 0 on shift right arrow in cubic-bezier()",function(){triggerTimingFunctionEditorKey({func:"cubic-bezier(0, 0, 1, 1)",item:"P2",key:KeyEvent.DOM_VK_RIGHT,shift:!0}),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,["0","0","1","1"])}),it("should call callback function after cubic-bezier edit in cubic-bezier()",function(){var calledBack=!1,_callback=function(timingFunctionString){calledBack=!0,expect(timingFunctionString).toBe("cubic-bezier(.42, .1, .58, 1)")};triggerTimingFunctionEditorKey({func:"cubic-bezier(.42, 0, .58 ,1)",item:"P1",key:KeyEvent.DOM_VK_UP,shift:!0,callback:_callback}),expectArraysToBeEqual(timingFuncEditor._cubicBezierCoords,[".42",".1",".58","1"]),expect(calledBack).toBeTruthy()}),it("should increase count by 1 on up arrow in steps()",function(){triggerTimingFunctionEditorKey({func:"steps(5)",item:"canvas",key:KeyEvent.DOM_VK_UP}),expect(timingFuncEditor._stepParams.count).toEqual(6)}),it("should decrease count by 1 on down arrow in steps()",function(){triggerTimingFunctionEditorKey({func:"steps(5)",item:"canvas",key:KeyEvent.DOM_VK_DOWN}),expect(timingFuncEditor._stepParams.count).toEqual(4)}),it("should change start to end on right arrow in steps()",function(){triggerTimingFunctionEditorKey({func:"steps(5, start)",item:"canvas",key:KeyEvent.DOM_VK_RIGHT}),expect(timingFuncEditor._stepParams.timing).toEqual("end")}),it("should change end to start on left arrow in steps()",function(){triggerTimingFunctionEditorKey({func:"steps(5, end)",item:"canvas",key:KeyEvent.DOM_VK_LEFT}),expect(timingFuncEditor._stepParams.timing).toEqual("start")}),it("should not decrease count to be less than 1 on down arrow in steps()",function(){triggerTimingFunctionEditorKey({func:"steps(1)",item:"canvas",key:KeyEvent.DOM_VK_DOWN}),expect(timingFuncEditor._stepParams.count).toEqual(1)}),it("should not change start to end on left arrow in steps()",function(){triggerTimingFunctionEditorKey({func:"steps(5, start)",item:"canvas",key:KeyEvent.DOM_VK_LEFT}),expect(timingFuncEditor._stepParams.timing).toEqual("start")}),it("should not change end to start on right arrow in steps()",function(){triggerTimingFunctionEditorKey({func:"steps(5, end)",item:"canvas",key:KeyEvent.DOM_VK_RIGHT}),expect(timingFuncEditor._stepParams.timing).toEqual("end")}),it("should call callback function after steps function edit",async function(){var calledBack=!1,_callback=function(timingFunctionString){calledBack=!0,expect(timingFunctionString).toBe("steps(5, start)")};triggerTimingFunctionEditorKey({func:"steps(4, start)",item:"canvas",key:KeyEvent.DOM_VK_UP,callback:_callback}),expect(timingFuncEditor._stepParams.count).toEqual(5),expect(calledBack).toBeTruthy()})})})})});