mirror of https://github.com/abpframework/abp.git
committed by
GitHub
174 changed files with 2476 additions and 1155 deletions
@ -0,0 +1,8 @@ |
|||
{ |
|||
"permissions": { |
|||
"allow": [ |
|||
"Bash(yarn nx g:*)", |
|||
"Bash(npx vitest:*)" |
|||
] |
|||
} |
|||
} |
|||
@ -1,5 +1,8 @@ |
|||
import { getJestProjectsAsync } from '@nx/jest'; |
|||
|
|||
/** |
|||
* @deprecated use vitest instead of jest |
|||
* @see https://vitest.dev/guide/migration.html#jest
|
|||
*/ |
|||
export default async () => ({ |
|||
projects: await getJestProjectsAsync(), |
|||
}); |
|||
|
|||
@ -0,0 +1,21 @@ |
|||
import { defineConfig } from 'vitest/config'; |
|||
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; |
|||
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; |
|||
|
|||
export default defineConfig(() => ({ |
|||
root: __dirname, |
|||
cacheDir: '../../node_modules/.vite/packages/account-core', |
|||
plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])], |
|||
test: { |
|||
name: 'account-core', |
|||
watch: false, |
|||
globals: true, |
|||
environment: 'jsdom', |
|||
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], |
|||
reporters: ['default'], |
|||
coverage: { |
|||
reportsDirectory: '../../coverage/packages/account-core', |
|||
provider: 'v8' as const, |
|||
}, |
|||
}, |
|||
})); |
|||
@ -0,0 +1,21 @@ |
|||
import { defineConfig } from 'vitest/config'; |
|||
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; |
|||
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; |
|||
|
|||
export default defineConfig(() => ({ |
|||
root: __dirname, |
|||
cacheDir: '../../node_modules/.vite/packages/account', |
|||
plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])], |
|||
test: { |
|||
name: 'account', |
|||
watch: false, |
|||
globals: true, |
|||
environment: 'jsdom', |
|||
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], |
|||
reporters: ['default'], |
|||
coverage: { |
|||
reportsDirectory: '../../coverage/packages/account', |
|||
provider: 'v8' as const, |
|||
}, |
|||
}, |
|||
})); |
|||
@ -0,0 +1,21 @@ |
|||
import { defineConfig } from 'vitest/config'; |
|||
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; |
|||
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; |
|||
|
|||
export default defineConfig(() => ({ |
|||
root: __dirname, |
|||
cacheDir: '../../node_modules/.vite/packages/components', |
|||
plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])], |
|||
test: { |
|||
name: 'components', |
|||
watch: false, |
|||
globals: true, |
|||
environment: 'jsdom', |
|||
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], |
|||
reporters: ['default'], |
|||
coverage: { |
|||
reportsDirectory: '../../coverage/packages/components', |
|||
provider: 'v8' as const, |
|||
}, |
|||
}, |
|||
})); |
|||
@ -1,23 +0,0 @@ |
|||
/* eslint-disable */ |
|||
export default { |
|||
displayName: 'core', |
|||
preset: '../../jest.preset.js', |
|||
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'], |
|||
globals: {}, |
|||
coverageDirectory: '../../coverage/packages/core', |
|||
transform: { |
|||
'^.+.(ts|mjs|js|html)$': [ |
|||
'jest-preset-angular', |
|||
{ |
|||
tsconfig: '<rootDir>/tsconfig.spec.json', |
|||
stringifyContentPathRegex: '\\.(html|svg)$', |
|||
}, |
|||
], |
|||
}, |
|||
transformIgnorePatterns: ['node_modules/(?!.*.mjs$)'], |
|||
snapshotSerializers: [ |
|||
'jest-preset-angular/build/serializers/no-ng-attributes', |
|||
'jest-preset-angular/build/serializers/ng-snapshot', |
|||
'jest-preset-angular/build/serializers/html-comment', |
|||
], |
|||
}; |
|||
@ -1,100 +1,109 @@ |
|||
import { TestBed} from '@angular/core/testing'; |
|||
import { DOCUMENT } from '@angular/common'; |
|||
|
|||
import { InternetConnectionService } from '../services/internet-connection-service'; |
|||
import { first } from 'rxjs'; |
|||
|
|||
let service: InternetConnectionService; |
|||
|
|||
describe('Internet connection when disconnected', () => { |
|||
const events = {}; |
|||
const addEventListener = jest.fn((event, callback) => { |
|||
events[event] = callback; |
|||
}); |
|||
const mockDocument = { defaultView: {navigator: {onLine: false}, addEventListener } } |
|||
beforeAll(() => { |
|||
TestBed.configureTestingModule({ |
|||
providers:[{provide:DOCUMENT, useValue: mockDocument}] |
|||
}) |
|||
service = TestBed.inject(InternetConnectionService); |
|||
}); |
|||
|
|||
it('document should be created', () => { |
|||
expect(service.document).toEqual(mockDocument); |
|||
}); |
|||
|
|||
it('signal value should be false', () => { |
|||
expect(service.networkStatus()).toEqual(false); |
|||
}); |
|||
|
|||
it('observable value should be false', |
|||
(done: any) => { |
|||
service.networkStatus$.pipe(first()).subscribe(value => { |
|||
expect(value).toBe(false) |
|||
done(); |
|||
}); |
|||
}); |
|||
|
|||
test.each(['offline','online'])('should addEventListener for %p, event',(v)=>{ |
|||
expect(events[v]).toBeTruthy() |
|||
}) |
|||
|
|||
test.each([['offline',false],["online",true]])('when %p called ,then signal value must be %p',(eventName,value)=>{ |
|||
events[eventName]() |
|||
expect(service.networkStatus()).toEqual(value); |
|||
}) |
|||
|
|||
test.each([['offline',false],["online",true]])('when %p called,then observable must return %p',(eventName,value)=>{ |
|||
events[eventName]() |
|||
service.networkStatus$.subscribe(val=>{ |
|||
expect(val).toEqual(value) |
|||
}) |
|||
}) |
|||
}); |
|||
|
|||
describe('when connection value changes for signals', () => { |
|||
const events = {}; |
|||
const addEventListener = jest.fn((event, callback) => { |
|||
events[event] = callback; |
|||
}); |
|||
const mockDocument = { defaultView: {navigator: {onLine: false}, addEventListener } } |
|||
beforeAll(() => { |
|||
TestBed.configureTestingModule({ |
|||
providers:[{provide:DOCUMENT, useValue: mockDocument}] |
|||
}) |
|||
service = TestBed.inject(InternetConnectionService); |
|||
}); |
|||
|
|||
it('signal value must be false when offline event is called while internet is connected', () => { |
|||
events['online']() |
|||
expect(service.networkStatus()).toEqual(true); |
|||
events['offline']() |
|||
expect(service.networkStatus()).toEqual(false); |
|||
}); |
|||
|
|||
it('signal value must be true when online event is called while internet is disconnected', () => { |
|||
events['offline']() |
|||
expect(service.networkStatus()).toEqual(false); |
|||
events['online']() |
|||
expect(service.networkStatus()).toEqual(true); |
|||
}); |
|||
|
|||
it('observable value must be false when offline event is called while internet is connected', (done:any) => { |
|||
events['online']() |
|||
events['offline']() |
|||
service.networkStatus$.subscribe(val=>{ |
|||
expect(val).toEqual(false) |
|||
done() |
|||
}) |
|||
}); |
|||
|
|||
it('observable value must be true when online event is called while internet is disconnected', (done:any) => { |
|||
events['offline']() |
|||
events['online']() |
|||
service.networkStatus$.subscribe(val=>{ |
|||
console.log(val); |
|||
expect(val).toEqual(true) |
|||
done() |
|||
}) |
|||
}); |
|||
}); |
|||
import { TestBed } from '@angular/core/testing'; |
|||
import { DOCUMENT } from '@angular/common'; |
|||
|
|||
import { InternetConnectionService } from '../services/internet-connection-service'; |
|||
import { first, firstValueFrom, skip } from 'rxjs'; |
|||
|
|||
let service: InternetConnectionService; |
|||
|
|||
describe('Internet connection when disconnected', () => { |
|||
const events = {}; |
|||
const addEventListener = vi.fn((event, callback) => { |
|||
events[event] = callback; |
|||
}); |
|||
const mockDocument = { defaultView: { navigator: { onLine: false }, addEventListener } }; |
|||
beforeAll(() => { |
|||
TestBed.configureTestingModule({ |
|||
providers: [{ provide: DOCUMENT, useValue: mockDocument }], |
|||
}); |
|||
service = TestBed.inject(InternetConnectionService); |
|||
}); |
|||
|
|||
it('document should be created', () => { |
|||
expect(service.document).toEqual(mockDocument); |
|||
}); |
|||
|
|||
it('signal value should be false', () => { |
|||
expect(service.networkStatus()).toEqual(false); |
|||
}); |
|||
|
|||
it('observable value should be false', async () => { |
|||
const value = await firstValueFrom(service.networkStatus$.pipe(first())); |
|||
expect(value).toBe(false); |
|||
}); |
|||
|
|||
test.each(['offline', 'online'])('should addEventListener for %p, event', v => { |
|||
expect(events[v]).toBeTruthy(); |
|||
}); |
|||
|
|||
test.each([ |
|||
['offline', false], |
|||
['online', true], |
|||
])('when %p called ,then signal value must be %p', (eventName, value) => { |
|||
events[eventName](); |
|||
expect(service.networkStatus()).toEqual(value); |
|||
}); |
|||
|
|||
test.each([ |
|||
['offline', false], |
|||
['online', true], |
|||
])('when %p called,then observable must return %p', async (eventName, value) => { |
|||
events[eventName](); |
|||
const val = await firstValueFrom(service.networkStatus$); |
|||
expect(val).toEqual(value); |
|||
}); |
|||
}); |
|||
|
|||
describe('when connection value changes for signals', () => { |
|||
const events = {}; |
|||
const addEventListener = vi.fn((event, callback) => { |
|||
events[event] = callback; |
|||
}); |
|||
const mockDocument = { defaultView: { navigator: { onLine: false }, addEventListener } }; |
|||
beforeAll(() => { |
|||
TestBed.configureTestingModule({ |
|||
providers: [{ provide: DOCUMENT, useValue: mockDocument }], |
|||
}); |
|||
service = TestBed.inject(InternetConnectionService); |
|||
}); |
|||
|
|||
it('signal value must be false when offline event is called while internet is connected', () => { |
|||
events['online'](); |
|||
expect(service.networkStatus()).toEqual(true); |
|||
events['offline'](); |
|||
expect(service.networkStatus()).toEqual(false); |
|||
}); |
|||
|
|||
it('signal value must be true when online event is called while internet is disconnected', () => { |
|||
events['offline'](); |
|||
expect(service.networkStatus()).toEqual(false); |
|||
events['online'](); |
|||
expect(service.networkStatus()).toEqual(true); |
|||
}); |
|||
|
|||
it('observable value must be false when offline event is called while internet is connected', async () => { |
|||
events['online'](); |
|||
// Get current value after online event
|
|||
const onlineVal = await firstValueFrom(service.networkStatus$); |
|||
expect(onlineVal).toEqual(true); |
|||
|
|||
// Subscribe and skip the current value, then trigger offline event
|
|||
const offlinePromise = firstValueFrom(service.networkStatus$.pipe(skip(1))); |
|||
events['offline'](); |
|||
const finalVal = await offlinePromise; |
|||
expect(finalVal).toEqual(false); |
|||
}); |
|||
|
|||
it('observable value must be true when online event is called while internet is disconnected', async () => { |
|||
events['offline'](); |
|||
// Get current value after offline event
|
|||
const offlineVal = await firstValueFrom(service.networkStatus$); |
|||
expect(offlineVal).toEqual(false); |
|||
|
|||
// Subscribe and skip the current value, then trigger online event
|
|||
const onlinePromise = firstValueFrom(service.networkStatus$.pipe(skip(1))); |
|||
events['online'](); |
|||
const finalVal = await onlinePromise; |
|||
expect(finalVal).toEqual(true); |
|||
}); |
|||
}); |
|||
|
|||
@ -1,55 +1,63 @@ |
|||
import { Component, DebugElement } from '@angular/core' |
|||
import { ComponentFixture, TestBed } from '@angular/core/testing' |
|||
import { ShowPasswordDirective } from '../directives'; |
|||
import { By } from '@angular/platform-browser'; |
|||
|
|||
@Component({ |
|||
standalone:true, |
|||
template: ` |
|||
<input [abpShowPassword]="true"> |
|||
<input [abpShowPassword]="false"> |
|||
<input /> |
|||
<input [abpShowPassword]="showPassword" />`,
|
|||
imports:[ShowPasswordDirective] |
|||
}) |
|||
class TestComponent { |
|||
showPassword = false |
|||
} |
|||
|
|||
describe('ShowPasswordDirective',()=>{ |
|||
let fixture: ComponentFixture<TestComponent>;; |
|||
let des : DebugElement[]; |
|||
let desAll : DebugElement[]; |
|||
let bareInput; |
|||
|
|||
beforeEach(()=>{ |
|||
fixture = TestBed.configureTestingModule({ |
|||
imports: [ TestComponent ] |
|||
}).createComponent(TestComponent) |
|||
|
|||
fixture.detectChanges(); |
|||
|
|||
des = fixture.debugElement.queryAll(By.directive(ShowPasswordDirective)); |
|||
|
|||
desAll = fixture.debugElement.queryAll(By.all()); |
|||
|
|||
bareInput = fixture.debugElement.query(By.css('input:not([abpShowPassword])')); |
|||
}) |
|||
|
|||
it('should have three input has ShowPasswordDirective elements', () => { |
|||
expect(des.length).toBe(3); |
|||
}); |
|||
|
|||
test.each([[0,'text'],[1,'password'],[2,'text'],[3,'password']])('%p. input type must be %p)', (index,inpType) => { |
|||
const inputType = desAll[index].nativeElement.type; |
|||
expect(inputType).toBe(inpType); |
|||
}); |
|||
|
|||
it('should have three input has ShowPasswordDirective elements', () => { |
|||
const input = des[2].nativeElement |
|||
expect(input.type).toBe('password') |
|||
fixture.componentInstance.showPassword = true |
|||
fixture.detectChanges() |
|||
expect(input.type).toBe('text') |
|||
}); |
|||
}); |
|||
import { Component, DebugElement, ChangeDetectorRef } from '@angular/core'; |
|||
import { ComponentFixture, TestBed } from '@angular/core/testing'; |
|||
import { By } from '@angular/platform-browser'; |
|||
import { ShowPasswordDirective } from '../directives'; |
|||
|
|||
@Component({ |
|||
template: ` <input [abpShowPassword]="true" />
|
|||
<input [abpShowPassword]="false" /> |
|||
<input /> |
|||
<input [abpShowPassword]="showPassword" />`,
|
|||
imports: [ShowPasswordDirective], |
|||
}) |
|||
class TestComponent { |
|||
showPassword = false; |
|||
} |
|||
|
|||
describe('ShowPasswordDirective', () => { |
|||
let fixture: ComponentFixture<TestComponent>; |
|||
let des: DebugElement[]; |
|||
let desAll: DebugElement[]; |
|||
let bareInput; |
|||
|
|||
beforeEach(() => { |
|||
fixture = TestBed.configureTestingModule({ |
|||
imports: [TestComponent], |
|||
}).createComponent(TestComponent); |
|||
|
|||
fixture.detectChanges(); |
|||
|
|||
des = fixture.debugElement.queryAll(By.directive(ShowPasswordDirective)); |
|||
|
|||
desAll = fixture.debugElement.queryAll(By.all()); |
|||
|
|||
bareInput = fixture.debugElement.query(By.css('input:not([abpShowPassword])')); |
|||
}); |
|||
|
|||
it('should have three input has ShowPasswordDirective elements', () => { |
|||
expect(des.length).toBe(3); |
|||
}); |
|||
|
|||
test.each([ |
|||
[0, 'text'], |
|||
[1, 'password'], |
|||
[2, 'text'], |
|||
[3, 'password'], |
|||
])('%p. input type must be %p)', (index, inpType) => { |
|||
const inputType = desAll[index].nativeElement.type; |
|||
expect(inputType).toBe(inpType); |
|||
}); |
|||
|
|||
it('should toggle input type when showPassword changes', () => { |
|||
const input = des[2].nativeElement; |
|||
expect(input.type).toBe('password'); |
|||
|
|||
fixture.componentInstance.showPassword = true; |
|||
|
|||
const cdr = fixture.componentRef.injector.get(ChangeDetectorRef); |
|||
cdr.markForCheck(); |
|||
cdr.detectChanges(); |
|||
|
|||
expect(input.type).toBe('text'); |
|||
}); |
|||
}); |
|||
|
|||
@ -0,0 +1,22 @@ |
|||
import { defineConfig } from 'vitest/config'; |
|||
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; |
|||
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; |
|||
|
|||
export default defineConfig(() => ({ |
|||
root: __dirname, |
|||
cacheDir: '../../node_modules/.vite/packages/core', |
|||
plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])], |
|||
test: { |
|||
name: 'core', |
|||
watch: false, |
|||
globals: true, |
|||
environment: 'jsdom', |
|||
setupFiles: ['src/test-setup.ts'], |
|||
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], |
|||
reporters: ['default'], |
|||
coverage: { |
|||
reportsDirectory: '../../coverage/packages/core', |
|||
provider: 'v8' as const, |
|||
}, |
|||
}, |
|||
})); |
|||
@ -0,0 +1,21 @@ |
|||
import { defineConfig } from 'vitest/config'; |
|||
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; |
|||
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; |
|||
|
|||
export default defineConfig(() => ({ |
|||
root: __dirname, |
|||
cacheDir: '../../node_modules/.vite/packages/feature-management', |
|||
plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])], |
|||
test: { |
|||
name: 'feature-management', |
|||
watch: false, |
|||
globals: true, |
|||
environment: 'jsdom', |
|||
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], |
|||
reporters: ['default'], |
|||
coverage: { |
|||
reportsDirectory: '../../coverage/packages/feature-management', |
|||
provider: 'v8' as const, |
|||
}, |
|||
}, |
|||
})); |
|||
@ -0,0 +1,21 @@ |
|||
import { defineConfig } from 'vitest/config'; |
|||
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; |
|||
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; |
|||
|
|||
export default defineConfig(() => ({ |
|||
root: __dirname, |
|||
cacheDir: '../../node_modules/.vite/packages/generators', |
|||
plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])], |
|||
test: { |
|||
name: 'generators', |
|||
watch: false, |
|||
globals: true, |
|||
environment: 'jsdom', |
|||
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], |
|||
reporters: ['default'], |
|||
coverage: { |
|||
reportsDirectory: '../../coverage/packages/generators', |
|||
provider: 'v8' as const, |
|||
}, |
|||
}, |
|||
})); |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue