2011-12-28 03:42:29 +04:00
|
|
|
nakedLoad 'jasmine-jquery'
|
2011-12-17 02:42:38 +04:00
|
|
|
$ = require 'jquery'
|
|
|
|
_ = require 'underscore'
|
2012-03-08 01:45:26 +04:00
|
|
|
Keymap = require 'keymap'
|
2012-02-02 23:14:50 +04:00
|
|
|
Point = require 'point'
|
2012-06-19 23:00:18 +04:00
|
|
|
Project = require 'project'
|
2012-04-27 01:54:54 +04:00
|
|
|
Directory = require 'directory'
|
2012-06-30 02:08:16 +04:00
|
|
|
File = require 'file'
|
2012-06-21 02:06:45 +04:00
|
|
|
RootView = require 'root-view'
|
2012-06-30 02:08:16 +04:00
|
|
|
fs = require 'fs'
|
2012-01-17 08:03:48 +04:00
|
|
|
require 'window'
|
2012-06-27 03:38:06 +04:00
|
|
|
$native.showDevTools()
|
2012-01-28 05:33:02 +04:00
|
|
|
|
2012-06-02 02:22:24 +04:00
|
|
|
requireStylesheet "jasmine.css"
|
|
|
|
|
2012-04-14 01:11:33 +04:00
|
|
|
defaultTitle = document.title
|
2012-06-30 02:08:16 +04:00
|
|
|
pathsWithSubscriptions = null
|
2012-04-14 01:11:33 +04:00
|
|
|
|
2012-01-28 05:33:02 +04:00
|
|
|
beforeEach ->
|
2012-06-19 23:00:18 +04:00
|
|
|
window.fixturesProject = new Project(require.resolve('fixtures'))
|
2012-01-28 05:33:02 +04:00
|
|
|
window.resetTimeouts()
|
2012-06-30 02:08:16 +04:00
|
|
|
pathsWithSubscriptions = []
|
2011-12-23 22:43:32 +04:00
|
|
|
|
|
|
|
afterEach ->
|
2012-06-21 02:06:45 +04:00
|
|
|
delete window.rootView if window.rootView
|
2012-05-12 03:06:42 +04:00
|
|
|
$('#jasmine-content').empty()
|
2012-04-14 01:11:33 +04:00
|
|
|
document.title = defaultTitle
|
2012-06-30 02:08:16 +04:00
|
|
|
ensureNoPathSubscriptions()
|
2011-12-17 02:42:38 +04:00
|
|
|
|
2012-04-04 04:20:48 +04:00
|
|
|
window.keymap.bindKeys '*', 'meta-w': 'close'
|
2012-03-08 01:27:21 +04:00
|
|
|
$(document).on 'close', -> window.close()
|
2012-03-07 22:04:41 +04:00
|
|
|
|
2012-06-21 02:06:45 +04:00
|
|
|
# Don't load user configuration in specs, because it's variable
|
|
|
|
RootView.prototype.loadUserConfiguration = ->
|
|
|
|
|
2012-06-30 02:08:16 +04:00
|
|
|
for klass in [Directory, File]
|
|
|
|
klass.prototype.originalOn = klass.prototype.on
|
|
|
|
klass.prototype.on = (args...) ->
|
|
|
|
pathsWithSubscriptions.push(this) if @subscriptionCount() == 0
|
|
|
|
@originalOn(args...)
|
2012-04-27 01:54:54 +04:00
|
|
|
|
2012-06-30 02:08:16 +04:00
|
|
|
ensureNoPathSubscriptions = ->
|
2012-04-27 01:54:54 +04:00
|
|
|
totalSubscriptionCount = 0
|
2012-06-30 02:08:16 +04:00
|
|
|
for path in pathsWithSubscriptions
|
|
|
|
totalSubscriptionCount += path.subscriptionCount()
|
|
|
|
console.log "Non-zero subscription count on", path if path.subscriptionCount() > 0
|
2012-04-27 01:54:54 +04:00
|
|
|
|
|
|
|
if totalSubscriptionCount > 0
|
2012-06-30 02:08:16 +04:00
|
|
|
throw new Error("Total path subscription count was #{totalSubscriptionCount}, when it should have been 0.\nSee console for details.")
|
2012-04-27 01:54:54 +04:00
|
|
|
|
2012-01-27 03:45:49 +04:00
|
|
|
# Use underscore's definition of equality for toEqual assertions
|
|
|
|
jasmine.Env.prototype.equals_ = _.isEqual
|
|
|
|
|
2012-02-03 05:00:10 +04:00
|
|
|
emitObject = jasmine.StringPrettyPrinter.prototype.emitObject
|
|
|
|
jasmine.StringPrettyPrinter.prototype.emitObject = (obj) ->
|
2012-02-04 04:05:57 +04:00
|
|
|
if obj.inspect
|
|
|
|
@append obj.inspect()
|
2012-02-03 05:00:10 +04:00
|
|
|
else
|
|
|
|
emitObject.call(this, obj)
|
|
|
|
|
2012-05-09 20:56:31 +04:00
|
|
|
window.keyIdentifierForKey = (key) ->
|
|
|
|
if key.length > 1 # named key
|
|
|
|
key
|
2012-02-15 22:03:50 +04:00
|
|
|
else
|
2012-05-09 20:56:31 +04:00
|
|
|
charCode = key.toUpperCase().charCodeAt(0)
|
|
|
|
"U+00" + charCode.toString(16)
|
2012-01-12 10:02:47 +04:00
|
|
|
|
2012-05-09 20:56:31 +04:00
|
|
|
window.keydownEvent = (key, properties={}) ->
|
|
|
|
event = $.Event "keydown", _.extend({originalEvent: { keyIdentifier: keyIdentifierForKey(key) }}, properties)
|
|
|
|
# event.keystroke = (new Keymap).keystrokeStringForEvent(event)
|
2012-02-15 22:03:50 +04:00
|
|
|
event
|
2012-01-11 03:30:53 +04:00
|
|
|
|
2012-03-03 03:42:04 +04:00
|
|
|
window.mouseEvent = (type, properties) ->
|
|
|
|
if properties.point
|
|
|
|
{point, editor} = properties
|
|
|
|
{top, left} = @pagePixelPositionForPoint(editor, point)
|
|
|
|
properties.pageX = left + 1
|
|
|
|
properties.pageY = top + 1
|
2012-02-03 02:57:05 +04:00
|
|
|
properties.originalEvent ?= {detail: 1}
|
2012-03-03 03:42:04 +04:00
|
|
|
$.Event type, properties
|
|
|
|
|
2012-05-08 00:55:33 +04:00
|
|
|
window.clickEvent = (properties={}) ->
|
|
|
|
window.mouseEvent("click", properties)
|
|
|
|
|
2012-03-03 03:42:04 +04:00
|
|
|
window.mousedownEvent = (properties={}) ->
|
|
|
|
window.mouseEvent('mousedown', properties)
|
2012-01-29 05:00:59 +04:00
|
|
|
|
|
|
|
window.mousemoveEvent = (properties={}) ->
|
2012-03-03 03:42:04 +04:00
|
|
|
window.mouseEvent('mousemove', properties)
|
2012-01-29 05:00:59 +04:00
|
|
|
|
2012-01-04 03:39:09 +04:00
|
|
|
window.waitsForPromise = (fn) ->
|
|
|
|
window.waitsFor (moveOn) ->
|
2012-07-11 02:05:29 +04:00
|
|
|
promise = fn()
|
|
|
|
promise.then promise.done(moveOn), promise.fail(moveOn)
|
2012-01-04 03:39:09 +04:00
|
|
|
|
2012-01-28 05:33:02 +04:00
|
|
|
window.resetTimeouts = ->
|
|
|
|
window.now = 0
|
|
|
|
window.timeoutCount = 0
|
|
|
|
window.timeouts = []
|
|
|
|
|
|
|
|
window.setTimeout = (callback, ms) ->
|
|
|
|
id = ++window.timeoutCount
|
|
|
|
window.timeouts.push([id, window.now + ms, callback])
|
|
|
|
id
|
|
|
|
|
|
|
|
window.clearTimeout = (idToClear) ->
|
|
|
|
window.timeouts = window.timeouts.filter ([id]) -> id != idToClear
|
|
|
|
|
2012-03-09 02:04:54 +04:00
|
|
|
window.advanceClock = (delta=1) ->
|
2012-01-28 05:33:02 +04:00
|
|
|
window.now += delta
|
|
|
|
window.timeouts = window.timeouts.filter ([id, strikeTime, callback]) ->
|
|
|
|
if strikeTime <= window.now
|
|
|
|
callback()
|
|
|
|
false
|
|
|
|
else
|
|
|
|
true
|
|
|
|
|
2012-03-03 03:42:04 +04:00
|
|
|
window.pagePixelPositionForPoint = (editor, point) ->
|
2012-02-02 23:14:50 +04:00
|
|
|
point = Point.fromObject point
|
2012-06-05 04:53:58 +04:00
|
|
|
top = editor.renderedLines.offset().top + point.row * editor.lineHeight
|
|
|
|
left = editor.renderedLines.offset().left + point.column * editor.charWidth - editor.renderedLines.scrollLeft()
|
2012-03-03 03:42:04 +04:00
|
|
|
{ top, left }
|
2012-02-02 23:14:50 +04:00
|
|
|
|
2012-02-09 01:04:55 +04:00
|
|
|
window.tokensText = (tokens) ->
|
|
|
|
_.pluck(tokens, 'value').join('')
|
2012-02-03 04:25:23 +04:00
|
|
|
|
2012-03-03 05:09:45 +04:00
|
|
|
window.setEditorWidthInChars = (editor, widthInChars, charWidth=editor.charWidth) ->
|
2012-06-05 04:53:58 +04:00
|
|
|
editor.width(charWidth * widthInChars + editor.renderedLines.position().left)
|
2012-03-03 05:09:45 +04:00
|
|
|
|
2012-04-21 03:18:07 +04:00
|
|
|
window.setEditorHeightInLines = (editor, heightInChars, charHeight=editor.lineHeight) ->
|
2012-06-05 04:53:58 +04:00
|
|
|
editor.height(charHeight * heightInChars + editor.renderedLines.position().top)
|
2012-05-11 21:52:03 +04:00
|
|
|
$(window).trigger 'resize' # update editor's on-screen lines
|
2012-04-04 01:39:09 +04:00
|
|
|
|
2012-01-11 08:06:34 +04:00
|
|
|
$.fn.resultOfTrigger = (type) ->
|
|
|
|
event = $.Event(type)
|
|
|
|
this.trigger(event)
|
|
|
|
event.result
|
2012-01-11 23:42:22 +04:00
|
|
|
|
|
|
|
$.fn.enableKeymap = ->
|
2012-02-29 23:33:15 +04:00
|
|
|
@on 'keydown', (e) => window.keymap.handleKeyEvent(e)
|
2012-01-11 23:42:22 +04:00
|
|
|
|
2012-01-17 07:23:27 +04:00
|
|
|
$.fn.attachToDom = ->
|
|
|
|
$('#jasmine-content').append(this)
|
|
|
|
|
2012-04-17 21:37:01 +04:00
|
|
|
$.fn.simulateDomAttachment = ->
|
|
|
|
$('<html>').append(this)
|
|
|
|
|
2012-01-25 05:19:01 +04:00
|
|
|
$.fn.textInput = (data) ->
|
2012-04-19 20:14:45 +04:00
|
|
|
this.each ->
|
|
|
|
event = document.createEvent('TextEvent')
|
|
|
|
event.initTextEvent('textInput', true, true, window, data)
|
|
|
|
event = jQuery.event.fix(event)
|
|
|
|
$(this).trigger(event)
|
|
|
|
|
2012-04-20 04:39:59 +04:00
|
|
|
$.fn.simulateDomAttachment = ->
|
2012-04-27 01:54:54 +04:00
|
|
|
$('<html>').append(this)
|
2012-06-29 21:20:43 +04:00
|
|
|
|
2012-07-03 05:21:24 +04:00
|
|
|
unless fs.md5ForPath(require.resolve('fixtures/sample.js')) == "dd38087d0d7e3e4802a6d3f9b9745f2b"
|
|
|
|
throw "Sample.js is modified"
|