Browse Source

update: some elements for the tests

pull/24530/head
sumeyye 2 weeks ago
parent
commit
f1e7b8e560
  1. 3
      npm/ng-packs/packages/core/src/lib/components/dynamic-layout.component.ts
  2. 36
      npm/ng-packs/packages/core/src/lib/directives/for.directive.ts
  3. 26
      npm/ng-packs/packages/core/src/lib/directives/permission.directive.ts
  4. 3
      npm/ng-packs/packages/core/src/lib/services/list.service.ts
  5. 2
      npm/ng-packs/packages/core/src/lib/services/router-events.service.ts
  6. 2
      npm/ng-packs/packages/core/tsconfig.spec.json
  7. 18
      npm/ng-packs/packages/core/vite.config.ts
  8. 8
      npm/ng-packs/packages/core/vitest.config.mts

3
npm/ng-packs/packages/core/src/lib/components/dynamic-layout.component.ts

@ -3,9 +3,6 @@ import {
inject, inject,
input, input,
isDevMode, isDevMode,
OnInit,
Optional,
SkipSelf,
Type, Type,
} from '@angular/core'; } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';

36
npm/ng-packs/packages/core/src/lib/directives/for.directive.ts

@ -1,16 +1,16 @@
import { import {
Directive, Directive,
EmbeddedViewRef, EmbeddedViewRef,
Input, Input,
IterableChangeRecord, IterableChangeRecord,
IterableChanges, IterableChanges,
IterableDiffer, IterableDiffer,
IterableDiffers, IterableDiffers,
OnChanges, OnChanges,
TemplateRef, TemplateRef,
TrackByFunction, TrackByFunction,
ViewContainerRef, ViewContainerRef,
inject inject,
} from '@angular/core'; } from '@angular/core';
import clone from 'just-clone'; import clone from 'just-clone';
import compare from 'just-compare'; import compare from 'just-compare';
@ -67,6 +67,7 @@ export class ForDirective implements OnChanges {
emptyRef?: TemplateRef<any>; emptyRef?: TemplateRef<any>;
private differ!: IterableDiffer<any> | null; private differ!: IterableDiffer<any> | null;
private lastItemsRef: any[] | null = null;
private isShowEmptyRef!: boolean; private isShowEmptyRef!: boolean;
@ -136,6 +137,7 @@ export class ForDirective implements OnChanges {
this.vcRef.createEmbeddedView(this.emptyRef).rootNodes; this.vcRef.createEmbeddedView(this.emptyRef).rootNodes;
this.isShowEmptyRef = true; this.isShowEmptyRef = true;
this.differ = null; this.differ = null;
this.lastItemsRef = null;
return; return;
} }
@ -169,6 +171,14 @@ export class ForDirective implements OnChanges {
} }
ngOnChanges() { ngOnChanges() {
if (!this.items) return;
// Recreate differ if items array reference changed
if (this.lastItemsRef !== this.items) {
this.differ = null;
this.lastItemsRef = this.items;
}
let items = clone(this.items) as any[]; let items = clone(this.items) as any[];
if (!Array.isArray(items)) return; if (!Array.isArray(items)) return;

26
npm/ng-packs/packages/core/src/lib/directives/permission.directive.ts

@ -1,13 +1,13 @@
import { import {
AfterViewInit, AfterViewInit,
ChangeDetectorRef, ChangeDetectorRef,
Directive, Directive,
Input, Input,
OnChanges, OnChanges,
OnDestroy, OnDestroy,
TemplateRef, TemplateRef,
ViewContainerRef, ViewContainerRef,
inject inject,
} from '@angular/core'; } from '@angular/core';
import { ReplaySubject, Subscription } from 'rxjs'; import { ReplaySubject, Subscription } from 'rxjs';
import { distinctUntilChanged, take } from 'rxjs/operators'; import { distinctUntilChanged, take } from 'rxjs/operators';
@ -19,7 +19,7 @@ import { QueueManager } from '../utils/queue';
selector: '[abpPermission]', selector: '[abpPermission]',
}) })
export class PermissionDirective implements OnDestroy, OnChanges, AfterViewInit { export class PermissionDirective implements OnDestroy, OnChanges, AfterViewInit {
private templateRef = inject<TemplateRef<any>>(TemplateRef, { optional: true })!; private templateRef = inject<TemplateRef<any>>(TemplateRef, { optional: true });
private vcRef = inject(ViewContainerRef); private vcRef = inject(ViewContainerRef);
private permissionService = inject(PermissionService); private permissionService = inject(PermissionService);
private cdRef = inject(ChangeDetectorRef); private cdRef = inject(ChangeDetectorRef);
@ -45,7 +45,9 @@ export class PermissionDirective implements OnDestroy, OnChanges, AfterViewInit
.pipe(distinctUntilChanged()) .pipe(distinctUntilChanged())
.subscribe(isGranted => { .subscribe(isGranted => {
this.vcRef.clear(); this.vcRef.clear();
if (isGranted) this.vcRef.createEmbeddedView(this.templateRef); if (isGranted && this.templateRef) {
this.vcRef.createEmbeddedView(this.templateRef);
}
if (this.runChangeDetection) { if (this.runChangeDetection) {
if (!this.rendered) { if (!this.rendered) {
this.cdrSubject.next(); this.cdrSubject.next();

3
npm/ng-packs/packages/core/src/lib/services/list.service.ts

@ -2,6 +2,7 @@ import { Injectable, Injector, OnDestroy, inject } from '@angular/core';
import { import {
EMPTY, EMPTY,
BehaviorSubject, BehaviorSubject,
defer,
MonoTypeOperatorFunction, MonoTypeOperatorFunction,
Observable, Observable,
ReplaySubject, ReplaySubject,
@ -134,7 +135,7 @@ export class ListService<QueryParamsType = ABP.PageQueryParams | any> implements
tap(() => this._isLoading$.next(true)), tap(() => this._isLoading$.next(true)),
tap(() => this._requestStatus.next('loading')), tap(() => this._requestStatus.next('loading')),
switchMap(query => switchMap(query =>
streamCreatorCallback(query).pipe( defer(() => streamCreatorCallback(query)).pipe(
catchError(() => { catchError(() => {
this._requestStatus.next('error'); this._requestStatus.next('error');
return EMPTY; return EMPTY;

2
npm/ng-packs/packages/core/src/lib/services/router-events.service.ts

@ -34,7 +34,7 @@ export class RouterEvents {
protected listenToNavigation(): void { protected listenToNavigation(): void {
const routerEvent$ = this.router.events.pipe( const routerEvent$ = this.router.events.pipe(
filter(e => e instanceof NavigationEvent.End && !e.url.includes('error')) filter(e => e instanceof NavigationEvent.End && e.url != null && !e.url.includes('error'))
) as Observable<NavigationEnd>; ) as Observable<NavigationEnd>;
routerEvent$.subscribe(event => { routerEvent$.subscribe(event => {

2
npm/ng-packs/packages/core/tsconfig.spec.json

@ -6,7 +6,7 @@
}, },
"include": [ "include": [
"vite.config.ts", "vite.config.ts",
"vite.config.mts", "vitest.config.mts",
"vitest.config.ts", "vitest.config.ts",
"vitest.config.mts", "vitest.config.mts",
"src/**/*.test.ts", "src/**/*.test.ts",

18
npm/ng-packs/packages/core/vite.config.ts

@ -1,18 +0,0 @@
/// <reference types="vitest" />
import { defineConfig } from 'vitest/config';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
export default defineConfig({
plugins: [nxViteTsPaths()],
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['src/test-setup.ts'],
include: ['src/**/*.spec.ts'],
coverage: {
reportsDirectory: '../../coverage/packages/core',
provider: 'v8',
reporter: ['text', 'json', 'html'],
},
},
});

8
npm/ng-packs/packages/core/vite.config.mts → npm/ng-packs/packages/core/vitest.config.mts

@ -1,5 +1,4 @@
/// <reference types='vitest' /> import { defineConfig } from 'vitest/config';
import { defineConfig } from 'vite';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
@ -7,15 +6,12 @@ export default defineConfig(() => ({
root: __dirname, root: __dirname,
cacheDir: '../../node_modules/.vite/packages/core', cacheDir: '../../node_modules/.vite/packages/core',
plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])], plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])],
// Uncomment this if you are using workers.
// worker: {
// plugins: () => [ nxViteTsPaths() ],
// },
test: { test: {
name: 'core', name: 'core',
watch: false, watch: false,
globals: true, globals: true,
environment: 'jsdom', environment: 'jsdom',
setupFiles: ['src/test-setup.ts'],
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
reporters: ['default'], reporters: ['default'],
coverage: { coverage: {
Loading…
Cancel
Save