mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-16 22:26:16 -08:00
feat: update DialogService tests and add new test runner for ESM libraries
This commit is contained in:
1 parent
122a69047c
commit
7cf00510d1
5 files changed
+189
-42
No files matched your search
@@ -1,43 +1,65 @@
|
||||
/* import { inject, TestBed } from '@angular/core/testing';
|
||||
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { MockComponent, MockModule } from 'ng-mocks';
|
||||
import { EMPTY } from 'rxjs';
|
||||
import { ConfirmDialogData } from '../<../../../apps/web/src/app/shared/components/confirm-dialog/confirm-dialog-data.interface';
|
||||
import { ConfirmDialogComponent } from '../../../../apps/web/src/app/shared/components/confirm-dialog/confirm-dialog.component';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { of } from 'rxjs';
|
||||
import { DialogService } from './dialog.service';
|
||||
|
||||
describe('Service: Dialog', () => {
|
||||
describe('DialogService', () => {
|
||||
let service: DialogService;
|
||||
let dialog: { open: jest.Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
dialog = {
|
||||
open: jest.fn(),
|
||||
};
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
providers: [DialogService, MatDialog],
|
||||
imports: [
|
||||
MockComponent(ConfirmDialogComponent),
|
||||
MockModule(MatDialogModule),
|
||||
TranslateModule.forRoot(),
|
||||
providers: [
|
||||
DialogService,
|
||||
{
|
||||
provide: MatDialog,
|
||||
useValue: dialog,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
service = TestBed.inject(DialogService);
|
||||
});
|
||||
|
||||
it('should create the service', inject(
|
||||
[DialogService],
|
||||
(service: DialogService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}
|
||||
));
|
||||
it('opens the confirm dialog with the expected config', () => {
|
||||
dialog.open.mockReturnValue({
|
||||
afterClosed: () => of(false),
|
||||
});
|
||||
|
||||
it('should open a confirm dialog', inject(
|
||||
[MatDialog, DialogService],
|
||||
(dialog: MatDialog, service: DialogService) => {
|
||||
jest.spyOn(dialog, 'open').mockReturnValue({
|
||||
afterClosed: () => EMPTY,
|
||||
} as any);
|
||||
service.openConfirmDialog({
|
||||
title: 'Remove dialog',
|
||||
message: 'Message',
|
||||
} as ConfirmDialogData);
|
||||
expect(dialog.open).toHaveBeenCalled();
|
||||
}
|
||||
));
|
||||
service.openConfirmDialog({
|
||||
title: 'Remove',
|
||||
message: 'Confirm removal?',
|
||||
onConfirm: jest.fn(),
|
||||
});
|
||||
|
||||
expect(dialog.open).toHaveBeenCalledWith(
|
||||
expect.any(Function),
|
||||
expect.objectContaining({
|
||||
data: expect.objectContaining({
|
||||
title: 'Remove',
|
||||
message: 'Confirm removal?',
|
||||
}),
|
||||
width: '300px',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('invokes onConfirm only after the dialog resolves truthy', () => {
|
||||
const onConfirm = jest.fn();
|
||||
dialog.open.mockReturnValue({
|
||||
afterClosed: () => of(true),
|
||||
});
|
||||
|
||||
service.openConfirmDialog({
|
||||
title: 'Remove',
|
||||
message: 'Confirm removal?',
|
||||
onConfirm,
|
||||
});
|
||||
|
||||
expect(onConfirm).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
*/
|
||||
@@ -7,11 +7,18 @@
|
||||
"tags": ["scope:shared", "domain:shared-ui", "type:util"],
|
||||
"targets": {
|
||||
"test": {
|
||||
"executor": "@nx/jest:jest",
|
||||
"executor": "nx:run-commands",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"options": {
|
||||
"jestConfig": "libs/ui/pipes/jest.config.ts",
|
||||
"tsConfig": "libs/ui/pipes/tsconfig.spec.json"
|
||||
"command": [
|
||||
"node",
|
||||
"./tools/testing/run-web-esm-lib-tests.mjs",
|
||||
"libs/ui/pipes/src"
|
||||
],
|
||||
"env": {
|
||||
"NODE_OPTIONS": "--experimental-vm-modules"
|
||||
},
|
||||
"forwardAllArgs": true
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
/* import { MomentDatePipe } from './moment-date.pipe';
|
||||
import { MomentDatePipe } from './moment-date.pipe';
|
||||
|
||||
describe('Pipe: MomentDate', () => {
|
||||
it('create an instance', () => {
|
||||
const pipe = new MomentDatePipe();
|
||||
expect(pipe).toBeTruthy();
|
||||
describe('MomentDatePipe', () => {
|
||||
let pipe: MomentDatePipe;
|
||||
|
||||
beforeEach(() => {
|
||||
pipe = new MomentDatePipe();
|
||||
});
|
||||
|
||||
it('formats ISO strings using the requested output format', () => {
|
||||
expect(pipe.transform('2026-03-28T12:00:00.000Z', 'YYYY-MM-DD')).toBe(
|
||||
'2026-03-28'
|
||||
);
|
||||
});
|
||||
|
||||
it('supports explicit parse formats for non-ISO values', () => {
|
||||
expect(
|
||||
pipe.transform('28/03/2026', 'YYYY-MM-DD', 'DD/MM/YYYY')
|
||||
).toBe('2026-03-28');
|
||||
});
|
||||
});
|
||||
*/
|
||||
Reference in new issue
Block a user