Use fixture files to requireStylesheet

This commit is contained in:
probablycorey
2013-03-05 17:03:28 -08:00
committed by Corey Johnson
parent 050c376e87
commit 9acd401b9e
2 changed files with 24 additions and 24 deletions

View File

@@ -63,37 +63,45 @@ describe "Window", ->
expect(atom.confirm).toHaveBeenCalled()
describe "requireStylesheet(path)", ->
it "synchronously loads the stylesheet at the given path and installs a style tag for it in the head", ->
$('head style[id*="atom.less"]').remove()
it "synchronously loads css at the given path and installs a style tag for it in the head", ->
cssPath = project.resolve('css.css')
lengthBefore = $('head style').length
requireStylesheet('atom.less')
requireStylesheet(cssPath)
expect($('head style').length).toBe lengthBefore + 1
styleElt = $('head style[id*="atom.less"]')
fullPath = require.resolve('atom.less')
expect(styleElt.attr('id')).toBe fullPath
expect(styleElt.text()).toBe parseLessFile(fullPath)
element = $('head style[id*="css.css"]')
expect(element.attr('id')).toBe cssPath
expect(element.text()).toBe fs.read(cssPath)
# doesn't append twice
requireStylesheet('atom.less')
requireStylesheet(cssPath)
expect($('head style').length).toBe lengthBefore + 1
$('head style[id*="css.css"]').remove()
it "synchronously loads and parses less files at the given path and installs a style tag for it in the head", ->
$('head style[id*="markdown.less"]').remove()
lessPath = project.resolve('sample.less')
lengthBefore = $('head style').length
requireStylesheet('markdown.less')
requireStylesheet(lessPath)
expect($('head style').length).toBe lengthBefore + 1
styleElt = $('head style[id*="markdown.less"]')
element = $('head style[id*="sample.less"]')
expect(element.attr('id')).toBe lessPath
expect(element.text()).toBe """
#header {
color: #4d926f;
}
h2 {
color: #4d926f;
}
fullPath = require.resolve('markdown.less')
expect(styleElt.attr('id')).toBe fullPath
expect(styleElt.text()).toBe parseLessFile(fullPath)
"""
# doesn't append twice
requireStylesheet('markdown.less')
requireStylesheet(lessPath)
expect($('head style').length).toBe lengthBefore + 1
$('head style[id*="sample.less"]').remove()
describe ".disableStyleSheet(path)", ->
it "removes styling applied by given stylesheet path", ->

View File

@@ -4,7 +4,6 @@ window.setUpEnvironment()
nakedLoad 'jasmine-jquery'
$ = require 'jquery'
_ = require 'underscore'
{less} = require 'less'
Keymap = require 'keymap'
Config = require 'config'
Point = require 'point'
@@ -214,13 +213,6 @@ window.setEditorHeightInLines = (editor, heightInChars, charHeight=editor.lineHe
editor.height(charHeight * heightInChars + editor.renderedLines.position().top)
$(window).trigger 'resize' # update editor's on-screen lines
window.parseLessFile = (path) ->
content = ""
(new less.Parser).parse __read(path), (e, tree) ->
throw new Error(e.message, file, e.line) if e
content = tree.toCSS()
content
$.fn.resultOfTrigger = (type) ->
event = $.Event(type)
this.trigger(event)