|
1 | 1 | import { IgxSplitterModule } from './splitter.module'; |
2 | 2 | import { configureTestSuite } from '../test-utils/configure-suite'; |
3 | 3 | import { TestBed, async } from '@angular/core/testing'; |
4 | | -import { Component, ViewChild } from '@angular/core'; |
| 4 | +import { Component, ViewChild, DebugElement } from '@angular/core'; |
5 | 5 | import { SplitterType, IgxSplitterComponent } from './splitter.component'; |
6 | 6 | import { By } from '@angular/platform-browser'; |
| 7 | +import { UIInteractions } from '../test-utils/ui-interactions.spec'; |
7 | 8 |
|
8 | 9 |
|
9 | 10 | const SPLITTERBAR_CLASS = 'igx-splitter-bar'; |
@@ -131,6 +132,111 @@ describe('IgxSplitter', () => { |
131 | 132 | splitterBarComponent.onDragStart(args); |
132 | 133 | expect(args.cancel).toBeTruthy(); |
133 | 134 | }); |
| 135 | + |
| 136 | + it('should allow resizing with up/down arrow keys', () => { |
| 137 | + fixture.componentInstance.type = SplitterType.Vertical; |
| 138 | + fixture.detectChanges(); |
| 139 | + const pane1 = splitter.panes.toArray()[0]; |
| 140 | + const pane2 = splitter.panes.toArray()[1]; |
| 141 | + expect(pane1.size).toBe('auto'); |
| 142 | + expect(pane2.size).toBe('auto'); |
| 143 | + const pane1_originalSize = pane1.element.offsetHeight; |
| 144 | + const pane2_originalSize = pane2.element.offsetHeight; |
| 145 | + const splitterBarComponent: DebugElement = fixture.debugElement.query(By.css(SPLITTERBAR_CLASS)); |
| 146 | + splitterBarComponent.nativeElement.focus(); |
| 147 | + UIInteractions.triggerEventHandlerKeyDown('ArrowUp', splitterBarComponent); |
| 148 | + fixture.detectChanges(); |
| 149 | + expect(pane1.size).toBe(pane1_originalSize - 10 + 'px'); |
| 150 | + expect(pane2.size).toBe(pane2_originalSize + 10 + 'px'); |
| 151 | + |
| 152 | + UIInteractions.triggerEventHandlerKeyDown('ArrowDown', splitterBarComponent); |
| 153 | + UIInteractions.triggerEventHandlerKeyDown('ArrowDown', splitterBarComponent); |
| 154 | + fixture.detectChanges(); |
| 155 | + expect(pane1.size).toBe(pane1_originalSize + 10 + 'px'); |
| 156 | + expect(pane2.size).toBe(pane2_originalSize - 10 + 'px'); |
| 157 | + |
| 158 | + pane2.resizable = false; |
| 159 | + UIInteractions.triggerEventHandlerKeyDown('ArrowDown', splitterBarComponent); |
| 160 | + fixture.detectChanges(); |
| 161 | + expect(pane1.size).toBe(pane1_originalSize + 10 + 'px'); |
| 162 | + expect(pane2.size).toBe(pane2_originalSize - 10 + 'px'); |
| 163 | + }); |
| 164 | + |
| 165 | + it('should allow resizing with left/right arrow keys', () => { |
| 166 | + fixture.componentInstance.type = SplitterType.Horizontal; |
| 167 | + fixture.detectChanges(); |
| 168 | + const pane1 = splitter.panes.toArray()[0]; |
| 169 | + const pane2 = splitter.panes.toArray()[1]; |
| 170 | + expect(pane1.size).toBe('auto'); |
| 171 | + expect(pane2.size).toBe('auto'); |
| 172 | + const pane1_originalSize = pane1.element.offsetWidth; |
| 173 | + const pane2_originalSize = pane2.element.offsetWidth; |
| 174 | + const splitterBarComponent: DebugElement = fixture.debugElement.query(By.css(SPLITTERBAR_CLASS)); |
| 175 | + splitterBarComponent.nativeElement.focus(); |
| 176 | + UIInteractions.triggerEventHandlerKeyDown('ArrowLeft', splitterBarComponent); |
| 177 | + fixture.detectChanges(); |
| 178 | + expect(parseFloat(pane1.size)).toBeCloseTo(pane1_originalSize - 10, 0); |
| 179 | + expect(parseFloat(pane2.size)).toBeCloseTo(pane2_originalSize + 10, 0); |
| 180 | + |
| 181 | + UIInteractions.triggerEventHandlerKeyDown('ArrowRight', splitterBarComponent); |
| 182 | + UIInteractions.triggerEventHandlerKeyDown('ArrowRight', splitterBarComponent); |
| 183 | + fixture.detectChanges(); |
| 184 | + expect(parseFloat(pane1.size)).toBeCloseTo(pane1_originalSize + 10, 0); |
| 185 | + expect(parseFloat(pane2.size)).toBeCloseTo(pane2_originalSize - 10, 0); |
| 186 | + |
| 187 | + pane1.resizable = false; |
| 188 | + UIInteractions.triggerEventHandlerKeyDown('ArrowRight', splitterBarComponent); |
| 189 | + fixture.detectChanges(); |
| 190 | + expect(parseFloat(pane1.size)).toBeCloseTo(pane1_originalSize + 10, 0); |
| 191 | + expect(parseFloat(pane2.size)).toBeCloseTo(pane2_originalSize - 10, 0); |
| 192 | + }); |
| 193 | + |
| 194 | + it('should allow expand/collapse with Ctrl + up/down arrow keys', () => { |
| 195 | + fixture.componentInstance.type = SplitterType.Vertical; |
| 196 | + fixture.detectChanges(); |
| 197 | + const pane1 = splitter.panes.toArray()[0]; |
| 198 | + const pane2 = splitter.panes.toArray()[1]; |
| 199 | + expect(pane1.size).toBe('auto'); |
| 200 | + expect(pane2.size).toBe('auto'); |
| 201 | + const splitterBarComponent: DebugElement = fixture.debugElement.query(By.css(SPLITTERBAR_CLASS)); |
| 202 | + splitterBarComponent.nativeElement.focus(); |
| 203 | + UIInteractions.triggerEventHandlerKeyDown('ArrowUp', splitterBarComponent, false, false, true); |
| 204 | + fixture.detectChanges(); |
| 205 | + expect(pane1.hidden).toBeTruthy(); |
| 206 | + UIInteractions.triggerEventHandlerKeyDown('ArrowDown', splitterBarComponent, false, false, true); |
| 207 | + fixture.detectChanges(); |
| 208 | + expect(pane1.hidden).toBeFalsy(); |
| 209 | + UIInteractions.triggerEventHandlerKeyDown('ArrowDown', splitterBarComponent, false, false, true); |
| 210 | + fixture.detectChanges(); |
| 211 | + expect(pane2.hidden).toBeTruthy(); |
| 212 | + UIInteractions.triggerEventHandlerKeyDown('ArrowUp', splitterBarComponent, false, false, true); |
| 213 | + fixture.detectChanges(); |
| 214 | + expect(pane2.hidden).toBeFalsy(); |
| 215 | + }); |
| 216 | + |
| 217 | + it('should allow expand/collapse with Ctrl + left/right arrow keys', () => { |
| 218 | + fixture.componentInstance.type = SplitterType.Horizontal; |
| 219 | + fixture.detectChanges(); |
| 220 | + const pane1 = splitter.panes.toArray()[0]; |
| 221 | + const pane2 = splitter.panes.toArray()[1]; |
| 222 | + expect(pane1.size).toBe('auto'); |
| 223 | + expect(pane2.size).toBe('auto'); |
| 224 | + const splitterBarComponent: DebugElement = fixture.debugElement.query(By.css(SPLITTERBAR_CLASS)); |
| 225 | + splitterBarComponent.nativeElement.focus(); |
| 226 | + UIInteractions.triggerEventHandlerKeyDown('ArrowLeft', splitterBarComponent, false, false, true); |
| 227 | + fixture.detectChanges(); |
| 228 | + expect(pane1.hidden).toBeTruthy(); |
| 229 | + UIInteractions.triggerEventHandlerKeyDown('ArrowRight', splitterBarComponent, false, false, true); |
| 230 | + fixture.detectChanges(); |
| 231 | + expect(pane1.hidden).toBeFalsy(); |
| 232 | + UIInteractions.triggerEventHandlerKeyDown('ArrowRight', splitterBarComponent, false, false, true); |
| 233 | + fixture.detectChanges(); |
| 234 | + expect(pane2.hidden).toBeTruthy(); |
| 235 | + UIInteractions.triggerEventHandlerKeyDown('ArrowLeft', splitterBarComponent, false, false, true); |
| 236 | + fixture.detectChanges(); |
| 237 | + expect(pane2.hidden).toBeFalsy(); |
| 238 | + }); |
| 239 | + |
134 | 240 | }); |
135 | 241 |
|
136 | 242 | describe('IgxSplitter pane toggle', () => { |
|
0 commit comments