Skip to content

Commit

Permalink
fix(ng): post merge tests issues
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeNury committed Dec 16, 2024
1 parent 6825ffd commit a12a80e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
9 changes: 6 additions & 3 deletions packages/ng/core-select/input/select-input.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,40 @@ export function runALuSelectInputComponentTestSuite<TValue>(config: LuSelectInpu
nativeElement = fixture.nativeElement as HTMLElement;
});

it('should openPanel when ArrowDown', () => {
it('should openPanel when ArrowDown', async () => {
// Arrange
const event = new KeyboardEvent('keydown', { key: 'ArrowDown' });

// Act
nativeElement.dispatchEvent(event);
await fixture.whenStable();

// Assert
expect(component.isPanelOpen).toBe(true);
});

it.each(['a', 'A', 'À'])('should openPanel and emit clueChange when pressing %s', (key) => {
it.each(['a', 'A', 'À'])('should openPanel and emit clueChange when pressing %s', async (key) => {
// Arrange
const event = new KeyboardEvent('keydown', { key });
const clueChangeSpy = jest.spyOn(component.clueChange, 'emit');

// Act
nativeElement.dispatchEvent(event);
await fixture.whenStable();

// Assert
expect(component.isPanelOpen).toBe(true);
expect(clueChangeSpy).toHaveBeenCalledWith(key);
});

it('should openPanel and but not emit clueChange when pressing Space', () => {
it('should openPanel and but not emit clueChange when pressing Space', async () => {
// Arrange
const event = new KeyboardEvent('keydown', { key: ' ' });
const clueChangeSpy = jest.spyOn(component.clueChange, 'emit');

// Act
nativeElement.dispatchEvent(event);
await fixture.whenStable();

// Assert
expect(component.isPanelOpen).toBe(true);
Expand Down
31 changes: 22 additions & 9 deletions packages/ng/multi-select/input/select-input.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ describe('LuMultiSelectInputComponent', () => {
fixture.detectChanges();
});

it('should not emit value on init', () => {
it('should not emit value on init', async () => {
// Arrange
const { componentInstance } = fixture;
componentInstance.openPanel();
await wait0();
componentInstance.panelRef.changeDetectorRef.detectChanges();

// Act
Expand All @@ -152,10 +153,11 @@ describe('LuMultiSelectInputComponent', () => {
expect(emittedSelectValues).toEqual([]);
});

it('should emit all when clicking on select all while selection was empty', () => {
it('should emit all when clicking on select all while selection was empty', async () => {
// Arrange
const { componentInstance } = fixture;
componentInstance.openPanel();
await wait0();
componentInstance.panelRef.changeDetectorRef.detectChanges();

// Act
Expand All @@ -166,10 +168,11 @@ describe('LuMultiSelectInputComponent', () => {
expect(emittedSelectValues).toEqual([{ mode: 'all' }]);
});

it('should emit mode exclude when clicking on select all then selecting option', () => {
it('should emit mode exclude when clicking on select all then selecting option', async () => {
// Arrange
const { componentInstance } = fixture;
componentInstance.openPanel();
await wait0();
componentInstance.panelRef.changeDetectorRef.detectChanges();

// Act
Expand All @@ -182,10 +185,11 @@ describe('LuMultiSelectInputComponent', () => {
expect(emittedSelectValues).toEqual([{ mode: 'all' }, { mode: 'exclude', values: [options[0]] }]);
});

it('should emit mode include when clicking on select all then selecting option', () => {
it('should emit mode include when clicking on select all then selecting option', async () => {
// Arrange
const { componentInstance } = fixture;
componentInstance.openPanel();
await wait0();
componentInstance.panelRef.changeDetectorRef.detectChanges();

// Act
Expand All @@ -196,10 +200,11 @@ describe('LuMultiSelectInputComponent', () => {
expect(emittedSelectValues).toEqual([{ mode: 'include', values: [options[0]] }]);
});

it('should set "all" selection when clicking on select all with included option', () => {
it('should set "all" selection when clicking on select all with included option', async () => {
// Arrange
const { componentInstance } = fixture;
componentInstance.openPanel();
await wait0();
componentInstance.panelRef.changeDetectorRef.detectChanges();

// Act
Expand All @@ -212,10 +217,11 @@ describe('LuMultiSelectInputComponent', () => {
expect(emittedSelectValues).toEqual([{ mode: 'include', values: [options[0]] }, { mode: 'all' }]);
});

it('should set "none" selection when clicking on select all with excluded option', () => {
it('should set "none" selection when clicking on select all with excluded option', async () => {
// Arrange
const { componentInstance } = fixture;
componentInstance.openPanel();
await wait0();
componentInstance.panelRef.changeDetectorRef.detectChanges();

// Act
Expand All @@ -230,9 +236,10 @@ describe('LuMultiSelectInputComponent', () => {
expect(emittedSelectValues).toEqual([{ mode: 'all' }, { mode: 'exclude', values: [options[0]] }, { mode: 'none' }]);
});

it('should emit mode all when clicking on each option', () => {
it('should emit mode all when clicking on each option', async () => {
const { componentInstance } = fixture;
componentInstance.openPanel();
await wait0();
componentInstance.panelRef.changeDetectorRef.detectChanges();

// Act
Expand All @@ -243,10 +250,11 @@ describe('LuMultiSelectInputComponent', () => {
expect(emittedSelectValues).toEqual([{ mode: 'all' }]);
});

it('should emit "none" selection when clicking on select all then clear', () => {
it('should emit "none" selection when clicking on select all then clear', async () => {
// Arrange
const { componentInstance } = fixture;
componentInstance.openPanel();
await wait0();
componentInstance.panelRef.changeDetectorRef.detectChanges();

// Act
Expand All @@ -259,10 +267,11 @@ describe('LuMultiSelectInputComponent', () => {
expect(emittedSelectValues).toEqual([{ mode: 'all' }, { mode: 'none' }]);
});

it('should emit "none" selection when clicking on select all then unselect each option', () => {
it('should emit "none" selection when clicking on select all then unselect each option', async () => {
// Arrange
const { componentInstance } = fixture;
componentInstance.openPanel();
await wait0();
componentInstance.panelRef.changeDetectorRef.detectChanges();

// Act
Expand Down Expand Up @@ -307,3 +316,7 @@ function createComponent(override?: MetadataOverride<Component>) {

return TestBed.createComponent<LuMultiSelectInputComponent<Entity>>(LuMultiSelectInputComponent);
}

function wait0() {
return new Promise((resolve) => setTimeout(resolve, 0));
}
12 changes: 12 additions & 0 deletions setup-jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ Element.prototype.scrollIntoView = () => {};
// It is used in LF's schematics tests
Object.assign(global, { TextDecoder, TextEncoder });

const originalError = console.error;
const hideCssParseError = (...args: unknown[]) => {
if (args[0] && typeof args[0] === 'object' && args[0].constructor.name === 'Error' && args[0]['type'] === 'css parsing') {
// JSDOM doesn't support CSS @layer rules and throws verbose errors
return;
} else {
originalError(...args);
}
};

console.error = hideCssParseError;

class ResizeObserver {
observe() {}
unobserve() {}
Expand Down

0 comments on commit a12a80e

Please sign in to comment.