From bee12af4c1be4a57576f32461aba63c12da7fc04 Mon Sep 17 00:00:00 2001 From: Jason Rudolph Date: Mon, 22 May 2017 10:07:07 -0400 Subject: [PATCH] Move directional pane movement specs up to WorkspaceElement In preparation for providing directional pane navigation that goes beyond the currently-active pane container, this commit: - Moves the existing directional pane movement specs out of the PaneContainerElement specs and into the WorkspaceElement specs - Adjusts the specs to perform all set-up in terms of the workspace, as opposed to manually constructing a PaneContainer. --- spec/pane-container-element-spec.coffee | 189 ----------------- spec/workspace-element-spec.js | 262 ++++++++++++++++++++++++ 2 files changed, 262 insertions(+), 189 deletions(-) diff --git a/spec/pane-container-element-spec.coffee b/spec/pane-container-element-spec.coffee index 9f25e13eb..2035e1726 100644 --- a/spec/pane-container-element-spec.coffee +++ b/spec/pane-container-element-spec.coffee @@ -237,192 +237,3 @@ describe "PaneContainerElement", -> atom.commands.dispatch(rightPane.getElement(), 'pane:decrease-size') expect(leftPane.getFlexScale()).toBe 1/1.1 expect(rightPane.getFlexScale()).toBe 1/1.1 - - describe "changing focus, copying and moving items directionally between panes", -> - [item1, item2, item3, item4, item5, item6, item7, item8, item9, - pane1, pane2, pane3, pane4, pane5, pane6, pane7, pane8, pane9, - container, containerElement] = [] - - beforeEach -> - atom.config.set("core.destroyEmptyPanes", false) - - # Set up a grid of 9 panes, in the following arrangement, where the - # numbers correspond to the variable names below. - # - # ------- - # |1|2|3| - # ------- - # |4|5|6| - # ------- - # |7|8|9| - # ------- - - buildElement = (id) -> - element = document.createElement('div') - element.textContent = id - element.tabIndex = -1 - element.copy = -> - element.cloneNode(true) - element - - container = new PaneContainer(params) - - [item1, item2, item3, item4, item5, item6, item7, item8, item9] = - [buildElement('1'), buildElement('2'), buildElement('3'), - buildElement('4'), buildElement('5'), buildElement('6'), - buildElement('7'), buildElement('8'), buildElement('9')] - - pane1 = container.getActivePane() - pane1.activateItem(item1) - pane4 = pane1.splitDown(items: [item4]) - pane7 = pane4.splitDown(items: [item7]) - - pane2 = pane1.splitRight(items: [item2]) - pane3 = pane2.splitRight(items: [item3]) - - pane5 = pane4.splitRight(items: [item5]) - pane6 = pane5.splitRight(items: [item6]) - - pane8 = pane7.splitRight(items: [item8]) - pane9 = pane8.splitRight(items: [item9]) - - containerElement = container.getElement() - containerElement.style.height = '400px' - containerElement.style.width = '400px' - jasmine.attachToDOM(containerElement) - - describe "::focusPaneViewAbove()", -> - describe "when there are multiple rows above the focused pane", -> - it "focuses up to the adjacent row", -> - pane8.activate() - containerElement.focusPaneViewAbove() - expect(document.activeElement).toBe pane5.getActiveItem() - - describe "when there are no rows above the focused pane", -> - it "keeps the current pane focused", -> - pane2.activate() - containerElement.focusPaneViewAbove() - expect(document.activeElement).toBe pane2.getActiveItem() - - describe "::focusPaneViewBelow()", -> - describe "when there are multiple rows below the focused pane", -> - it "focuses down to the adjacent row", -> - pane2.activate() - containerElement.focusPaneViewBelow() - expect(document.activeElement).toBe pane5.getActiveItem() - - describe "when there are no rows below the focused pane", -> - it "keeps the current pane focused", -> - pane8.activate() - containerElement.focusPaneViewBelow() - expect(document.activeElement).toBe pane8.getActiveItem() - - describe "::focusPaneViewOnLeft()", -> - describe "when there are multiple columns to the left of the focused pane", -> - it "focuses left to the adjacent column", -> - pane6.activate() - containerElement.focusPaneViewOnLeft() - expect(document.activeElement).toBe pane5.getActiveItem() - - describe "when there are no columns to the left of the focused pane", -> - it "keeps the current pane focused", -> - pane4.activate() - containerElement.focusPaneViewOnLeft() - expect(document.activeElement).toBe pane4.getActiveItem() - - describe "::focusPaneViewOnRight()", -> - describe "when there are multiple columns to the right of the focused pane", -> - it "focuses right to the adjacent column", -> - pane4.activate() - containerElement.focusPaneViewOnRight() - expect(document.activeElement).toBe pane5.getActiveItem() - - describe "when there are no columns to the right of the focused pane", -> - it "keeps the current pane focused", -> - pane6.activate() - containerElement.focusPaneViewOnRight() - expect(document.activeElement).toBe pane6.getActiveItem() - - describe "::moveActiveItemToPaneAbove(keepOriginal)", -> - describe "when there are multiple rows above the focused pane", -> - it "moves the active item up to the adjacent row", -> - pane8.activate() - containerElement.moveActiveItemToPaneAbove() - expect(container.paneForItem(item8)).toBe pane5 - expect(pane5.getActiveItem()).toBe item8 - - describe "when there are no rows above the focused pane", -> - it "keeps the active item in the focused pane", -> - pane2.activate() - containerElement.moveActiveItemToPaneAbove() - expect(container.paneForItem(item2)).toBe pane2 - - describe "when `keepOriginal: true` is passed in the params", -> - it "keeps the item and adds a copy of it to the adjacent pane", -> - pane8.activate() - containerElement.moveActiveItemToPaneAbove(keepOriginal: true) - expect(container.paneForItem(item8)).toBe pane8 - expect(pane5.getActiveItem().textContent).toBe '8' - - describe "::moveActiveItemToPaneBelow(keepOriginal)", -> - describe "when there are multiple rows below the focused pane", -> - it "moves the active item down to the adjacent row", -> - pane2.activate() - containerElement.moveActiveItemToPaneBelow() - expect(container.paneForItem(item2)).toBe pane5 - expect(pane5.getActiveItem()).toBe item2 - - describe "when there are no rows below the focused pane", -> - it "keeps the active item in the focused pane", -> - pane8.activate() - containerElement.moveActiveItemToPaneBelow() - expect(container.paneForItem(item8)).toBe pane8 - - describe "when `keepOriginal: true` is passed in the params", -> - it "keeps the item and adds a copy of it to the adjacent pane", -> - pane2.activate() - containerElement.moveActiveItemToPaneBelow(keepOriginal: true) - expect(container.paneForItem(item2)).toBe pane2 - expect(pane5.getActiveItem().textContent).toBe '2' - - describe "::moveActiveItemToPaneOnLeft(keepOriginal)", -> - describe "when there are multiple columns to the left of the focused pane", -> - it "moves the active item left to the adjacent column", -> - pane6.activate() - containerElement.moveActiveItemToPaneOnLeft() - expect(container.paneForItem(item6)).toBe pane5 - expect(pane5.getActiveItem()).toBe item6 - - describe "when there are no columns to the left of the focused pane", -> - it "keeps the active item in the focused pane", -> - pane4.activate() - containerElement.moveActiveItemToPaneOnLeft() - expect(container.paneForItem(item4)).toBe pane4 - - describe "when `keepOriginal: true` is passed in the params", -> - it "keeps the item and adds a copy of it to the adjacent pane", -> - pane6.activate() - containerElement.moveActiveItemToPaneOnLeft(keepOriginal: true) - expect(container.paneForItem(item6)).toBe pane6 - expect(pane5.getActiveItem().textContent).toBe '6' - - describe "::moveActiveItemToPaneOnRight(keepOriginal)", -> - describe "when there are multiple columns to the right of the focused pane", -> - it "moves the active item right to the adjacent column", -> - pane4.activate() - containerElement.moveActiveItemToPaneOnRight() - expect(container.paneForItem(item4)).toBe pane5 - expect(pane5.getActiveItem()).toBe item4 - - describe "when there are no columns to the right of the focused pane", -> - it "keeps the active item in the focused pane", -> - pane6.activate() - containerElement.moveActiveItemToPaneOnRight() - expect(container.paneForItem(item6)).toBe pane6 - - describe "when `keepOriginal: true` is passed in the params", -> - it "keeps the item and adds a copy of it to the adjacent pane", -> - pane4.activate() - containerElement.moveActiveItemToPaneOnRight(keepOriginal: true) - expect(container.paneForItem(item4)).toBe pane4 - expect(pane5.getActiveItem().textContent).toBe '4' diff --git a/spec/workspace-element-spec.js b/spec/workspace-element-spec.js index ea597c0aa..83d85f742 100644 --- a/spec/workspace-element-spec.js +++ b/spec/workspace-element-spec.js @@ -5,6 +5,7 @@ const {ipcRenderer} = require('electron') const path = require('path') const temp = require('temp').track() +const PaneContainer = require('../src/pane-container') const {Disposable} = require('event-kit') const {it, fit, ffit, fffit, beforeEach, afterEach} = require('./async-spec-helpers') @@ -34,6 +35,267 @@ describe('WorkspaceElement', () => { }) }) + describe('changing focus, copying, and moving items directionally between panes', function () { + let pane1, pane2, pane3, pane4, pane5, pane6, pane7, pane8, pane9, + workspace, containerElement + + beforeEach(function () { + atom.config.set('core.destroyEmptyPanes', false) + expect(document.hasFocus()).toBe(true, 'Document needs to be focused to run this test') + + workspace = atom.workspace + + // Set up a grid of 9 panes, in the following arrangement, where the + // numbers correspond to the variable names below. + // + // ------- + // |1|2|3| + // ------- + // |4|5|6| + // ------- + // |7|8|9| + // ------- + + const container = workspace.getActivePaneContainer() + expect(container.getLocation()).toEqual('center') + expect(container.getPanes().length).toEqual(1) + + pane1 = container.getActivePane() + pane4 = pane1.splitDown() + pane7 = pane4.splitDown() + + pane2 = pane1.splitRight() + pane3 = pane2.splitRight() + + pane5 = pane4.splitRight() + pane6 = pane5.splitRight() + + pane8 = pane7.splitRight() + pane9 = pane8.splitRight() + + containerElement = container.paneContainer.getElement() + containerElement.style.height = '400px' + containerElement.style.width = '400px' + jasmine.attachToDOM(containerElement) + }) + + describe('::focusPaneViewAbove()', function () { + describe('when there are multiple rows above the focused pane', () => + it('focuses up to the adjacent row', function () { + pane8.activate() + containerElement.focusPaneViewAbove() + expect(document.activeElement).toBe(pane5.getElement()) + }) + ) + + describe('when there are no rows above the focused pane', () => + it('keeps the current pane focused', function () { + pane2.activate() + containerElement.focusPaneViewAbove() + expect(document.activeElement).toBe(pane2.getElement()) + }) + ) + }) + + describe('::focusPaneViewBelow()', function () { + describe('when there are multiple rows below the focused pane', () => + it('focuses down to the adjacent row', function () { + pane2.activate() + containerElement.focusPaneViewBelow() + expect(document.activeElement).toBe(pane5.getElement()) + }) + ) + + describe('when there are no rows below the focused pane', () => + it('keeps the current pane focused', function () { + pane8.activate() + containerElement.focusPaneViewBelow() + expect(document.activeElement).toBe(pane8.getElement()) + }) + ) + }) + + describe('::focusPaneViewOnLeft()', function () { + describe('when there are multiple columns to the left of the focused pane', () => + it('focuses left to the adjacent column', function () { + pane6.activate() + containerElement.focusPaneViewOnLeft() + expect(document.activeElement).toBe(pane5.getElement()) + }) + ) + + describe('when there are no columns to the left of the focused pane', () => + it('keeps the current pane focused', function () { + pane4.activate() + containerElement.focusPaneViewOnLeft() + expect(document.activeElement).toBe(pane4.getElement()) + }) + ) + }) + + describe('::focusPaneViewOnRight()', function () { + describe('when there are multiple columns to the right of the focused pane', () => + it('focuses right to the adjacent column', function () { + pane4.activate() + containerElement.focusPaneViewOnRight() + expect(document.activeElement).toBe(pane5.getElement()) + }) + ) + + describe('when there are no columns to the right of the focused pane', () => + it('keeps the current pane focused', function () { + pane6.activate() + containerElement.focusPaneViewOnRight() + expect(document.activeElement).toBe(pane6.getElement()) + }) + ) + }) + + describe('::moveActiveItemToPaneAbove(keepOriginal)', function () { + describe('when there are multiple rows above the focused pane', () => + it('moves the active item up to the adjacent row', function () { + const item = document.createElement('div') + pane8.activate() + pane8.activateItem(item) + containerElement.moveActiveItemToPaneAbove() + expect(workspace.paneForItem(item)).toBe(pane5) + expect(pane5.getActiveItem()).toBe(item) + }) + ) + + describe('when there are no rows above the focused pane', () => + it('keeps the active pane focused', function () { + const item = document.createElement('div') + pane2.activate() + pane2.activateItem(item) + containerElement.moveActiveItemToPaneAbove() + expect(workspace.paneForItem(item)).toBe(pane2) + }) + ) + + describe('when `keepOriginal: true` is passed in the params', () => + it('keeps the item and adds a copy of it to the adjacent pane', function () { + const itemA = document.createElement('div') + const itemB = document.createElement('div') + itemA.copy = () => itemB + pane8.activate() + pane8.activateItem(itemA) + containerElement.moveActiveItemToPaneAbove({keepOriginal: true}) + expect(workspace.paneForItem(itemA)).toBe(pane8) + expect(pane5.getActiveItem()).toBe(itemB) + }) + ) + }) + + describe('::moveActiveItemToPaneBelow(keepOriginal)', function () { + describe('when there are multiple rows below the focused pane', () => + it('moves the active item down to the adjacent row', function () { + const item = document.createElement('div') + pane2.activate() + pane2.activateItem(item) + containerElement.moveActiveItemToPaneBelow() + expect(workspace.paneForItem(item)).toBe(pane5) + expect(pane5.getActiveItem()).toBe(item) + }) + ) + + describe('when there are no rows below the focused pane', () => + it('keeps the active item in the focused pane', function () { + const item = document.createElement('div') + pane8.activate() + pane8.activateItem(item) + containerElement.moveActiveItemToPaneBelow() + expect(workspace.paneForItem(item)).toBe(pane8) + }) + ) + + describe('when `keepOriginal: true` is passed in the params', () => + it('keeps the item and adds a copy of it to the adjacent pane', function () { + const itemA = document.createElement('div') + const itemB = document.createElement('div') + itemA.copy = () => itemB + pane2.activate() + pane2.activateItem(itemA) + containerElement.moveActiveItemToPaneBelow({keepOriginal: true}) + expect(workspace.paneForItem(itemA)).toBe(pane2) + expect(pane5.getActiveItem()).toBe(itemB) + }) + ) + }) + + describe('::moveActiveItemToPaneOnLeft(keepOriginal)', function () { + describe('when there are multiple columns to the left of the focused pane', () => + it('moves the active item left to the adjacent column', function () { + const item = document.createElement('div') + pane6.activate() + pane6.activateItem(item) + containerElement.moveActiveItemToPaneOnLeft() + expect(workspace.paneForItem(item)).toBe(pane5) + expect(pane5.getActiveItem()).toBe(item) + }) + ) + + describe('when there are no columns to the left of the focused pane', () => + it('keeps the active item in the focused pane', function () { + const item = document.createElement('div') + pane4.activate() + pane4.activateItem(item) + containerElement.moveActiveItemToPaneOnLeft() + expect(workspace.paneForItem(item)).toBe(pane4) + }) + ) + + describe('when `keepOriginal: true` is passed in the params', () => + it('keeps the item and adds a copy of it to the adjacent pane', function () { + const itemA = document.createElement('div') + const itemB = document.createElement('div') + itemA.copy = () => itemB + pane6.activate() + pane6.activateItem(itemA) + containerElement.moveActiveItemToPaneOnLeft({keepOriginal: true}) + expect(workspace.paneForItem(itemA)).toBe(pane6) + expect(pane5.getActiveItem()).toBe(itemB) + }) + ) + }) + + describe('::moveActiveItemToPaneOnRight(keepOriginal)', function () { + describe('when there are multiple columns to the right of the focused pane', () => + it('moves the active item right to the adjacent column', function () { + const item = document.createElement('div') + pane4.activate() + pane4.activateItem(item) + containerElement.moveActiveItemToPaneOnRight() + expect(workspace.paneForItem(item)).toBe(pane5) + expect(pane5.getActiveItem()).toBe(item) + }) + ) + + describe('when there are no columns to the right of the focused pane', () => + it('keeps the active item in the focused pane', function () { + const item = document.createElement('div') + pane6.activate() + pane6.activateItem(item) + containerElement.moveActiveItemToPaneOnRight() + expect(workspace.paneForItem(item)).toBe(pane6) + }) + ) + + describe('when `keepOriginal: true` is passed in the params', () => + it('keeps the item and adds a copy of it to the adjacent pane', function () { + const itemA = document.createElement('div') + const itemB = document.createElement('div') + itemA.copy = () => itemB + pane4.activate() + pane4.activateItem(itemA) + containerElement.moveActiveItemToPaneOnRight({keepOriginal: true}) + expect(workspace.paneForItem(itemA)).toBe(pane4) + expect(pane5.getActiveItem()).toBe(itemB) + }) + ) + }) + }) + describe('mousing over docks', () => { let workspaceElement