···11+# Keybindings require three things to be fully defined: A selector that is
22+# matched against the focused element, the keystroke and the command to
33+# execute.
44+#
55+# Below is a basic keybinding which registers on all platforms by applying to
66+# the root workspace element.
77+88+# For more detailed documentation see
99+# https://atom.io/docs/latest/behind-atom-keymaps-in-depth
1010+'atom-workspace':
1111+ 'ctrl-alt-o': 'minisuite:toggle'
+22
lib/minisuite-view.coffee
···11+module.exports =
22+class MinisuiteView
33+ constructor: (serializedState) ->
44+ # Create root element
55+ @element = document.createElement('div')
66+ @element.classList.add('minisuite')
77+88+ # Create message element
99+ message = document.createElement('div')
1010+ message.textContent = "The Minisuite package is Alive! It's ALIVE!"
1111+ message.classList.add('message')
1212+ @element.appendChild(message)
1313+1414+ # Returns an object that can be retrieved when package is activated
1515+ serialize: ->
1616+1717+ # Tear down any state and detach
1818+ destroy: ->
1919+ @element.remove()
2020+2121+ getElement: ->
2222+ @element
+33
lib/minisuite.coffee
···11+MinisuiteView = require './minisuite-view'
22+{CompositeDisposable} = require 'atom'
33+44+module.exports = Minisuite =
55+ minisuiteView: null
66+ modalPanel: null
77+ subscriptions: null
88+99+ activate: (state) ->
1010+ @minisuiteView = new MinisuiteView(state.minisuiteViewState)
1111+ @modalPanel = atom.workspace.addModalPanel(item: @minisuiteView.getElement(), visible: false)
1212+1313+ # Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
1414+ @subscriptions = new CompositeDisposable
1515+1616+ # Register command that toggles this view
1717+ @subscriptions.add atom.commands.add 'atom-workspace', 'minisuite:toggle': => @toggle()
1818+1919+ deactivate: ->
2020+ @modalPanel.destroy()
2121+ @subscriptions.dispose()
2222+ @minisuiteView.destroy()
2323+2424+ serialize: ->
2525+ minisuiteViewState: @minisuiteView.serialize()
2626+2727+ toggle: ->
2828+ console.log 'Minisuite was toggled!'
2929+3030+ if @modalPanel.isVisible()
3131+ @modalPanel.hide()
3232+ else
3333+ @modalPanel.show()
···11+Minisuite = require '../lib/minisuite'
22+33+# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
44+#
55+# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
66+# or `fdescribe`). Remove the `f` to unfocus the block.
77+88+describe "Minisuite", ->
99+ [workspaceElement, activationPromise] = []
1010+1111+ beforeEach ->
1212+ workspaceElement = atom.views.getView(atom.workspace)
1313+ activationPromise = atom.packages.activatePackage('minisuite')
1414+1515+ describe "when the minisuite:toggle event is triggered", ->
1616+ it "hides and shows the modal panel", ->
1717+ # Before the activation event the view is not on the DOM, and no panel
1818+ # has been created
1919+ expect(workspaceElement.querySelector('.minisuite')).not.toExist()
2020+2121+ # This is an activation event, triggering it will cause the package to be
2222+ # activated.
2323+ atom.commands.dispatch workspaceElement, 'minisuite:toggle'
2424+2525+ waitsForPromise ->
2626+ activationPromise
2727+2828+ runs ->
2929+ expect(workspaceElement.querySelector('.minisuite')).toExist()
3030+3131+ minisuiteElement = workspaceElement.querySelector('.minisuite')
3232+ expect(minisuiteElement).toExist()
3333+3434+ minisuitePanel = atom.workspace.panelForItem(minisuiteElement)
3535+ expect(minisuitePanel.isVisible()).toBe true
3636+ atom.commands.dispatch workspaceElement, 'minisuite:toggle'
3737+ expect(minisuitePanel.isVisible()).toBe false
3838+3939+ it "hides and shows the view", ->
4040+ # This test shows you an integration test testing at the view level.
4141+4242+ # Attaching the workspaceElement to the DOM is required to allow the
4343+ # `toBeVisible()` matchers to work. Anything testing visibility or focus
4444+ # requires that the workspaceElement is on the DOM. Tests that attach the
4545+ # workspaceElement to the DOM are generally slower than those off DOM.
4646+ jasmine.attachToDOM(workspaceElement)
4747+4848+ expect(workspaceElement.querySelector('.minisuite')).not.toExist()
4949+5050+ # This is an activation event, triggering it causes the package to be
5151+ # activated.
5252+ atom.commands.dispatch workspaceElement, 'minisuite:toggle'
5353+5454+ waitsForPromise ->
5555+ activationPromise
5656+5757+ runs ->
5858+ # Now we can test for view visibility
5959+ minisuiteElement = workspaceElement.querySelector('.minisuite')
6060+ expect(minisuiteElement).toBeVisible()
6161+ atom.commands.dispatch workspaceElement, 'minisuite:toggle'
6262+ expect(minisuiteElement).not.toBeVisible()
+5
spec/minisuite-view-spec.coffee
···11+MinisuiteView = require '../lib/minisuite-view'
22+33+describe "MinisuiteView", ->
44+ it "has one valid test", ->
55+ expect("life").toBe "easy"
+8
styles/minisuite.less
···11+// The ui-variables file is provided by base themes provided by Atom.
22+//
33+// See https://github.com/atom/atom-dark-ui/blob/master/styles/ui-variables.less
44+// for a full listing of what's available.
55+@import "ui-variables";
66+77+.minisuite {
88+}