forked from atom/atom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkspace-element-spec.js
933 lines (798 loc) · 37.6 KB
/
workspace-element-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
/** @babel */
const {ipcRenderer} = require('electron')
const etch = require('etch')
const path = require('path')
const temp = require('temp').track()
const {Disposable} = require('event-kit')
const {it, fit, ffit, fffit, beforeEach, afterEach} = require('./async-spec-helpers')
const getNextUpdatePromise = () => etch.getScheduler().nextUpdatePromise
describe('WorkspaceElement', () => {
afterEach(() => {
try {
temp.cleanupSync()
} catch (e) {
// Do nothing
}
})
describe('when the workspace element is focused', () => {
it('transfers focus to the active pane', () => {
const workspaceElement = atom.workspace.getElement()
jasmine.attachToDOM(workspaceElement)
const activePaneElement = atom.workspace.getActivePane().getElement()
document.body.focus()
expect(document.activeElement).not.toBe(activePaneElement)
workspaceElement.focus()
expect(document.activeElement).toBe(activePaneElement)
})
})
describe('when the active pane of an inactive pane container is focused', () => {
it('changes the active pane container', () => {
const dock = atom.workspace.getLeftDock()
dock.show()
jasmine.attachToDOM(atom.workspace.getElement())
expect(atom.workspace.getActivePaneContainer()).toBe(atom.workspace.getCenter())
dock.getActivePane().getElement().focus()
expect(atom.workspace.getActivePaneContainer()).toBe(dock)
})
})
describe('finding the nearest visible pane in a specific direction', () => {
let pane1, pane2, pane3, pane4, pane5, pane6, pane7, pane8, pane9,
leftDockPane, rightDockPane, bottomDockPane, workspace, workspaceElement
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 workspace center with 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()
const leftDock = workspace.getLeftDock()
const rightDock = workspace.getRightDock()
const bottomDock = workspace.getBottomDock()
expect(leftDock.isVisible()).toBe(false)
expect(rightDock.isVisible()).toBe(false)
expect(bottomDock.isVisible()).toBe(false)
expect(leftDock.getPanes().length).toBe(1)
expect(rightDock.getPanes().length).toBe(1)
expect(bottomDock.getPanes().length).toBe(1)
leftDockPane = leftDock.getPanes()[0]
rightDockPane = rightDock.getPanes()[0]
bottomDockPane = bottomDock.getPanes()[0]
workspaceElement = atom.workspace.getElement()
workspaceElement.style.height = '400px'
workspaceElement.style.width = '400px'
jasmine.attachToDOM(workspaceElement)
})
describe('finding the nearest pane above', () => {
describe('when there are multiple rows above the pane', () => {
it('returns the pane in the adjacent row above', () => {
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('above', pane8)
expect(nearestPaneElement).toBe(pane5.getElement())
})
})
describe('when there are no rows above the pane', () => {
it('returns null', () => {
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('above', pane2)
expect(nearestPaneElement).toBeUndefined() // TODO Expect toBeNull()
})
})
describe('when the bottom dock contains the pane', () => {
it('returns the pane in the adjacent row above', () => {
workspace.getBottomDock().show()
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('above', bottomDockPane)
expect(nearestPaneElement).toBe(pane7.getElement())
})
})
})
describe('finding the nearest pane below', () => {
describe('when there are multiple rows below the pane', () => {
it('returns the pane in the adjacent row below', () => {
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('below', pane2)
expect(nearestPaneElement).toBe(pane5.getElement())
})
})
describe('when there are no rows below the pane', () => {
it('returns null', () => {
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('below', pane8)
expect(nearestPaneElement).toBeUndefined() // TODO Expect toBeNull()
})
})
describe('when the bottom dock is visible', () => {
describe("when the workspace center's bottommost row contains the pane", () => {
it("returns the pane in the bottom dock's adjacent row below", () => {
workspace.getBottomDock().show()
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('below', pane8)
expect(nearestPaneElement).toBe(bottomDockPane.getElement())
})
})
})
})
describe('finding the nearest pane to the left', () => {
describe('when there are multiple columns to the left of the pane', () => {
it('returns the pane in the adjacent column to the left', () => {
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('left', pane6)
expect(nearestPaneElement).toBe(pane5.getElement())
})
})
describe('when there are no columns to the left of the pane', () => {
it('returns null', () => {
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('left', pane4)
expect(nearestPaneElement).toBeUndefined() // TODO Expect toBeNull()
})
})
describe('when the right dock contains the pane', () => {
it('returns the pane in the adjacent column to the left', () => {
workspace.getRightDock().show()
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('left', rightDockPane)
expect(nearestPaneElement).toBe(pane3.getElement())
})
})
describe('when the left dock is visible', () => {
describe("when the workspace center's leftmost column contains the pane", () => {
it("returns the pane in the left dock's adjacent column to the left", () => {
workspace.getLeftDock().show()
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('left', pane4)
expect(nearestPaneElement).toBe(leftDockPane.getElement())
})
})
describe('when the bottom dock contains the pane', () => {
it("returns the pane in the left dock's adjacent column to the left", () => {
workspace.getLeftDock().show()
workspace.getBottomDock().show()
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('left', bottomDockPane)
expect(nearestPaneElement).toBe(leftDockPane.getElement())
})
})
})
})
describe('finding the nearest pane to the right', () => {
describe('when there are multiple columns to the right of the pane', () => {
it('returns the pane in the adjacent column to the right', () => {
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('right', pane4)
expect(nearestPaneElement).toBe(pane5.getElement())
})
})
describe('when there are no columns to the right of the pane', () => {
it('returns null', () => {
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('right', pane6)
expect(nearestPaneElement).toBeUndefined() // TODO Expect toBeNull()
})
})
describe('when the left dock contains the pane', () => {
it('returns the pane in the adjacent column to the right', () => {
workspace.getLeftDock().show()
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('right', leftDockPane)
expect(nearestPaneElement).toBe(pane1.getElement())
})
})
describe('when the right dock is visible', () => {
describe("when the workspace center's rightmost column contains the pane", () => {
it("returns the pane in the right dock's adjacent column to the right", () => {
workspace.getRightDock().show()
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('right', pane6)
expect(nearestPaneElement).toBe(rightDockPane.getElement())
})
})
describe('when the bottom dock contains the pane', () => {
it("returns the pane in the right dock's adjacent column to the right", () => {
workspace.getRightDock().show()
workspace.getBottomDock().show()
nearestPaneElement = workspaceElement.nearestVisiblePaneInDirection('right', bottomDockPane)
expect(nearestPaneElement).toBe(rightDockPane.getElement())
})
})
})
})
})
describe('changing focus, copying, and moving items directionally between panes', function () {
let workspace, workspaceElement, startingPane
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
expect(workspace.getLeftDock().isVisible()).toBe(false)
expect(workspace.getRightDock().isVisible()).toBe(false)
expect(workspace.getBottomDock().isVisible()).toBe(false)
const panes = workspace.getCenter().getPanes()
expect(panes.length).toEqual(1)
startingPane = panes[0]
workspaceElement = atom.workspace.getElement()
workspaceElement.style.height = '400px'
workspaceElement.style.width = '400px'
jasmine.attachToDOM(workspaceElement)
})
describe('::focusPaneViewAbove()', function () {
describe('when there is a row above the focused pane', () =>
it('focuses up to the adjacent row', function () {
const paneAbove = startingPane.splitUp()
startingPane.activate()
workspaceElement.focusPaneViewAbove()
expect(document.activeElement).toBe(paneAbove.getElement())
})
)
describe('when there are no rows above the focused pane', () =>
it('keeps the current pane focused', function () {
startingPane.activate()
workspaceElement.focusPaneViewAbove()
expect(document.activeElement).toBe(startingPane.getElement())
})
)
})
describe('::focusPaneViewBelow()', function () {
describe('when there is a row below the focused pane', () =>
it('focuses down to the adjacent row', function () {
const paneBelow = startingPane.splitDown()
startingPane.activate()
workspaceElement.focusPaneViewBelow()
expect(document.activeElement).toBe(paneBelow.getElement())
})
)
describe('when there are no rows below the focused pane', () =>
it('keeps the current pane focused', function () {
startingPane.activate()
workspaceElement.focusPaneViewBelow()
expect(document.activeElement).toBe(startingPane.getElement())
})
)
})
describe('::focusPaneViewOnLeft()', function () {
describe('when there is a column to the left of the focused pane', () =>
it('focuses left to the adjacent column', function () {
const paneOnLeft = startingPane.splitLeft()
startingPane.activate()
workspaceElement.focusPaneViewOnLeft()
expect(document.activeElement).toBe(paneOnLeft.getElement())
})
)
describe('when there are no columns to the left of the focused pane', () =>
it('keeps the current pane focused', function () {
startingPane.activate()
workspaceElement.focusPaneViewOnLeft()
expect(document.activeElement).toBe(startingPane.getElement())
})
)
})
describe('::focusPaneViewOnRight()', function () {
describe('when there is a column to the right of the focused pane', () =>
it('focuses right to the adjacent column', function () {
const paneOnRight = startingPane.splitRight()
startingPane.activate()
workspaceElement.focusPaneViewOnRight()
expect(document.activeElement).toBe(paneOnRight.getElement())
})
)
describe('when there are no columns to the right of the focused pane', () =>
it('keeps the current pane focused', function () {
startingPane.activate()
workspaceElement.focusPaneViewOnRight()
expect(document.activeElement).toBe(startingPane.getElement())
})
)
})
describe('::moveActiveItemToPaneAbove(keepOriginal)', function () {
describe('when there is a row above the focused pane', () =>
it('moves the active item up to the adjacent row', function () {
const item = document.createElement('div')
const paneAbove = startingPane.splitUp()
startingPane.activate()
startingPane.activateItem(item)
workspaceElement.moveActiveItemToPaneAbove()
expect(workspace.paneForItem(item)).toBe(paneAbove)
expect(paneAbove.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')
startingPane.activate()
startingPane.activateItem(item)
workspaceElement.moveActiveItemToPaneAbove()
expect(workspace.paneForItem(item)).toBe(startingPane)
})
)
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
const paneAbove = startingPane.splitUp()
startingPane.activate()
startingPane.activateItem(itemA)
workspaceElement.moveActiveItemToPaneAbove({keepOriginal: true})
expect(workspace.paneForItem(itemA)).toBe(startingPane)
expect(paneAbove.getActiveItem()).toBe(itemB)
})
)
})
describe('::moveActiveItemToPaneBelow(keepOriginal)', function () {
describe('when there is a row below the focused pane', () =>
it('moves the active item down to the adjacent row', function () {
const item = document.createElement('div')
const paneBelow = startingPane.splitDown()
startingPane.activate()
startingPane.activateItem(item)
workspaceElement.moveActiveItemToPaneBelow()
expect(workspace.paneForItem(item)).toBe(paneBelow)
expect(paneBelow.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')
startingPane.activate()
startingPane.activateItem(item)
workspaceElement.moveActiveItemToPaneBelow()
expect(workspace.paneForItem(item)).toBe(startingPane)
})
)
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
const paneBelow = startingPane.splitDown()
startingPane.activate()
startingPane.activateItem(itemA)
workspaceElement.moveActiveItemToPaneBelow({keepOriginal: true})
expect(workspace.paneForItem(itemA)).toBe(startingPane)
expect(paneBelow.getActiveItem()).toBe(itemB)
})
)
})
describe('::moveActiveItemToPaneOnLeft(keepOriginal)', function () {
describe('when there is a column to the left of the focused pane', () =>
it('moves the active item left to the adjacent column', function () {
const item = document.createElement('div')
const paneOnLeft = startingPane.splitLeft()
startingPane.activate()
startingPane.activateItem(item)
workspaceElement.moveActiveItemToPaneOnLeft()
expect(workspace.paneForItem(item)).toBe(paneOnLeft)
expect(paneOnLeft.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')
startingPane.activate()
startingPane.activateItem(item)
workspaceElement.moveActiveItemToPaneOnLeft()
expect(workspace.paneForItem(item)).toBe(startingPane)
})
)
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
const paneOnLeft = startingPane.splitLeft()
startingPane.activate()
startingPane.activateItem(itemA)
workspaceElement.moveActiveItemToPaneOnLeft({keepOriginal: true})
expect(workspace.paneForItem(itemA)).toBe(startingPane)
expect(paneOnLeft.getActiveItem()).toBe(itemB)
})
)
})
describe('::moveActiveItemToPaneOnRight(keepOriginal)', function () {
describe('when there is a column to the right of the focused pane', () =>
it('moves the active item right to the adjacent column', function () {
const item = document.createElement('div')
const paneOnRight = startingPane.splitRight()
startingPane.activate()
startingPane.activateItem(item)
workspaceElement.moveActiveItemToPaneOnRight()
expect(workspace.paneForItem(item)).toBe(paneOnRight)
expect(paneOnRight.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')
startingPane.activate()
startingPane.activateItem(item)
workspaceElement.moveActiveItemToPaneOnRight()
expect(workspace.paneForItem(item)).toBe(startingPane)
})
)
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
const paneOnRight = startingPane.splitRight()
startingPane.activate()
startingPane.activateItem(itemA)
workspaceElement.moveActiveItemToPaneOnRight({keepOriginal: true})
expect(workspace.paneForItem(itemA)).toBe(startingPane)
expect(paneOnRight.getActiveItem()).toBe(itemB)
})
)
})
describe('::moveActiveItemToNearestPaneInDirection(direction, params)', () => {
describe('when the item is not allowed in nearest pane in the given direction', () => {
it('does not move or copy the active item', function () {
const item = {
element: document.createElement('div'),
getAllowedLocations: () => ['left', 'right']
}
workspace.getBottomDock().show()
startingPane.activate()
startingPane.activateItem(item)
workspaceElement.moveActiveItemToNearestPaneInDirection('below', {keepOriginal: false})
expect(workspace.paneForItem(item)).toBe(startingPane)
workspaceElement.moveActiveItemToNearestPaneInDirection('below', {keepOriginal: true})
expect(workspace.paneForItem(item)).toBe(startingPane)
})
})
describe("when the item doesn't implement a `copy` function", () => {
it('does not copy the active item', function () {
const item = document.createElement('div')
const paneBelow = startingPane.splitDown()
expect(paneBelow.getItems().length).toEqual(0)
startingPane.activate()
startingPane.activateItem(item)
workspaceElement.focusPaneViewAbove()
workspaceElement.moveActiveItemToNearestPaneInDirection('below', {keepOriginal: true})
expect(workspace.paneForItem(item)).toBe(startingPane)
expect(paneBelow.getItems().length).toEqual(0)
})
})
})
})
describe('mousing over docks', () => {
let workspaceElement
beforeEach(() => {
workspaceElement = atom.workspace.getElement()
workspaceElement.style.width = '600px'
workspaceElement.style.height = '300px'
jasmine.attachToDOM(workspaceElement)
})
it('shows the toggle button when the dock is open', async () => {
await Promise.all([
atom.workspace.open({
element: document.createElement('div'),
getDefaultLocation() { return 'left' },
getPreferredWidth() { return 150 }
}),
atom.workspace.open({
element: document.createElement('div'),
getDefaultLocation() { return 'right' },
getPreferredWidth() { return 150 }
}),
atom.workspace.open({
element: document.createElement('div'),
getDefaultLocation() { return 'bottom' },
getPreferredHeight() { return 100 }
})
])
const leftDock = atom.workspace.getLeftDock()
const rightDock = atom.workspace.getRightDock()
const bottomDock = atom.workspace.getBottomDock()
expect(leftDock.isVisible()).toBe(true)
expect(rightDock.isVisible()).toBe(true)
expect(bottomDock.isVisible()).toBe(true)
expectToggleButtonHidden(leftDock)
expectToggleButtonHidden(rightDock)
expectToggleButtonHidden(bottomDock)
// --- Right Dock ---
// Mouse over where the toggle button would be if the dock were hovered
moveMouse({clientX: 440, clientY: 150})
await getNextUpdatePromise()
expectToggleButtonHidden(leftDock)
expectToggleButtonHidden(rightDock)
expectToggleButtonHidden(bottomDock)
// Mouse over the dock
moveMouse({clientX: 460, clientY: 150})
await getNextUpdatePromise()
expectToggleButtonHidden(leftDock)
expectToggleButtonVisible(rightDock, 'icon-chevron-right')
expectToggleButtonHidden(bottomDock)
// Mouse over the toggle button
moveMouse({clientX: 440, clientY: 150})
await getNextUpdatePromise()
expectToggleButtonHidden(leftDock)
expectToggleButtonVisible(rightDock, 'icon-chevron-right')
expectToggleButtonHidden(bottomDock)
// Click the toggle button
rightDock.refs.toggleButton.refs.innerElement.click()
await getNextUpdatePromise()
expect(rightDock.isVisible()).toBe(false)
expectToggleButtonHidden(rightDock)
// Mouse to edge of the window
moveMouse({clientX: 575, clientY: 150})
await getNextUpdatePromise()
expectToggleButtonHidden(rightDock)
moveMouse({clientX: 598, clientY: 150})
await getNextUpdatePromise()
expectToggleButtonVisible(rightDock, 'icon-chevron-left')
// Click the toggle button again
rightDock.refs.toggleButton.refs.innerElement.click()
await getNextUpdatePromise()
expect(rightDock.isVisible()).toBe(true)
expectToggleButtonVisible(rightDock, 'icon-chevron-right')
// --- Left Dock ---
// Mouse over where the toggle button would be if the dock were hovered
moveMouse({clientX: 160, clientY: 150})
await getNextUpdatePromise()
expectToggleButtonHidden(leftDock)
expectToggleButtonHidden(rightDock)
expectToggleButtonHidden(bottomDock)
// Mouse over the dock
moveMouse({clientX: 140, clientY: 150})
await getNextUpdatePromise()
expectToggleButtonVisible(leftDock, 'icon-chevron-left')
expectToggleButtonHidden(rightDock)
expectToggleButtonHidden(bottomDock)
// Mouse over the toggle button
moveMouse({clientX: 160, clientY: 150})
await getNextUpdatePromise()
expectToggleButtonVisible(leftDock, 'icon-chevron-left')
expectToggleButtonHidden(rightDock)
expectToggleButtonHidden(bottomDock)
// Click the toggle button
leftDock.refs.toggleButton.refs.innerElement.click()
await getNextUpdatePromise()
expect(leftDock.isVisible()).toBe(false)
expectToggleButtonHidden(leftDock)
// Mouse to edge of the window
moveMouse({clientX: 25, clientY: 150})
await getNextUpdatePromise()
expectToggleButtonHidden(leftDock)
moveMouse({clientX: 2, clientY: 150})
await getNextUpdatePromise()
expectToggleButtonVisible(leftDock, 'icon-chevron-right')
// Click the toggle button again
leftDock.refs.toggleButton.refs.innerElement.click()
await getNextUpdatePromise()
expect(leftDock.isVisible()).toBe(true)
expectToggleButtonVisible(leftDock, 'icon-chevron-left')
// --- Bottom Dock ---
// Mouse over where the toggle button would be if the dock were hovered
moveMouse({clientX: 300, clientY: 190})
await getNextUpdatePromise()
expectToggleButtonHidden(leftDock)
expectToggleButtonHidden(rightDock)
expectToggleButtonHidden(bottomDock)
// Mouse over the dock
moveMouse({clientX: 300, clientY: 210})
await getNextUpdatePromise()
expectToggleButtonHidden(leftDock)
expectToggleButtonHidden(rightDock)
expectToggleButtonVisible(bottomDock, 'icon-chevron-down')
// Mouse over the toggle button
moveMouse({clientX: 300, clientY: 195})
await getNextUpdatePromise()
expectToggleButtonHidden(leftDock)
expectToggleButtonHidden(rightDock)
expectToggleButtonVisible(bottomDock, 'icon-chevron-down')
// Click the toggle button
bottomDock.refs.toggleButton.refs.innerElement.click()
await getNextUpdatePromise()
expect(bottomDock.isVisible()).toBe(false)
expectToggleButtonHidden(bottomDock)
// Mouse to edge of the window
moveMouse({clientX: 300, clientY: 290})
await getNextUpdatePromise()
expectToggleButtonHidden(leftDock)
moveMouse({clientX: 300, clientY: 299})
await getNextUpdatePromise()
expectToggleButtonVisible(bottomDock, 'icon-chevron-up')
// Click the toggle button again
bottomDock.refs.toggleButton.refs.innerElement.click()
await getNextUpdatePromise()
expect(bottomDock.isVisible()).toBe(true)
expectToggleButtonVisible(bottomDock, 'icon-chevron-down')
})
function moveMouse (coordinates) {
window.dispatchEvent(new MouseEvent('mousemove', coordinates))
advanceClock(100)
}
function expectToggleButtonHidden(dock) {
expect(dock.refs.toggleButton.element).not.toHaveClass('atom-dock-toggle-button-visible')
}
function expectToggleButtonVisible(dock, iconClass) {
expect(dock.refs.toggleButton.element).toHaveClass('atom-dock-toggle-button-visible')
expect(dock.refs.toggleButton.refs.iconElement).toHaveClass(iconClass)
}
})
describe('the scrollbar visibility class', () => {
it('has a class based on the style of the scrollbar', () => {
let observeCallback
const scrollbarStyle = require('scrollbar-style')
spyOn(scrollbarStyle, 'observePreferredScrollbarStyle').andCallFake(cb => {
observeCallback = cb
return new Disposable(() => {})
})
const workspaceElement = atom.workspace.getElement()
observeCallback('legacy')
expect(workspaceElement.className).toMatch('scrollbars-visible-always')
observeCallback('overlay')
expect(workspaceElement).toHaveClass('scrollbars-visible-when-scrolling')
})
})
describe('editor font styling', () => {
let editor, editorElement, workspaceElement
beforeEach(async () => {
await atom.workspace.open('sample.js')
workspaceElement = atom.workspace.getElement()
jasmine.attachToDOM(workspaceElement)
editor = atom.workspace.getActiveTextEditor()
editorElement = editor.getElement()
})
it("updates the font-size based on the 'editor.fontSize' config value", async () => {
const initialCharWidth = editor.getDefaultCharWidth()
expect(getComputedStyle(editorElement).fontSize).toBe(atom.config.get('editor.fontSize') + 'px')
atom.config.set('editor.fontSize', atom.config.get('editor.fontSize') + 5)
await editorElement.component.getNextUpdatePromise()
expect(getComputedStyle(editorElement).fontSize).toBe(atom.config.get('editor.fontSize') + 'px')
expect(editor.getDefaultCharWidth()).toBeGreaterThan(initialCharWidth)
})
it("updates the font-family based on the 'editor.fontFamily' config value", async () => {
const initialCharWidth = editor.getDefaultCharWidth()
let fontFamily = atom.config.get('editor.fontFamily')
expect(getComputedStyle(editorElement).fontFamily).toBe(fontFamily)
atom.config.set('editor.fontFamily', 'sans-serif')
fontFamily = atom.config.get('editor.fontFamily')
await editorElement.component.getNextUpdatePromise()
expect(getComputedStyle(editorElement).fontFamily).toBe(fontFamily)
expect(editor.getDefaultCharWidth()).not.toBe(initialCharWidth)
})
it("updates the line-height based on the 'editor.lineHeight' config value", async () => {
const initialLineHeight = editor.getLineHeightInPixels()
atom.config.set('editor.lineHeight', '30px')
await editorElement.component.getNextUpdatePromise()
expect(getComputedStyle(editorElement).lineHeight).toBe(atom.config.get('editor.lineHeight'))
expect(editor.getLineHeightInPixels()).not.toBe(initialLineHeight)
})
it('increases or decreases the font size when a ctrl-mousewheel event occurs', () => {
atom.config.set('editor.zoomFontWhenCtrlScrolling', true)
atom.config.set('editor.fontSize', 12)
// Zoom out
editorElement.querySelector('span').dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaY: -10,
ctrlKey: true
}))
expect(atom.config.get('editor.fontSize')).toBe(11)
// Zoom in
editorElement.querySelector('span').dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaY: 10,
ctrlKey: true
}))
expect(atom.config.get('editor.fontSize')).toBe(12)
// Not on an atom-text-editor
workspaceElement.dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaY: 10,
ctrlKey: true
}))
expect(atom.config.get('editor.fontSize')).toBe(12)
// No ctrl key
editorElement.querySelector('span').dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaY: 10
}))
expect(atom.config.get('editor.fontSize')).toBe(12)
atom.config.set('editor.zoomFontWhenCtrlScrolling', false)
editorElement.querySelector('span').dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaY: 10,
ctrlKey: true
}))
expect(atom.config.get('editor.fontSize')).toBe(12)
})
})
describe('panel containers', () => {
it('inserts panel container elements in the correct places in the DOM', () => {
const workspaceElement = atom.workspace.getElement()
const leftContainer = workspaceElement.querySelector('atom-panel-container.left')
const rightContainer = workspaceElement.querySelector('atom-panel-container.right')
expect(leftContainer.nextSibling).toBe(workspaceElement.verticalAxis)
expect(rightContainer.previousSibling).toBe(workspaceElement.verticalAxis)
const topContainer = workspaceElement.querySelector('atom-panel-container.top')
const bottomContainer = workspaceElement.querySelector('atom-panel-container.bottom')
expect(topContainer.nextSibling).toBe(workspaceElement.paneContainer)
expect(bottomContainer.previousSibling).toBe(workspaceElement.paneContainer)
const headerContainer = workspaceElement.querySelector('atom-panel-container.header')
const footerContainer = workspaceElement.querySelector('atom-panel-container.footer')
expect(headerContainer.nextSibling).toBe(workspaceElement.horizontalAxis)
expect(footerContainer.previousSibling).toBe(workspaceElement.horizontalAxis)
const modalContainer = workspaceElement.querySelector('atom-panel-container.modal')
expect(modalContainer.parentNode).toBe(workspaceElement)
})
it('stretches header/footer panels to the workspace width', () => {
const workspaceElement = atom.workspace.getElement()
jasmine.attachToDOM(workspaceElement)
expect(workspaceElement.offsetWidth).toBeGreaterThan(0)
const headerItem = document.createElement('div')
atom.workspace.addHeaderPanel({item: headerItem})
expect(headerItem.offsetWidth).toEqual(workspaceElement.offsetWidth)
const footerItem = document.createElement('div')
atom.workspace.addFooterPanel({item: footerItem})
expect(footerItem.offsetWidth).toEqual(workspaceElement.offsetWidth)
})
it('shrinks horizontal axis according to header/footer panels height', () => {
const workspaceElement = atom.workspace.getElement()
workspaceElement.style.height = '100px'
const horizontalAxisElement = workspaceElement.querySelector('atom-workspace-axis.horizontal')
jasmine.attachToDOM(workspaceElement)
const originalHorizontalAxisHeight = horizontalAxisElement.offsetHeight
expect(workspaceElement.offsetHeight).toBeGreaterThan(0)
expect(originalHorizontalAxisHeight).toBeGreaterThan(0)
const headerItem = document.createElement('div')
headerItem.style.height = '10px'
atom.workspace.addHeaderPanel({item: headerItem})
expect(headerItem.offsetHeight).toBeGreaterThan(0)
const footerItem = document.createElement('div')
footerItem.style.height = '15px'
atom.workspace.addFooterPanel({item: footerItem})
expect(footerItem.offsetHeight).toBeGreaterThan(0)
expect(horizontalAxisElement.offsetHeight).toEqual(originalHorizontalAxisHeight - headerItem.offsetHeight - footerItem.offsetHeight)
})
})
describe("the 'window:toggle-invisibles' command", () => {
it('shows/hides invisibles in all open and future editors', () => {
const workspaceElement = atom.workspace.getElement()
expect(atom.config.get('editor.showInvisibles')).toBe(false)
atom.commands.dispatch(workspaceElement, 'window:toggle-invisibles')
expect(atom.config.get('editor.showInvisibles')).toBe(true)
atom.commands.dispatch(workspaceElement, 'window:toggle-invisibles')
expect(atom.config.get('editor.showInvisibles')).toBe(false)
})
})
describe("the 'window:run-package-specs' command", () => {
it("runs the package specs for the active item's project path, or the first project path", () => {
const workspaceElement = atom.workspace.getElement()
spyOn(ipcRenderer, 'send')
// No project paths. Don't try to run specs.
atom.commands.dispatch(workspaceElement, 'window:run-package-specs')
expect(ipcRenderer.send).not.toHaveBeenCalledWith('run-package-specs')
const projectPaths = [temp.mkdirSync('dir1-'), temp.mkdirSync('dir2-')]
atom.project.setPaths(projectPaths)
// No active item. Use first project directory.
atom.commands.dispatch(workspaceElement, 'window:run-package-specs')
expect(ipcRenderer.send).toHaveBeenCalledWith('run-package-specs', path.join(projectPaths[0], 'spec'), {})
ipcRenderer.send.reset()
// Active item doesn't implement ::getPath(). Use first project directory.
const item = document.createElement('div')
atom.workspace.getActivePane().activateItem(item)
atom.commands.dispatch(workspaceElement, 'window:run-package-specs')
expect(ipcRenderer.send).toHaveBeenCalledWith('run-package-specs', path.join(projectPaths[0], 'spec'), {})
ipcRenderer.send.reset()
// Active item has no path. Use first project directory.
item.getPath = () => null
atom.commands.dispatch(workspaceElement, 'window:run-package-specs')
expect(ipcRenderer.send).toHaveBeenCalledWith('run-package-specs', path.join(projectPaths[0], 'spec'), {})
ipcRenderer.send.reset()
// Active item has path. Use project path for item path.
item.getPath = () => path.join(projectPaths[1], 'a-file.txt')
atom.commands.dispatch(workspaceElement, 'window:run-package-specs')
expect(ipcRenderer.send).toHaveBeenCalledWith('run-package-specs', path.join(projectPaths[1], 'spec'), {})
ipcRenderer.send.reset()
})
it("passes additional options to the spec window", () => {
const workspaceElement = atom.workspace.getElement()
spyOn(ipcRenderer, 'send')
const projectPath = temp.mkdirSync('dir1-')
atom.project.setPaths([projectPath])
workspaceElement.runPackageSpecs({env: {ATOM_GITHUB_BABEL_ENV: 'coverage'}})
expect(ipcRenderer.send).toHaveBeenCalledWith(
'run-package-specs', path.join(projectPath, 'spec'), {env: {ATOM_GITHUB_BABEL_ENV: 'coverage'}})
})
})
})