|
4 | 4 | dispatchEvent,
|
5 | 5 | dispatchFakeEvent,
|
6 | 6 | dispatchKeyboardEvent,
|
| 7 | + dispatchMouseEvent, |
7 | 8 | provideFakeDirectionality,
|
8 | 9 | } from '@angular/cdk/testing/private';
|
9 | 10 | import {Component, DebugElement, ElementRef, ViewChild} from '@angular/core';
|
@@ -234,6 +235,90 @@ describe('Row Chips', () => {
|
234 | 235 | fixture.detectChanges();
|
235 | 236 | expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeTruthy();
|
236 | 237 | });
|
| 238 | + |
| 239 | + it('should not begin editing on single click', () => { |
| 240 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeFalsy(); |
| 241 | + dispatchMouseEvent(chipNativeElement, 'click'); |
| 242 | + fixture.detectChanges(); |
| 243 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeFalsy(); |
| 244 | + }); |
| 245 | + |
| 246 | + it('should begin editing on single click when focused', fakeAsync(() => { |
| 247 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeFalsy(); |
| 248 | + chipNativeElement.focus(); |
| 249 | + |
| 250 | + // Need to also simulate the mousedown as that sets the already focused flag. |
| 251 | + dispatchMouseEvent(chipNativeElement, 'mousedown'); |
| 252 | + dispatchMouseEvent(chipNativeElement, 'click'); |
| 253 | + fixture.detectChanges(); |
| 254 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeTruthy(); |
| 255 | + })); |
| 256 | + |
| 257 | + describe('when disabled', () => { |
| 258 | + beforeEach(() => { |
| 259 | + testComponent.disabled = true; |
| 260 | + fixture.changeDetectorRef.markForCheck(); |
| 261 | + fixture.detectChanges(); |
| 262 | + }); |
| 263 | + |
| 264 | + it('should not begin editing on double click', () => { |
| 265 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeFalsy(); |
| 266 | + dispatchFakeEvent(chipNativeElement, 'dblclick'); |
| 267 | + fixture.detectChanges(); |
| 268 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeFalsy(); |
| 269 | + }); |
| 270 | + |
| 271 | + it('should not begin editing on ENTER', () => { |
| 272 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeFalsy(); |
| 273 | + dispatchKeyboardEvent(chipNativeElement, 'keydown', ENTER); |
| 274 | + fixture.detectChanges(); |
| 275 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeFalsy(); |
| 276 | + }); |
| 277 | + |
| 278 | + it('should not begin editing on single click when focused', fakeAsync(() => { |
| 279 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeFalsy(); |
| 280 | + chipNativeElement.focus(); |
| 281 | + |
| 282 | + // Need to also simulate the mousedown as that sets the already focused flag. |
| 283 | + dispatchMouseEvent(chipNativeElement, 'mousedown'); |
| 284 | + dispatchMouseEvent(chipNativeElement, 'click'); |
| 285 | + fixture.detectChanges(); |
| 286 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeFalsy(); |
| 287 | + })); |
| 288 | + }); |
| 289 | + |
| 290 | + describe('when not editable', () => { |
| 291 | + beforeEach(() => { |
| 292 | + testComponent.editable = false; |
| 293 | + fixture.changeDetectorRef.markForCheck(); |
| 294 | + fixture.detectChanges(); |
| 295 | + }); |
| 296 | + |
| 297 | + it('should not begin editing on double click', () => { |
| 298 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeFalsy(); |
| 299 | + dispatchFakeEvent(chipNativeElement, 'dblclick'); |
| 300 | + fixture.detectChanges(); |
| 301 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeFalsy(); |
| 302 | + }); |
| 303 | + |
| 304 | + it('should not begin editing on ENTER', () => { |
| 305 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeFalsy(); |
| 306 | + dispatchKeyboardEvent(chipNativeElement, 'keydown', ENTER); |
| 307 | + fixture.detectChanges(); |
| 308 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeFalsy(); |
| 309 | + }); |
| 310 | + |
| 311 | + it('should not begin editing on single click when focused', fakeAsync(() => { |
| 312 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeFalsy(); |
| 313 | + chipNativeElement.focus(); |
| 314 | + |
| 315 | + // Need to also simulate the mousedown as that sets the already focused flag. |
| 316 | + dispatchMouseEvent(chipNativeElement, 'mousedown'); |
| 317 | + dispatchMouseEvent(chipNativeElement, 'click'); |
| 318 | + fixture.detectChanges(); |
| 319 | + expect(chipNativeElement.querySelector('.mat-chip-edit-input')).toBeFalsy(); |
| 320 | + })); |
| 321 | + }); |
237 | 322 | });
|
238 | 323 |
|
239 | 324 | describe('editing behavior', () => {
|
|
0 commit comments