mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Fix Workspace spec
This commit is contained in:
@@ -657,17 +657,6 @@ describe('Workspace', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the file is over 2MB', () => {
|
||||
it('opens the editor with largeFileMode: true', () => {
|
||||
spyOn(fs, 'getSizeSync').andReturn(2 * 1048577) // 2MB
|
||||
|
||||
let editor = null
|
||||
waitsForPromise(() => workspace.open('sample.js').then(e => { editor = e }))
|
||||
|
||||
runs(() => expect(editor.largeFileMode).toBe(true))
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the file is over user-defined limit', () => {
|
||||
const shouldPromptForFileOfSize = (size, shouldPrompt) => {
|
||||
spyOn(fs, 'getSizeSync').andReturn(size * 1048577)
|
||||
@@ -690,7 +679,6 @@ describe('Workspace', () => {
|
||||
|
||||
runs(() => {
|
||||
expect(atom.applicationDelegate.confirm).toHaveBeenCalled()
|
||||
expect(editor.largeFileMode).toBe(true)
|
||||
})
|
||||
} else {
|
||||
runs(() => expect(editor).not.toBeUndefined())
|
||||
@@ -1238,29 +1226,22 @@ describe('Workspace', () => {
|
||||
})
|
||||
|
||||
describe('the grammar-used hook', () => {
|
||||
it('fires when opening a file or changing the grammar of an open file', () => {
|
||||
let editor = null
|
||||
let javascriptGrammarUsed = false
|
||||
let coffeescriptGrammarUsed = false
|
||||
it('fires when opening a file or changing the grammar of an open file', async () => {
|
||||
let resolveJavascriptGrammarUsed, resolveCoffeeScriptGrammarUsed
|
||||
const javascriptGrammarUsed = new Promise(resolve => { resolveJavascriptGrammarUsed = resolve })
|
||||
const coffeescriptGrammarUsed = new Promise(resolve => { resolveCoffeeScriptGrammarUsed = resolve })
|
||||
|
||||
atom.packages.triggerDeferredActivationHooks()
|
||||
atom.packages.onDidTriggerActivationHook('language-javascript:grammar-used', resolveJavascriptGrammarUsed)
|
||||
atom.packages.onDidTriggerActivationHook('language-coffee-script:grammar-used', resolveCoffeeScriptGrammarUsed)
|
||||
|
||||
runs(() => {
|
||||
atom.packages.onDidTriggerActivationHook('language-javascript:grammar-used', () => { javascriptGrammarUsed = true })
|
||||
atom.packages.onDidTriggerActivationHook('language-coffee-script:grammar-used', () => { coffeescriptGrammarUsed = true })
|
||||
})
|
||||
const editor = await atom.workspace.open('sample.js', {autoIndent: false})
|
||||
await atom.packages.activatePackage('language-javascript')
|
||||
await javascriptGrammarUsed
|
||||
|
||||
waitsForPromise(() => atom.workspace.open('sample.js', {autoIndent: false}).then(o => { editor = o }))
|
||||
|
||||
waitsForPromise(() => atom.packages.activatePackage('language-javascript'))
|
||||
|
||||
waitsFor(() => javascriptGrammarUsed)
|
||||
|
||||
waitsForPromise(() => atom.packages.activatePackage('language-coffee-script'))
|
||||
|
||||
runs(() => editor.setGrammar(atom.grammars.selectGrammar('.coffee')))
|
||||
|
||||
waitsFor(() => coffeescriptGrammarUsed)
|
||||
await atom.packages.activatePackage('language-coffee-script')
|
||||
atom.grammars.assignLanguageMode(editor, 'coffeescript')
|
||||
await coffeescriptGrammarUsed
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1522,34 +1503,27 @@ describe('Workspace', () => {
|
||||
})
|
||||
|
||||
describe('when an editor is destroyed', () => {
|
||||
it('removes the editor', () => {
|
||||
let editor = null
|
||||
|
||||
waitsForPromise(() => workspace.open('a').then(e => { editor = e }))
|
||||
|
||||
runs(() => {
|
||||
expect(workspace.getTextEditors()).toHaveLength(1)
|
||||
editor.destroy()
|
||||
expect(workspace.getTextEditors()).toHaveLength(0)
|
||||
})
|
||||
it('removes the editor', async () => {
|
||||
const editor = await workspace.open('a')
|
||||
expect(workspace.getTextEditors()).toHaveLength(1)
|
||||
editor.destroy()
|
||||
expect(workspace.getTextEditors()).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when an editor is copied because its pane is split', () => {
|
||||
it('sets up the new editor to be configured by the text editor registry', () => {
|
||||
waitsForPromise(() => atom.packages.activatePackage('language-javascript'))
|
||||
it('sets up the new editor to be configured by the text editor registry', async () => {
|
||||
await atom.packages.activatePackage('language-javascript')
|
||||
|
||||
waitsForPromise(() =>
|
||||
workspace.open('a').then(editor => {
|
||||
atom.textEditors.setGrammarOverride(editor, 'source.js')
|
||||
expect(editor.getGrammar().name).toBe('JavaScript')
|
||||
const editor = await workspace.open('a')
|
||||
|
||||
workspace.getActivePane().splitRight({copyActiveItem: true})
|
||||
const newEditor = workspace.getActiveTextEditor()
|
||||
expect(newEditor).not.toBe(editor)
|
||||
expect(newEditor.getGrammar().name).toBe('JavaScript')
|
||||
})
|
||||
)
|
||||
atom.grammars.assignLanguageMode(editor, 'javascript')
|
||||
expect(editor.getGrammar().name).toBe('JavaScript')
|
||||
|
||||
workspace.getActivePane().splitRight({copyActiveItem: true})
|
||||
const newEditor = workspace.getActiveTextEditor()
|
||||
expect(newEditor).not.toBe(editor)
|
||||
expect(newEditor.getGrammar().name).toBe('JavaScript')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -2790,7 +2764,7 @@ i = /test/; #FIXME\
|
||||
})
|
||||
|
||||
describe('grammar activation', () => {
|
||||
it('notifies the workspace of which grammar is used', () => {
|
||||
it('notifies the workspace of which grammar is used', async () => {
|
||||
atom.packages.triggerDeferredActivationHooks()
|
||||
|
||||
const javascriptGrammarUsed = jasmine.createSpy('js grammar used')
|
||||
@@ -2801,24 +2775,22 @@ i = /test/; #FIXME\
|
||||
atom.packages.onDidTriggerActivationHook('language-ruby:grammar-used', rubyGrammarUsed)
|
||||
atom.packages.onDidTriggerActivationHook('language-c:grammar-used', cGrammarUsed)
|
||||
|
||||
waitsForPromise(() => atom.packages.activatePackage('language-ruby'))
|
||||
waitsForPromise(() => atom.packages.activatePackage('language-javascript'))
|
||||
waitsForPromise(() => atom.packages.activatePackage('language-c'))
|
||||
waitsForPromise(() => atom.workspace.open('sample-with-comments.js'))
|
||||
await atom.packages.activatePackage('language-ruby')
|
||||
await atom.packages.activatePackage('language-javascript')
|
||||
await atom.packages.activatePackage('language-c')
|
||||
await atom.workspace.open('sample-with-comments.js')
|
||||
|
||||
runs(() => {
|
||||
// Hooks are triggered when opening new editors
|
||||
expect(javascriptGrammarUsed).toHaveBeenCalled()
|
||||
// Hooks are triggered when opening new editors
|
||||
expect(javascriptGrammarUsed).toHaveBeenCalled()
|
||||
|
||||
// Hooks are triggered when changing existing editors grammars
|
||||
atom.workspace.getActiveTextEditor().setGrammar(atom.grammars.grammarForScopeName('source.c'))
|
||||
expect(cGrammarUsed).toHaveBeenCalled()
|
||||
// Hooks are triggered when changing existing editors grammars
|
||||
atom.grammars.assignLanguageMode(atom.workspace.getActiveTextEditor(), 'c')
|
||||
expect(cGrammarUsed).toHaveBeenCalled()
|
||||
|
||||
// Hooks are triggered when editors are added in other ways.
|
||||
atom.workspace.getActivePane().splitRight({copyActiveItem: true})
|
||||
atom.workspace.getActiveTextEditor().setGrammar(atom.grammars.grammarForScopeName('source.ruby'))
|
||||
expect(rubyGrammarUsed).toHaveBeenCalled()
|
||||
})
|
||||
// Hooks are triggered when editors are added in other ways.
|
||||
atom.workspace.getActivePane().splitRight({copyActiveItem: true})
|
||||
atom.grammars.assignLanguageMode(atom.workspace.getActiveTextEditor(), 'ruby')
|
||||
expect(rubyGrammarUsed).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user