Skip to content

Commit

Permalink
refactor deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
dobanisola-scottlogic committed May 20, 2024
1 parent e5c6c18 commit d76e115
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
16 changes: 8 additions & 8 deletions src/app/components/treetable/treetable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ fdescribe('TreeTable', () => {

const basicTreeTableEl = fixture.debugElement.query(By.css('.basicTreeTable'));
let rowEls = basicTreeTableEl.queryAll(By.css('tr'));
rowEls[2].nativeElement.dispatchEvent(new KeyboardEvent('keydown', {code:'ArrowDown'}));
rowEls[2].nativeElement.dispatchEvent(new KeyboardEvent('keydown', { code: 'ArrowDown' }));

fixture.detectChanges();
rowEls = basicTreeTableEl.queryAll(By.css('tr'));
Expand All @@ -738,7 +738,7 @@ fdescribe('TreeTable', () => {

const basicTreeTableEl = fixture.debugElement.query(By.css('.basicTreeTable'));
let rowEls = basicTreeTableEl.queryAll(By.css('tr'));
rowEls[3].nativeElement.dispatchEvent(new KeyboardEvent('keydown', {code:'ArrowUp'}));
rowEls[3].nativeElement.dispatchEvent(new KeyboardEvent('keydown', { code: 'ArrowUp' }));

fixture.detectChanges();
rowEls = basicTreeTableEl.queryAll(By.css('tr'));
Expand Down Expand Up @@ -1103,32 +1103,32 @@ fdescribe('TreeTable', () => {
fixture.detectChanges();

editableColumns = editableTreeTableEl.queryAll(By.css('td'));
editableColumns[1].triggerEventHandler('keydown', { target: editableColumns[1].nativeElement, keyCode: 9, preventDefault() {} });
editableColumns[1].triggerEventHandler('keydown', { target: editableColumns[1].nativeElement, code: 'Tab', preventDefault() {} });
fixture.detectChanges();

editableColumns = editableTreeTableEl.queryAll(By.css('td'));
expect(editableColumns[1].nativeElement.className).not.toContain('p-cell-editing');
expect(editableColumns[2].nativeElement.className).toContain('p-cell-editing');
editableColumns[2].triggerEventHandler('keydown', { target: editableColumns[2].nativeElement, keyCode: 9, preventDefault() {} });
editableColumns[2].triggerEventHandler('keydown', { target: editableColumns[2].nativeElement, code: 'Tab', preventDefault() {} });
fixture.detectChanges();

editableColumns = editableTreeTableEl.queryAll(By.css('td'));
expect(editableColumns[2].nativeElement.className).not.toContain('p-cell-editing');
expect(editableColumns[3].nativeElement.className).toContain('p-cell-editing');

editableColumns = editableTreeTableEl.queryAll(By.css('td'));
editableColumns[3].triggerEventHandler('keydown', { target: editableColumns[3].nativeElement, shiftKey: true, keyCode: 9, code: 'Tab', preventDefault() {} });
editableColumns[3].triggerEventHandler('keydown', { target: editableColumns[3].nativeElement, shiftKey: true, code: 'Tab', preventDefault() {} });
fixture.detectChanges();

expect(editableColumns[3].nativeElement.className).not.toContain('p-cell-editing');
expect(editableColumns[2].nativeElement.className).toContain('p-cell-editing');
editableColumns = editableTreeTableEl.queryAll(By.css('td'));
editableColumns[2].triggerEventHandler('keydown', { target: editableColumns[2].nativeElement, shiftKey: true, keyCode: 9, code: 'Tab', preventDefault() {} });
editableColumns[2].triggerEventHandler('keydown', { target: editableColumns[2].nativeElement, shiftKey: true, code: 'Tab', preventDefault() {} });
fixture.detectChanges();

expect(editableColumns[1].nativeElement.className).toContain('p-cell-editing');
editableColumns = editableTreeTableEl.queryAll(By.css('td'));
editableColumns[1].triggerEventHandler('keydown', { target: editableColumns[1].nativeElement, shiftKey: true, keyCode: 27, code: 'Escape', preventDefault() {} });
editableColumns[1].triggerEventHandler('keydown', { target: editableColumns[1].nativeElement, shiftKey: true, code: 'Escape', preventDefault() {} });
fixture.detectChanges();

expect(editableColumns[1].nativeElement.className).not.toContain('p-cell-editing');
Expand All @@ -1138,7 +1138,7 @@ fdescribe('TreeTable', () => {

expect(editableColumns[1].nativeElement.className).toContain('p-cell-editing');
editableColumns = editableTreeTableEl.queryAll(By.css('td'));
editableColumns[1].triggerEventHandler('keydown', { target: editableColumns[1].nativeElement, shiftKey: false, keyCode: 13, code: 'Enter', preventDefault() {} });
editableColumns[1].triggerEventHandler('keydown', { target: editableColumns[1].nativeElement, shiftKey: false, code: 'Enter', preventDefault() {} });
fixture.detectChanges();

expect(editableColumns[1].nativeElement.className).not.toContain('p-cell-editing');
Expand Down
13 changes: 3 additions & 10 deletions src/app/components/treetable/treetable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3326,30 +3326,23 @@ export class TTEditableColumn implements AfterViewInit {
@HostListener('keydown', ['$event'])
onKeyDown(event: KeyboardEvent) {
if (this.isEnabled()) {
//enter
if (event.keyCode == 13 && !event.shiftKey) {
if (event.code == 'Enter' && !event.shiftKey) {
if (this.tt.isEditingCellValid()) {
DomHandler.removeClass(this.tt.editingCell, 'p-cell-editing');
this.closeEditingCell();
this.tt.onEditComplete.emit({ field: this.field, data: this.data });
}

event.preventDefault();
}

//escape
else if (event.keyCode == 27) {
} else if (event.code == 'Escape') {
if (this.tt.isEditingCellValid()) {
DomHandler.removeClass(this.tt.editingCell, 'p-cell-editing');
this.closeEditingCell();
this.tt.onEditCancel.emit({ field: this.field, data: this.data });
}

event.preventDefault();
}

//tab
else if (event.keyCode == 9) {
} else if (event.code == 'Tab') {
this.tt.onEditComplete.emit({ field: this.field, data: this.data });

if (event.shiftKey) this.moveToPreviousCell(event);
Expand Down

0 comments on commit d76e115

Please sign in to comment.