Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Editor and Table unit test #15646

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/app/components/editor/editor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { TestBed, ComponentFixture, waitForAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Editor } from './editor';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
Expand All @@ -7,15 +7,15 @@ describe('Editor', () => {
let editor: Editor;
let fixture: ComponentFixture<Editor>;

beforeEach(() => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [NoopAnimationsModule],
declarations: [Editor]
});

fixture = TestBed.createComponent(Editor);
editor = fixture.componentInstance;
});
}));

it('should display by default', () => {
fixture.detectChanges();
Expand All @@ -25,9 +25,7 @@ describe('Editor', () => {
});

it('should show value', () => {
editor.value = 'V';
fixture.detectChanges();

editor.writeValue('V');
fixture.detectChanges();

const paragraphEl = fixture.debugElement.query(By.css('.p-editor-content')).nativeElement.children[0].children[0];
Expand Down
16 changes: 8 additions & 8 deletions src/app/components/table/table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,9 +1238,9 @@ describe('Table', () => {
fixture.detectChanges();

expect(onColumnResizeEndSpy).toHaveBeenCalled();
expect(resizerEls[0].parentElement.clientWidth).toEqual(firstWidth - 30);
expect(resizerEls[0].parentElement.clientWidth).not.toEqual(firstWidth);
expect(defaultWidth).toEqual(resizerEls[0].parentElement.parentElement.clientWidth);
expect(resizerEls[0]?.parentElement?.clientWidth).toEqual(firstWidth - 30);
expect(resizerEls[0]?.parentElement?.clientWidth).not.toEqual(firstWidth);
expect(defaultWidth).toEqual(resizerEls[0]!.parentElement!.parentElement!.clientWidth);
});

it('should call resize and resizeColGroup with scrollableTable (fit)', () => {
Expand All @@ -1249,13 +1249,13 @@ describe('Table', () => {
fixture.detectChanges();

let resizerEls = document.getElementsByClassName('p-column-resizer');
let defaultWidth = resizerEls[0].parentElement.parentElement.clientWidth;
let defaultWidth = resizerEls[0]?.parentElement?.parentElement?.clientWidth;
const onColumnResizeBeginSpy = spyOn(colResizeTable, 'onColumnResizeBegin').and.callThrough();
const event: any = document.createEvent('CustomEvent');
event.pageX = 450;
event.which = 1;
event.initEvent('mousedown');
let firstWidth = resizerEls[0].parentElement.clientWidth;
let firstWidth = resizerEls[0]?.parentElement?.clientWidth;
resizerEls[0].dispatchEvent(event as MouseEvent);
fixture.detectChanges();

Expand Down Expand Up @@ -1443,7 +1443,7 @@ describe('Table', () => {
it('should open contextMenu and select row', () => {
fixture.detectChanges();

const contextMenu = fixture.debugElement.query(By.css('.p-contextmenu')).componentInstance as ContextMenu;
const contextMenu = fixture.debugElement.query(By.directive(ContextMenu)).componentInstance;
const showSpy = spyOn(contextMenu, 'show').and.callThrough();
const contextMenuTableEl = fixture.debugElement.query(By.css('.contextMenuTable'));
const rowEls = contextMenuTableEl.queryAll(By.css('tr'));
Expand All @@ -1465,7 +1465,7 @@ describe('Table', () => {
contextMenuTable.contextMenuSelectionMode = 'joint';
fixture.detectChanges();

const contextMenu = fixture.debugElement.query(By.css('.p-contextmenu')).componentInstance as ContextMenu;
const contextMenu = fixture.debugElement.query(By.directive(ContextMenu)).componentInstance;
const showSpy = spyOn(contextMenu, 'show').and.callThrough();
const contextMenuTableEl = fixture.debugElement.query(By.css('.contextMenuTable'));
const rowEls = contextMenuTableEl.queryAll(By.css('tr'));
Expand All @@ -1487,7 +1487,7 @@ describe('Table', () => {
contextMenuTable.contextMenuSelectionMode = 'joint';
fixture.detectChanges();

const contextMenu = fixture.debugElement.query(By.css('.p-contextmenu')).componentInstance as ContextMenu;
const contextMenu = fixture.debugElement.query(By.directive(ContextMenu)).componentInstance;
const showSpy = spyOn(contextMenu, 'show').and.callThrough();
const contextMenuTableEl = fixture.debugElement.query(By.css('.contextMenuTable'));
const rowEls = contextMenuTableEl.queryAll(By.css('tr'));
Expand Down
Loading