diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4feb3c8f8..6c24b926a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,7 @@ jobs: - name: use node.js uses: actions/setup-node@v1 with: - node-version: 18.16.0 + node-version: 20.13.1 - name: build run: | diff --git a/lib/ng-nest/ui/page-header/page-header.component.spec.ts b/lib/ng-nest/ui/page-header/page-header.component.spec.ts index 59fb21b48..fbc2170d7 100644 --- a/lib/ng-nest/ui/page-header/page-header.component.spec.ts +++ b/lib/ng-nest/ui/page-header/page-header.component.spec.ts @@ -1,18 +1,47 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XPageHeaderComponent } from '@ng-nest/ui/page-header'; -import { XPageHeaderPrefix } from './page-header.property'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - +import { XPageHeaderComponent, XPageHeaderPrefix } from '@ng-nest/ui/page-header'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +@Component({ + standalone: true, + imports: [XPageHeaderComponent], + template: ` ` +}) +class XTestPageHeaderComponent {} + +@Component({ + standalone: true, + imports: [XPageHeaderComponent], + template: ` + + + ` +}) +class XTestPageHeaderPropertyComponent { + backIcon = signal('fto-arrow-left'); + backText = signal(''); + title = signal(''); + subTitle = signal(''); + + backClickResult = signal(null); + backClick(event: Event) { + this.backClickResult.set(event); + } +} + describe(XPageHeaderPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXPageHeaderComponent], - imports: [BrowserAnimationsModule, XPageHeaderComponent], + imports: [XTestPageHeaderComponent, XTestPageHeaderPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -20,38 +49,39 @@ describe(XPageHeaderPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let pageheader: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXPageHeaderComponent); + fixture = TestBed.createComponent(XTestPageHeaderComponent); fixture.detectChanges(); - pageheader = fixture.debugElement.query(By.directive(XPageHeaderComponent)); }); - it('should create.', () => { - expect(pageheader).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XPageHeaderComponent)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestPageHeaderPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestPageHeaderPropertyComponent); + // component = fixture.componentInstance; + fixture.detectChanges(); + }); + it('backIcon.', () => { + expect(true).toBe(true); + }); + it('backText.', () => { + expect(true).toBe(true); + }); + it('title.', () => { + expect(true).toBe(true); + }); + it('subTitle.', () => { + expect(true).toBe(true); + }); + it('backClick.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - template: ` - -
- -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXPageHeaderComponent {} diff --git a/lib/ng-nest/ui/pagination/pagination.component.spec.ts b/lib/ng-nest/ui/pagination/pagination.component.spec.ts index f1ef8970b..89dda3801 100644 --- a/lib/ng-nest/ui/pagination/pagination.component.spec.ts +++ b/lib/ng-nest/ui/pagination/pagination.component.spec.ts @@ -1,282 +1,185 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, ChangeDetectorRef, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal, TemplateRef, viewChild } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XPaginationComponent } from '@ng-nest/ui/pagination'; -import { XPaginationPrefix } from './pagination.property'; -import { XI18nService, en_US, zh_CN } from '@ng-nest/ui/i18n'; -import { XButtonComponent } from '@ng-nest/ui/button'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { + XPaginationComponent, + XPaginationInputIndexSizeSureType, + XPaginationPrefix, + XPaginationSizeData +} from '@ng-nest/ui/pagination'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { provideAnimations } from '@angular/platform-browser/animations'; +import { XDataArray, XQuery, XTemplate } from '@ng-nest/ui/core'; +import { XSelectNode } from '@ng-nest/ui/select'; + +@Component({ + standalone: true, + imports: [XPaginationComponent], + template: ` ` +}) +class XTestPaginationComponent {} + +@Component({ + standalone: true, + imports: [XPaginationComponent], + template: ` + + + + {{ total }} + ` +}) +class XTestPaginationPropertyComponent { + index = signal(1); + size = signal(10); + total = signal(0); + query = signal({}); + pageLinkSize = signal(5); + showEllipsis = signal(true); + showTotal = signal(true); + space = signal('0.25rem'); + showBackground = signal(false); + showSize = signal(false); + sizeWidth = signal('6.875rem'); + showInputSize = signal(false); + inputSizeTooltipText = signal(''); + inputSizeWidth = signal('3.125rem'); + sizeData = signal>(XPaginationSizeData); + disabled = signal(false); + showJump = signal(false); + jumpTooltipText = signal(''); + jumpWidth = signal('3.125rem'); + totalTpl = signal(''); + totalTemplate = viewChild>('totalTemplate'); + simple = signal(false); + simpleIndexWidth = signal('8.125rem'); + inputIndexSizeSureType = signal('enter'); +} describe(XPaginationPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXPaginationComponent, TestXPaginationStyleComponent], - imports: [BrowserAnimationsModule, XPaginationComponent, XButtonComponent], + imports: [XTestPaginationComponent, XTestPaginationPropertyComponent], providers: [ + provideAnimations(), provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), provideExperimentalZonelessChangeDetection() ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXPaginationComponent); + fixture = TestBed.createComponent(XTestPaginationComponent); fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XPaginationComponent)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XPaginationComponent)); + expect(com).toBeDefined(); }); }); - describe(`style.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXPaginationStyleComponent); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestPaginationPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestPaginationPropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XPaginationComponent)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('index.', () => { + expect(true).toBe(true); + }); + it('size.', () => { + expect(true).toBe(true); + }); + it('total.', () => { + expect(true).toBe(true); + }); + it('query.', () => { + expect(true).toBe(true); + }); + it('pageLinkSize.', () => { + expect(true).toBe(true); + }); + it('showEllipsis.', () => { + expect(true).toBe(true); + }); + it('showTotal.', () => { + expect(true).toBe(true); + }); + it('space.', () => { + expect(true).toBe(true); + }); + it('showBackground.', () => { + expect(true).toBe(true); + }); + it('showSize.', () => { + expect(true).toBe(true); + }); + it('sizeWidth.', () => { + expect(true).toBe(true); + }); + it('showInputSize.', () => { + expect(true).toBe(true); + }); + it('inputSizeTooltipText.', () => { + expect(true).toBe(true); + }); + it('inputSizeWidth.', () => { + expect(true).toBe(true); + }); + it('sizeData.', () => { + expect(true).toBe(true); + }); + it('disabled.', () => { + expect(true).toBe(true); + }); + it('showJump.', () => { + expect(true).toBe(true); + }); + it('jumpTooltipText.', () => { + expect(true).toBe(true); + }); + it('jumpWidth.', () => { + expect(true).toBe(true); + }); + it('totalTpl.', () => { + expect(true).toBe(true); + }); + it('simple.', () => { + expect(true).toBe(true); + }); + it('simpleIndexWidth.', () => { + expect(true).toBe(true); + }); + it('inputIndexSizeSureType.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - selector: 'test-x-pagination', - template: ` - 切换为英文 - 切换为中文 -
- -
-
- -
-
- -
- - - - - - - - - 共 {{ total }} 条数据 - - `, - styles: [ - ` - :host .row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXPaginationComponent { - index = 1; - size = 10; - total = 100; - - constructor( - private i18nService: XI18nService, - private cdr: ChangeDetectorRef - ) {} - - change(_index: number) { - // console.log(index); - } - - english() { - this.i18nService.setLocale(en_US); - this.cdr.detectChanges(); - } - - chinese() { - this.i18nService.setLocale(zh_CN); - this.cdr.detectChanges(); - } -} - -@Component({ - selector: 'test-x-pagination-style', - template: ` - - - - - - - - - - - - - - ` -}) -class TestXPaginationStyleComponent { - index = 1; - size = 10; - total = 100; - - constructor( - private i18nService: XI18nService, - private cdr: ChangeDetectorRef - ) {} - - change(_index: number) { - // console.log(index); - } - - english() { - this.i18nService.setLocale(en_US); - this.cdr.detectChanges(); - } - - chinese() { - this.i18nService.setLocale(zh_CN); - this.cdr.detectChanges(); - } -} diff --git a/lib/ng-nest/ui/popconfirm/popconfirm.component.spec.ts b/lib/ng-nest/ui/popconfirm/popconfirm.component.spec.ts index 7522d00fd..abaf7a75a 100644 --- a/lib/ng-nest/ui/popconfirm/popconfirm.component.spec.ts +++ b/lib/ng-nest/ui/popconfirm/popconfirm.component.spec.ts @@ -1,92 +1,145 @@ -import { XIconComponent } from '@ng-nest/ui/icon'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, ChangeDetectorRef, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { XPopconfirmComponent } from '@ng-nest/ui/popconfirm'; -import { FormsModule } from '@angular/forms'; -import { XPopconfirmPrefix } from './popconfirm.property'; -import { XButtonComponent } from '@ng-nest/ui/button'; -import { XContainerComponent } from '@ng-nest/ui/container'; -import { interval } from 'rxjs'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - -import { XSwitchComponent } from '@ng-nest/ui/switch'; +import { XPopconfirmComponent, XPopconfirmPrefix } from '@ng-nest/ui/popconfirm'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { provideAnimations } from '@angular/platform-browser/animations'; +import { XPlacement, XTemplate } from '@ng-nest/ui/core'; +import { XPopoverTrigger } from '@ng-nest/ui/popover'; +import { Observable } from 'rxjs'; + +@Component({ + standalone: true, + imports: [XPopconfirmComponent], + template: ` ` +}) +class XTestPopconfirmComponent {} + +@Component({ + standalone: true, + imports: [XPopconfirmComponent], + template: ` + + ` +}) +class XTestPopconfirmPropertyComponent { + title = signal(''); + content = signal(''); + placement = signal('bottom'); + trigger = signal('click'); + width = signal(''); + maxWidth = signal('15rem'); + minWidth = signal('15rem'); + icon = signal('fto-help-circle'); + iconColor = signal('#e6a23c'); + cancelText = signal(''); + confirmText = signal(''); + confirmAsync = signal | null>(null); + condition = signal(false); + + cancelResult = signal(null); + cancel(event: Event) { + this.cancelResult.set(event); + } + + confirmResult = signal(null); + confirm(event: Event) { + this.confirmResult.set(event); + } +} describe(XPopconfirmPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXPopconfirmComponent], - imports: [ - BrowserAnimationsModule, - - FormsModule, - XPopconfirmComponent, - XButtonComponent, - XContainerComponent, - XRowComponent, - XColComponent, - XIconComponent, - XSwitchComponent - ], + imports: [XTestPopconfirmComponent, XTestPopconfirmPropertyComponent], providers: [ + provideAnimations(), provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), provideExperimentalZonelessChangeDetection() ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let popconfirm: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXPopconfirmComponent); + fixture = TestBed.createComponent(XTestPopconfirmComponent); fixture.detectChanges(); - popconfirm = fixture.debugElement.query(By.directive(XPopconfirmComponent)); }); - it('should create.', () => { - expect(popconfirm).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XPopconfirmComponent)); + expect(com).toBeDefined(); }); }); -}); - -@Component({ - template: ` - -
- - 删除 - -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row { - padding-left: 5rem; - } - .row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXPopconfirmComponent { - constructor(public cdr: ChangeDetectorRef) { - interval(1).subscribe(() => { - this.cdr.detectChanges(); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestPopconfirmPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestPopconfirmPropertyComponent); + // component = fixture.componentInstance; + fixture.detectChanges(); }); - } - confirm() { - console.log('confirm'); - } - cancel() { - console.log('cancel'); - } -} + it('title.', () => { + expect(true).toBe(true); + }); + it('content.', () => { + expect(true).toBe(true); + }); + it('placement.', () => { + expect(true).toBe(true); + }); + it('trigger.', () => { + expect(true).toBe(true); + }); + it('width.', () => { + expect(true).toBe(true); + }); + it('maxWidth.', () => { + expect(true).toBe(true); + }); + it('minWidth.', () => { + expect(true).toBe(true); + }); + it('icon.', () => { + expect(true).toBe(true); + }); + it('iconColor.', () => { + expect(true).toBe(true); + }); + it('cancelText.', () => { + expect(true).toBe(true); + }); + it('confirmText.', () => { + expect(true).toBe(true); + }); + it('confirmAsync.', () => { + expect(true).toBe(true); + }); + it('condition.', () => { + expect(true).toBe(true); + }); + it('cancel.', () => { + expect(true).toBe(true); + }); + it('confirm.', () => { + expect(true).toBe(true); + }); + }); +}); diff --git a/lib/ng-nest/ui/popover/popover.directive.spec.ts b/lib/ng-nest/ui/popover/popover.directive.spec.ts index 6e3839633..f4c81a37f 100644 --- a/lib/ng-nest/ui/popover/popover.directive.spec.ts +++ b/lib/ng-nest/ui/popover/popover.directive.spec.ts @@ -1,127 +1,131 @@ -import { XButtonComponent } from '@ng-nest/ui/button'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, ChangeDetectorRef, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, ElementRef, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XPopoverDirective } from '@ng-nest/ui/popover'; -import { XPopoverPrefix } from './popover.property'; -import { interval } from 'rxjs'; -import { XIconComponent } from '@ng-nest/ui/icon'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - +import { XPopoverDirective, XPopoverPrefix, XPopoverTrigger } from '@ng-nest/ui/popover'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XPlacement, XTemplate } from '@ng-nest/ui/core'; +import { provideAnimations } from '@angular/platform-browser/animations'; + +@Component({ + standalone: true, + imports: [XPopoverDirective], + template: `
popover
` +}) +class XTestPopoverComponent {} + +@Component({ + standalone: true, + imports: [XPopoverDirective], + template: ` +
+ ` +}) +class XTestPopoverPropertyComponent { + title = signal(''); + content = signal(''); + footer = signal(''); + panelClass = signal(''); + connectTo = signal | HTMLElement | null>(null); + placement = signal('top'); + trigger = signal('hover'); + width = signal(''); + maxWidth = signal('10rem'); + minWidth = signal('10rem'); + visible = signal(false); + condition = signal(false); + mouseEnterDelay = signal(150); + mouseLeaveDelay = signal(100); +} describe(XPopoverPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXPopoverComponent], - imports: [BrowserAnimationsModule, XPopoverDirective, XButtonComponent, XIconComponent], + imports: [XTestPopoverComponent, XTestPopoverPropertyComponent], providers: [ + provideAnimations(), provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), provideExperimentalZonelessChangeDetection() ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXPopoverComponent); + fixture = TestBed.createComponent(XTestPopoverComponent); fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XPopoverDirective)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XPopoverDirective)); + expect(com).toBeDefined(); }); }); -}); - -@Component({ - selector: 'test-x-popover', - template: ` - -
-
- 上左 - 上中 - 上右 -
-
- 左上左中左下 -
-
- 右上右中右下 -
-
- 下左下中下右 -
-
-
- click 激活 - - 激活 - - - 激活 - - 用户信息 - -
    -
  • 姓名:李永奇
  • -
  • 邮箱:ng-nest@ng-nest.com
  • -
-
-
-
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .box { - padding: 5rem 10rem; - width: 45rem; - } - .box .top { - text-align: center; - } - .box .left { - float: left; - width: 5rem; - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - } - .box .right { - float: right; - width: 5rem; - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - } - .box .bottom { - clear: both; - text-align: center; - } - ` - ] -}) -class TestXPopoverComponent { - constructor(public cdr: ChangeDetectorRef) { - interval(1).subscribe(() => { - this.cdr.detectChanges(); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestPopoverPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestPopoverPropertyComponent); + // component = fixture.componentInstance; + fixture.detectChanges(); }); - } -} + it('title.', () => { + expect(true).toBe(true); + }); + it('content.', () => { + expect(true).toBe(true); + }); + it('footer.', () => { + expect(true).toBe(true); + }); + it('panelClass.', () => { + expect(true).toBe(true); + }); + it('connectTo.', () => { + expect(true).toBe(true); + }); + it('placement.', () => { + expect(true).toBe(true); + }); + it('trigger.', () => { + expect(true).toBe(true); + }); + it('width.', () => { + expect(true).toBe(true); + }); + it('maxWidth.', () => { + expect(true).toBe(true); + }); + it('minWidth.', () => { + expect(true).toBe(true); + }); + it('visible.', () => { + expect(true).toBe(true); + }); + it('condition.', () => { + expect(true).toBe(true); + }); + it('mouseEnterDelay.', () => { + expect(true).toBe(true); + }); + it('mouseLeaveDelay.', () => { + expect(true).toBe(true); + }); + }); +}); diff --git a/lib/ng-nest/ui/progress/progress.component.spec.ts b/lib/ng-nest/ui/progress/progress.component.spec.ts index 40590620e..630fb6a71 100644 --- a/lib/ng-nest/ui/progress/progress.component.spec.ts +++ b/lib/ng-nest/ui/progress/progress.component.spec.ts @@ -1,132 +1,152 @@ -import { XIconComponent } from '@ng-nest/ui/icon'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, ChangeDetectorRef, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { XProgressComponent } from '@ng-nest/ui/progress'; -import { FormsModule } from '@angular/forms'; -import { XProgressPrefix } from './progress.property'; -import { XButtonComponent, XButtonsComponent } from '@ng-nest/ui/button'; -import { XContainerComponent } from '@ng-nest/ui/container'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - +import { + XProgressColor, + XProgressComponent, + XProgressGradient, + XProgressPrefix, + XProgressStatus, + XProgressType +} from '@ng-nest/ui/progress'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { provideAnimations } from '@angular/platform-browser/animations'; + +@Component({ + standalone: true, + imports: [XProgressComponent], + template: ` ` +}) +class XTestProgressComponent {} + +@Component({ + standalone: true, + imports: [XProgressComponent], + template: ` + + + ` +}) +class XTestProgressPropertyComponent { + type = signal('line'); + percent = signal(0); + height = signal('1rem'); + status = signal('normal'); + info = signal(true); + infoWidth = signal('3.5rem'); + inside = signal(false); + format = signal<((percent: number) => string) | null>(null); + color = signal(null); + gradient = signal(null); + steps = signal(null); + stepWidth = signal('2rem'); + stepFlex = signal(false); + thickness = signal('1rem'); + size = signal('8rem'); + notchAngle = signal(80); + subsection = signal(false); +} describe(XProgressPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXProgressComponent], - imports: [ - BrowserAnimationsModule, - - FormsModule, - XProgressComponent, - XButtonComponent, - XButtonsComponent, - XContainerComponent, - XRowComponent, - XColComponent, - XIconComponent - ], + imports: [XTestProgressComponent, XTestProgressPropertyComponent], providers: [ + provideAnimations(), provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), provideExperimentalZonelessChangeDetection() ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let progress: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXProgressComponent); + fixture = TestBed.createComponent(XTestProgressComponent); fixture.detectChanges(); - progress = fixture.debugElement.query(By.directive(XProgressComponent)); }); - it('should create.', () => { - expect(progress).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XProgressComponent)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestProgressPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestProgressPropertyComponent); + // component = fixture.componentInstance; + fixture.detectChanges(); + }); + it('type.', () => { + expect(true).toBe(true); + }); + it('percent.', () => { + expect(true).toBe(true); + }); + it('height.', () => { + expect(true).toBe(true); + }); + it('status.', () => { + expect(true).toBe(true); + }); + it('info.', () => { + expect(true).toBe(true); + }); + it('infoWidth.', () => { + expect(true).toBe(true); + }); + it('inside.', () => { + expect(true).toBe(true); + }); + it('format.', () => { + expect(true).toBe(true); + }); + it('color.', () => { + expect(true).toBe(true); + }); + it('gradient.', () => { + expect(true).toBe(true); + }); + it('steps.', () => { + expect(true).toBe(true); + }); + it('stepWidth.', () => { + expect(true).toBe(true); + }); + it('stepFlex.', () => { + expect(true).toBe(true); + }); + it('thickness.', () => { + expect(true).toBe(true); + }); + it('size.', () => { + expect(true).toBe(true); + }); + it('notchAngle.', () => { + expect(true).toBe(true); + }); + it('subsection.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - template: ` - -
- - - - - - -
-
- - -
-
- - - - - -
-
- - - - - - - -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row { - padding: 1rem; - } - .row:not(:first-child) { - margin-top: 1rem; - } - .row x-progress:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXProgressComponent { - constructor(private cdr: ChangeDetectorRef) {} - format(percent: number) { - return percent === 100 ? '已完成' : `加载中${percent}%`; - } - percent = 10; - color!: '#3f51b5'; - colors = [ - { color: '#f56c6c', percent: 20 }, - { color: '#e6a23c', percent: 40 }, - { color: '#5cb87a', percent: 60 }, - { color: '#1989fa', percent: 80 }, - { color: '#6f7ad3', percent: 100 } - ]; - colorFunc(percent: number) { - if (percent < 30) { - return '#909399'; - } else if (percent < 70) { - return '#e6a23c'; - } else { - return '#67c23a'; - } - } - plus(num: number) { - if ((this.percent === 0 && num === -10) || (this.percent === 100 && num === 10)) return; - this.percent = this.percent + num; - this.cdr.detectChanges(); - } -} diff --git a/lib/ng-nest/ui/radio/radio.component.spec.ts b/lib/ng-nest/ui/radio/radio.component.spec.ts index da623519c..ff7c2d002 100644 --- a/lib/ng-nest/ui/radio/radio.component.spec.ts +++ b/lib/ng-nest/ui/radio/radio.component.spec.ts @@ -1,57 +1,98 @@ -import { XButtonComponent } from '@ng-nest/ui/button'; -import { Observable } from 'rxjs'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, ChangeDetectorRef, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal, TemplateRef, viewChild } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { XRadioComponent } from '@ng-nest/ui/radio'; -import { FormsModule } from '@angular/forms'; -import { XRadioPrefix, XRadioNode } from './radio.property'; -import { XData } from '@ng-nest/ui/core'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - -import { XSelectComponent } from '@ng-nest/ui/select'; -import { XDatePickerComponent } from '@ng-nest/ui/date-picker'; -import { XAutoCompleteComponent } from '@ng-nest/ui/auto-complete'; -import { XCascadeComponent } from '@ng-nest/ui/cascade'; -import { XColorPickerComponent } from '@ng-nest/ui/color-picker'; -import { XFindComponent } from '@ng-nest/ui/find'; -import { XTextareaComponent } from '@ng-nest/ui/textarea'; -import { XTimePickerModule } from '@ng-nest/ui/time-picker'; -import { XInputComponent } from '@ng-nest/ui/input'; -import { XTagComponent } from '@ng-nest/ui/tag'; +import { XRadioComponent, XRadioNode, XRadioPrefix } from '@ng-nest/ui/radio'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XAlign, XData, XDirection, XJustify, XSize, XTemplate } from '@ng-nest/ui/core'; +import { XButtonType } from '@ng-nest/ui/button'; + +@Component({ + standalone: true, + imports: [XRadioComponent], + template: ` ` +}) +class XTestRadioComponent {} + +@Component({ + standalone: true, + imports: [XRadioComponent], + template: ` + + + + before + after + ` +}) +class XTestRadioPropertyComponent { + data = signal>([]); + button = signal(false); + icon = signal(false); + tag = signal(false); + type = signal('initial'); + tagBordered = signal(true); + tagDark = signal(false); + allowCancel = signal(false); + vertical = signal(false); + size = signal('medium'); + pointer = signal(false); + label = signal(''); + labelWidth = signal(''); + labelAlign = signal('start'); + justify = signal('start'); + align = signal('start'); + direction = signal('column'); + placeholder = signal(''); + disabled = signal(false); + required = signal(false); + readonly = signal(false); + valueTpl = signal | null>(null); + valueTplContext = signal(null); + before = signal(null); + beforeTemplate = viewChild>('beforeTemplate'); + after = signal(null); + afterTemplate = viewChild>('afterTemplate'); + pattern = signal(null); + message = signal([]); + active = signal(false); + inputValidator = signal<((value: any) => boolean) | null>(null); +} describe(XRadioPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ - TestXRadioComponent, - TestXRadioDisabledComponent, - TestXRadioButtonComponent, - TestXRadioIconComponent, - TestXRadioAsyncComponent - ], - imports: [ - BrowserAnimationsModule, - - FormsModule, - XRadioComponent, - XAutoCompleteComponent, - XSelectComponent, - XDatePickerComponent, - XButtonComponent, - XRowComponent, - XColComponent, - XCascadeComponent, - XColorPickerComponent, - XFindComponent, - XTextareaComponent, - XTimePickerModule, - XInputComponent, - XTagComponent - ], + imports: [XTestRadioComponent, XTestRadioPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -59,271 +100,111 @@ describe(XRadioPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let radio: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXRadioComponent); + fixture = TestBed.createComponent(XTestRadioComponent); fixture.detectChanges(); - radio = fixture.debugElement.query(By.directive(XRadioComponent)); }); - it('should create.', () => { - expect(radio).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XRadioComponent)); + expect(com).toBeDefined(); }); }); - describe(`disabled.`, () => { - let fixture: ComponentFixture; - let radio: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXRadioDisabledComponent); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestRadioPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestRadioPropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - radio = fixture.debugElement.query(By.directive(XRadioComponent)); }); - it('should create.', () => { - expect(radio).toBeDefined(); + it('data.', () => { + expect(true).toBe(true); }); - }); - describe(`button.`, () => { - let fixture: ComponentFixture; - let radio: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXRadioButtonComponent); - fixture.detectChanges(); - radio = fixture.debugElement.query(By.directive(XRadioComponent)); + it('button.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(radio).toBeDefined(); + it('icon.', () => { + expect(true).toBe(true); }); - }); - describe(`icon.`, () => { - let fixture: ComponentFixture; - let radio: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXRadioIconComponent); - fixture.detectChanges(); - radio = fixture.debugElement.query(By.directive(XRadioComponent)); + it('tag.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(radio).toBeDefined(); + it('type.', () => { + expect(true).toBe(true); }); - }); - describe(`async.`, () => { - let fixture: ComponentFixture; - let radio: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXRadioAsyncComponent); - fixture.detectChanges(); - radio = fixture.debugElement.query(By.directive(XRadioComponent)); + it('tagBordered.', () => { + expect(true).toBe(true); + }); + it('tagDark.', () => { + expect(true).toBe(true); + }); + it('allowCancel.', () => { + expect(true).toBe(true); + }); + it('vertical.', () => { + expect(true).toBe(true); + }); + it('size.', () => { + expect(true).toBe(true); + }); + it('pointer.', () => { + expect(true).toBe(true); + }); + it('label.', () => { + expect(true).toBe(true); + }); + it('labelWidth.', () => { + expect(true).toBe(true); + }); + it('labelAlign.', () => { + expect(true).toBe(true); + }); + it('justify.', () => { + expect(true).toBe(true); + }); + it('align.', () => { + expect(true).toBe(true); + }); + it('direction.', () => { + expect(true).toBe(true); + }); + it('placeholder.', () => { + expect(true).toBe(true); + }); + it('disabled.', () => { + expect(true).toBe(true); + }); + it('required.', () => { + expect(true).toBe(true); + }); + it('readonly.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(radio).toBeDefined(); + it('valueTpl.', () => { + expect(true).toBe(true); + }); + it('valueTplContext.', () => { + expect(true).toBe(true); + }); + it('before.', () => { + expect(true).toBe(true); + }); + it('after.', () => { + expect(true).toBe(true); + }); + it('pattern.', () => { + expect(true).toBe(true); + }); + it('message.', () => { + expect(true).toBe(true); + }); + it('active.', () => { + expect(true).toBe(true); + }); + it('inputValidator.', () => { + expect(true).toBe(true); }); }); }); - -const data: string[] = ['QQ', '微信', '钉钉', '微博']; - -const iconData: XData = [ - { label: 'QQ', icon: 'ado-qq' }, - { label: '微信', icon: 'ado-wechat' }, - { label: '钉钉', icon: 'ado-dingding' }, - { label: '微博', icon: 'ado-weibo' } -]; - -@Component({ - template: ` - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXRadioComponent { - data: XData = data; - model = 'QQ'; -} - -@Component({ - template: ` - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXRadioDisabledComponent { - data: XData = data; - dataDisabled: XData = ['QQ', '微信', { label: '钉钉', disabled: true }, '微博']; - model = '钉钉'; -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXRadioButtonComponent { - data: XData = data; - dataDisabled: XData = ['QQ', '微信', { label: '钉钉', disabled: true }, '微博']; - model = '钉钉'; -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXRadioIconComponent { - data: XData = iconData; - dataDisabled: XData = [ - { label: 'QQ', icon: 'ado-qq' }, - { label: '微信', icon: 'ado-wechat' }, - { label: '钉钉', disabled: true, icon: 'ado-dingding' }, - { label: '微博', icon: 'ado-weibo' } - ]; - model = '钉钉'; -} - -@Component({ - template: ` - - - - 请求 - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXRadioAsyncComponent { - constructor(public cdr: ChangeDetectorRef) {} - data!: XData; - model = 2; - loading = false; - getData() { - this.loading = true; - this.data = new Observable((x) => { - // 替换成http请求,或者data直接定义成 Observable 对象 - setTimeout(() => { - this.model = 3; - this.loading = false; - this.cdr.detectChanges(); - x.next(data); - x.complete(); - }, 2000); - }); - this.cdr.detectChanges(); - } -} diff --git a/lib/ng-nest/ui/rate/rate.component.spec.ts b/lib/ng-nest/ui/rate/rate.component.spec.ts index 28c0dc1c5..0d22f2ec8 100644 --- a/lib/ng-nest/ui/rate/rate.component.spec.ts +++ b/lib/ng-nest/ui/rate/rate.component.spec.ts @@ -1,228 +1,188 @@ -import { XButtonComponent } from '@ng-nest/ui/button'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal, TemplateRef, viewChild } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { XRateComponent } from '@ng-nest/ui/rate'; -import { FormsModule } from '@angular/forms'; -import { XRatePrefix } from './rate.property'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { XIconComponent } from '@ng-nest/ui/icon'; +import { XRateColor, XRateComponent, XRatePrefix } from '@ng-nest/ui/rate'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { provideAnimations } from '@angular/platform-browser/animations'; +import { XAlign, XDirection, XJustify, XSize, XTemplate } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XRateComponent], + template: ` ` +}) +class XTestRateComponent {} + +@Component({ + standalone: true, + imports: [XRateComponent], + template: ` + + + + custom + + before + after + ` +}) +class XTestRatePropertyComponent { + count = signal(5); + half = signal(false); + color = signal(''); + customTemp = signal | null>(null); + size = signal('medium'); + pointer = signal(false); + label = signal(''); + labelWidth = signal(''); + labelAlign = signal('start'); + justify = signal('start'); + align = signal('start'); + direction = signal('column'); + placeholder = signal(''); + disabled = signal(false); + required = signal(false); + readonly = signal(false); + valueTpl = signal | null>(null); + valueTplContext = signal(null); + before = signal(null); + beforeTemplate = viewChild>('beforeTemplate'); + after = signal(null); + afterTemplate = viewChild>('afterTemplate'); + pattern = signal(null); + message = signal([]); + active = signal(false); + inputValidator = signal<((value: any) => boolean) | null>(null); +} describe(XRatePrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXRateComponent, TestXRateHalfComponent, TestXRateDisabledComponent, TestXRateCustomComponent], - imports: [ - BrowserAnimationsModule, - FormsModule, - XRateComponent, - XButtonComponent, - XRowComponent, - XColComponent, - XIconComponent - ], + imports: [XTestRateComponent, XTestRatePropertyComponent], providers: [ + provideAnimations(), provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), provideExperimentalZonelessChangeDetection() ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let rate: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXRateComponent); + fixture = TestBed.createComponent(XTestRateComponent); fixture.detectChanges(); - rate = fixture.debugElement.query(By.directive(XRateComponent)); }); - it('should create.', () => { - expect(rate).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XRateComponent)); + expect(com).toBeDefined(); }); }); - describe(`half.`, () => { - let fixture: ComponentFixture; - let rate: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXRateHalfComponent); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestRatePropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestRatePropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - rate = fixture.debugElement.query(By.directive(XRateComponent)); }); - it('should create.', () => { - expect(rate).toBeDefined(); + it('count.', () => { + expect(true).toBe(true); }); - }); - describe(`custom.`, () => { - let fixture: ComponentFixture; - let rate: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXRateCustomComponent); - fixture.detectChanges(); - rate = fixture.debugElement.query(By.directive(XRateComponent)); + it('half.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(rate).toBeDefined(); + it('color.', () => { + expect(true).toBe(true); }); - }); - describe(`disabled.`, () => { - let fixture: ComponentFixture; - let rate: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXRateDisabledComponent); - fixture.detectChanges(); - rate = fixture.debugElement.query(By.directive(XRateComponent)); + it('customTemp.', () => { + expect(true).toBe(true); + }); + it('size.', () => { + expect(true).toBe(true); + }); + it('pointer.', () => { + expect(true).toBe(true); + }); + it('label.', () => { + expect(true).toBe(true); + }); + it('labelWidth.', () => { + expect(true).toBe(true); + }); + it('labelAlign.', () => { + expect(true).toBe(true); + }); + it('justify.', () => { + expect(true).toBe(true); + }); + it('align.', () => { + expect(true).toBe(true); + }); + it('direction.', () => { + expect(true).toBe(true); + }); + it('placeholder.', () => { + expect(true).toBe(true); + }); + it('disabled.', () => { + expect(true).toBe(true); + }); + it('required.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(rate).toBeDefined(); + it('readonly.', () => { + expect(true).toBe(true); + }); + it('valueTpl.', () => { + expect(true).toBe(true); + }); + it('valueTplContext.', () => { + expect(true).toBe(true); + }); + it('before.', () => { + expect(true).toBe(true); + }); + it('after.', () => { + expect(true).toBe(true); + }); + it('pattern.', () => { + expect(true).toBe(true); + }); + it('message.', () => { + expect(true).toBe(true); + }); + it('active.', () => { + expect(true).toBe(true); + }); + it('inputValidator.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - template: ` - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - x-row > x-col { - width: 14rem; - } - ` - ] -}) -class TestXRateComponent { - model = 3; -} - -@Component({ - template: ` - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - x-row > x-col { - width: 14rem; - } - ` - ] -}) -class TestXRateHalfComponent { - model = 3.5; - chang(event: number) { - console.log(event); - } -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - X - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - x-row > x-col { - width: 14rem; - } - ` - ] -}) -class TestXRateCustomComponent { - model = 3.5; - chang(event: number) { - console.log(event); - } -} - -@Component({ - template: ` - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - x-row > x-col { - width: 14rem; - } - ` - ] -}) -class TestXRateDisabledComponent { - model = 3; -} diff --git a/lib/ng-nest/ui/resizable/resizable.directive.spec.ts b/lib/ng-nest/ui/resizable/resizable.directive.spec.ts index 26c3d56bf..ad16846cf 100644 --- a/lib/ng-nest/ui/resizable/resizable.directive.spec.ts +++ b/lib/ng-nest/ui/resizable/resizable.directive.spec.ts @@ -1,14 +1,60 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { Component, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { XResizableDirective, XResizableEvent, XResizablePosition, XResizablePrefix } from '@ng-nest/ui/resizable'; import { provideHttpClientTesting } from '@angular/common/http/testing'; -import { TestBed } from '@angular/core/testing'; -import { XResizableDirective } from '@ng-nest/ui/resizable'; -import { XResizablePrefix } from './resizable.property'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; -import { provideExperimentalZonelessChangeDetection } from '@angular/core'; + +@Component({ + standalone: true, + imports: [XResizableDirective], + template: `
` +}) +class XTestResizableComponent {} + +@Component({ + standalone: true, + imports: [XResizableDirective], + template: ` +
+ ` +}) +class XTestResizablePropertyComponent { + resizable = signal(false); + position = signal('all'); + ghost = signal(false); + offsetLeft = signal('0'); + offsetTop = signal('0'); + + resizeBeginResult = signal(null); + resizeBegin(event: XResizableEvent) { + this.resizeBeginResult.set(event); + } + + resizingResult = signal(null); + resizing(event: XResizableEvent) { + this.resizingResult.set(event); + } + + resizeEndResult = signal(null); + resizeEnd(event: XResizableEvent) { + this.resizeEndResult.set(event); + } +} describe(XResizablePrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [XResizableDirective], + imports: [XTestResizableComponent, XTestResizablePropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -16,8 +62,47 @@ describe(XResizablePrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - it('should create.', () => { + describe('default.', () => { + let fixture: ComponentFixture; + beforeEach(() => { + fixture = TestBed.createComponent(XTestResizableComponent); + fixture.detectChanges(); + }); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XResizableDirective)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestResizablePropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestResizablePropertyComponent); + // component = fixture.componentInstance; + fixture.detectChanges(); + }); + it('resizable.', () => { + expect(true).toBe(true); + }); + it('position.', () => { + expect(true).toBe(true); + }); + it('ghost.', () => { + expect(true).toBe(true); + }); + it('offsetLeft.', () => { + expect(true).toBe(true); + }); + it('offsetTop.', () => { + expect(true).toBe(true); + }); + it('resizeBegin.', () => { + expect(true).toBe(true); + }); + it('resizing.', () => { + expect(true).toBe(true); + }); + it('resizeEnd.', () => { expect(true).toBe(true); }); }); diff --git a/lib/ng-nest/ui/result/result.component.spec.ts b/lib/ng-nest/ui/result/result.component.spec.ts index b3836037e..429aaedd7 100644 --- a/lib/ng-nest/ui/result/result.component.spec.ts +++ b/lib/ng-nest/ui/result/result.component.spec.ts @@ -1,34 +1,34 @@ -import { XIconComponent } from '@ng-nest/ui/icon'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { XResultComponent } from '@ng-nest/ui/result'; -import { FormsModule } from '@angular/forms'; -import { XResultPrefix } from './result.property'; -import { XButtonComponent, XButtonsComponent } from '@ng-nest/ui/button'; -import { XContainerComponent } from '@ng-nest/ui/container'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - +import { XResultComponent, XResultPrefix, XResultStatus } from '@ng-nest/ui/result'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XTemplate } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XResultComponent], + template: ` ` +}) +class XTestResultComponent {} + +@Component({ + standalone: true, + imports: [XResultComponent], + template: ` ` +}) +class XTestResultPropertyComponent { + status = signal('info'); + title = signal(null); + icon = signal(null); + subTitle = signal(null); +} describe(XResultPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXResultComponent], - imports: [ - BrowserAnimationsModule, - - FormsModule, - XResultComponent, - XButtonComponent, - XButtonsComponent, - XContainerComponent, - XRowComponent, - XColComponent, - XIconComponent - ], + imports: [XTestResultComponent, XTestResultPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -36,90 +36,36 @@ describe(XResultPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let result: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXResultComponent); + fixture = TestBed.createComponent(XTestResultComponent); fixture.detectChanges(); - result = fixture.debugElement.query(By.directive(XResultComponent)); }); - it('should create.', () => { - expect(result).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XResultComponent)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestResultPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestResultPropertyComponent); + // component = fixture.componentInstance; + fixture.detectChanges(); + }); + it('status.', () => { + expect(true).toBe(true); + }); + it('title.', () => { + expect(true).toBe(true); + }); + it('icon.', () => { + expect(true).toBe(true); + }); + it('subTitle.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - template: ` - -
- - - 返回列表 - 再次购买 - - -
-
- - 返回列表 - -
-
- - 返回列表 - -
-
- - 返回列表 - -
-
- - 返回列表 - -
-
- - 返回列表 - -
-
- - 返回列表 - -
-
- - 返回列表 - -
-
- - 返回列表 - - - - -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 2rem; - } - ` - ] -}) -class TestXResultComponent {} diff --git a/lib/ng-nest/ui/ripple/ripple.directive.spec.ts b/lib/ng-nest/ui/ripple/ripple.directive.spec.ts index bfc47b1aa..5704b8257 100644 --- a/lib/ng-nest/ui/ripple/ripple.directive.spec.ts +++ b/lib/ng-nest/ui/ripple/ripple.directive.spec.ts @@ -1,18 +1,32 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { XRippleDirective } from '@ng-nest/ui/ripple'; -import { Component, DebugElement, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XRipplePrefix } from './ripple.property'; -import { XButtonComponent } from '@ng-nest/ui/button'; +import { XRippleDirective, XRipplePrefix, XRippleType } from '@ng-nest/ui/ripple'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +@Component({ + standalone: true, + imports: [XRippleDirective], + template: `
` +}) +class XTestRippleComponent {} + +@Component({ + standalone: true, + imports: [XRippleDirective], + template: `
` +}) +class XTestRipplePropertyComponent { + type = signal('initial'); + duration = signal(500); + disabled = signal(false); +} + describe(XRipplePrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXRippleDirective], - imports: [XRippleDirective, XButtonComponent], + imports: [XTestRippleComponent, XTestRipplePropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -20,65 +34,33 @@ describe(XRipplePrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXRippleDirective); + fixture = TestBed.createComponent(XTestRippleComponent); + fixture.detectChanges(); + }); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XRippleDirective)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestRipplePropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestRipplePropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XRippleDirective)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('type.', () => { + expect(true).toBe(true); + }); + it('duration.', () => { + expect(true).toBe(true); + }); + it('disabled.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - selector: 'test-x-ripple', - template: ` -
- 默认按钮 - 主要按钮 - 成功按钮 - 警告按钮 - 危险按钮 - 信息按钮 -
-
- 朴素按钮 - 主要按钮 - 成功按钮 - 警告按钮 - 危险按钮 - 信息按钮 -
-
- 圆角按钮 - 主要按钮 - 成功按钮 - 警告按钮 - 危险按钮 - 信息按钮 -
-
- - - - - - -
- `, - styles: [ - ` - .row:not(:last-child) { - margin-bottom: 1rem; - } - .row > x-button:not(:first-child) { - margin-left: 1rem; - } - ` - ] -}) -class TestXRippleDirective {} diff --git a/lib/ng-nest/ui/select/select.component.spec.ts b/lib/ng-nest/ui/select/select.component.spec.ts index 18efec5c2..59d445111 100644 --- a/lib/ng-nest/ui/select/select.component.spec.ts +++ b/lib/ng-nest/ui/select/select.component.spec.ts @@ -1,42 +1,121 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, ChangeDetectorRef, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal, TemplateRef, viewChild } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XSelectComponent } from '@ng-nest/ui/select'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { XSelectPrefix, XSelectNode } from './select.property'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { Observable, interval } from 'rxjs'; -import { XData } from '@ng-nest/ui/core'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - -import { XRadioComponent } from '@ng-nest/ui/radio'; +import { XSelectComponent, XSelectNode, XSelectPrefix } from '@ng-nest/ui/select'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XAlign, XData, XDirection, XJustify, XPlacement, XSize, XTemplate } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XSelectComponent], + template: ` ` +}) +class XTestSelectComponent {} + +@Component({ + standalone: true, + imports: [XSelectComponent], + template: ` + + + +
{{ node.label }}
+
+ + before + after + ` +}) +class XTestSelectPropertyComponent { + data = signal>([]); + width = signal(''); + clearable = signal(true); + async = signal(false); + placement = signal('bottom'); + multiple = signal(false); + selectAll = signal(false); + selectAllText = signal(''); + nodeTpl = signal | null>(null); + nodeTemplate = viewChild>('nodeTemplate'); + bordered = signal(true); + portalMaxHeight = signal('12rem'); + portalWidth = signal(''); + search = signal(false); + caseSensitive = signal(true); + debounceTime = signal(200); + maxTagCount = signal(-1); + maxTagContent = signal(''); + virtualScroll = signal(false); + allowInput = signal(false); + size = signal('medium'); + pointer = signal(false); + label = signal(''); + labelWidth = signal(''); + labelAlign = signal('start'); + justify = signal('start'); + align = signal('start'); + direction = signal('column'); + placeholder = signal(''); + disabled = signal(false); + required = signal(false); + readonly = signal(false); + valueTpl = signal | null>(null); + valueTplContext = signal(null); + before = signal(null); + beforeTemplate = viewChild>('beforeTemplate'); + after = signal(null); + afterTemplate = viewChild>('afterTemplate'); + pattern = signal(null); + message = signal([]); + active = signal(false); + inputValidator = signal<((value: any) => boolean) | null>(null); +} describe(XSelectPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ - TestXSelectComponent, - TestXSelectAsyncComponent, - TestXSelectLabelComponent, - TestXSelectDisabledComponent, - TestXSelectRequiredComponent, - TestXSelectMultipleComponent, - TestXSelectCustomNodeComponent, - TestXSelectBorderedComponent, - TestXSelectSizeComponent - ], - imports: [ - BrowserAnimationsModule, - - XSelectComponent, - FormsModule, - ReactiveFormsModule, - XRowComponent, - XColComponent, - XRadioComponent - ], + imports: [XTestSelectComponent, XTestSelectPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -44,519 +123,141 @@ describe(XSelectPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXSelectComponent); + fixture = TestBed.createComponent(XTestSelectComponent); fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XSelectComponent)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XSelectComponent)); + expect(com).toBeDefined(); }); }); - describe(`async.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXSelectAsyncComponent); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestSelectPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestSelectPropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XSelectComponent)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('data.', () => { + expect(true).toBe(true); }); - }); - describe(`label.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXSelectLabelComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XSelectComponent)); + it('width.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('clearable.', () => { + expect(true).toBe(true); }); - }); - describe(`disabled.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXSelectDisabledComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XSelectComponent)); + it('async.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('placement.', () => { + expect(true).toBe(true); }); - }); - describe(`required.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXSelectRequiredComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XSelectComponent)); + it('multiple.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('selectAll.', () => { + expect(true).toBe(true); }); - }); - describe(`multiple.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXSelectMultipleComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XSelectComponent)); + it('selectAllText.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('nodeTpl.', () => { + expect(true).toBe(true); }); - }); - describe(`custom.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXSelectCustomNodeComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XSelectComponent)); + it('bordered.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('portalMaxHeight.', () => { + expect(true).toBe(true); }); - }); - describe(`size.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXSelectSizeComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XSelectComponent)); + it('portalWidth.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('search.', () => { + expect(true).toBe(true); }); - }); - describe(`bordered.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXSelectBorderedComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XSelectComponent)); + it('caseSensitive.', () => { + expect(true).toBe(true); + }); + it('debounceTime.', () => { + expect(true).toBe(true); + }); + it('maxTagCount.', () => { + expect(true).toBe(true); + }); + it('maxTagContent.', () => { + expect(true).toBe(true); + }); + it('virtualScroll.', () => { + expect(true).toBe(true); + }); + it('allowInput.', () => { + expect(true).toBe(true); + }); + it('size.', () => { + expect(true).toBe(true); + }); + it('pointer.', () => { + expect(true).toBe(true); + }); + it('label.', () => { + expect(true).toBe(true); + }); + it('labelWidth.', () => { + expect(true).toBe(true); + }); + it('labelAlign.', () => { + expect(true).toBe(true); + }); + it('justify.', () => { + expect(true).toBe(true); + }); + it('align.', () => { + expect(true).toBe(true); + }); + it('direction.', () => { + expect(true).toBe(true); + }); + it('placeholder.', () => { + expect(true).toBe(true); + }); + it('disabled.', () => { + expect(true).toBe(true); + }); + it('required.', () => { + expect(true).toBe(true); + }); + it('readonly.', () => { + expect(true).toBe(true); + }); + it('valueTpl.', () => { + expect(true).toBe(true); + }); + it('valueTplContext.', () => { + expect(true).toBe(true); + }); + it('before.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('after.', () => { + expect(true).toBe(true); + }); + it('pattern.', () => { + expect(true).toBe(true); + }); + it('message.', () => { + expect(true).toBe(true); + }); + it('active.', () => { + expect(true).toBe(true); + }); + it('inputValidator.', () => { + expect(true).toBe(true); }); }); }); - -const data: XData = [ - 'AAAA', - 'AAA', - 'BBBB', - 'CCCC', - 'DDDD', - 'EEEE', - 'FFFF', - 'GGGG', - 'HHHH', - 'IIII', - 'JJJJ' -]; - -@Component({ - template: ` - - - - - - - - - - - - `, - styles: [ - ` - :host { - height: 900px; - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSelectComponent { - data1 = data; - data2 = JSON.parse(JSON.stringify(data)); - model1: any; - model2: any = 'BBBB'; - constructor(public cdr: ChangeDetectorRef) { - interval(0).subscribe(() => this.cdr.detectChanges()); - } -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col { - width: 10rem; - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSelectLabelComponent { - data = data; - model: any; - constructor(public cdr: ChangeDetectorRef) {} -} - -@Component({ - template: ` - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col { - width: 10rem; - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSelectDisabledComponent { - data = data; - model = 'DDDD'; - constructor(public cdr: ChangeDetectorRef) {} -} - -@Component({ - template: ` - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col { - width: 10rem; - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSelectRequiredComponent { - data = data; - model1: any; - model2: any; -} - -@Component({ - template: ` - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col { - width: 10rem; - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSelectAsyncComponent { - model = 'QQ'; - data = new Observable((x) => { - // 替换成http请求,或者data直接定义成 Observable 对象 - setTimeout(() => { - this.model = '钉钉'; - x.next(['QQ', '微信', '钉钉', '微博']); - x.complete(); - }, 2000); - }); - constructor(private cdr: ChangeDetectorRef) {} - change() { - this.cdr.detectChanges(); - } -} - -@Component({ - template: ` - - - - - - - - - - `, - styles: [ - ` - :host { - height: 900px; - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSelectMultipleComponent { - data1 = data; - model1: any; - data2 = JSON.parse(JSON.stringify(data)); - model2 = [ - { id: 'AAAA', label: 'AAAA' }, - { id: 'BBBB', label: 'BBBB' } - ]; - constructor(public cdr: ChangeDetectorRef) { - interval(0).subscribe(() => this.cdr.detectChanges()); - } -} - -@Component({ - template: ` - - - - - - - {{ node?.label }}2 - - - - - - {{ node?.label }} 2 - - {{ item.label }} 2 - - - - `, - styles: [ - ` - :host { - height: 900px; - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - .select-item { - line-height: 1.25rem; - } - .select-item:not(:first-child):before { - content: ','; - } - ` - ] -}) -class TestXSelectCustomNodeComponent { - data1 = data; - model1: any; - data2 = JSON.parse(JSON.stringify(data)); - model2: any; - constructor(public cdr: ChangeDetectorRef) { - interval(0).subscribe(() => { - this.cdr.detectChanges(); - }); - } - - change(value: any) { - console.log(value); - } -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col > x-select { - width: 15rem; - display: block; - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSelectSizeComponent { - radioData = ['big', 'large', 'medium', 'small', 'mini']; - size = 'medium'; - data = data; - constructor(private cdr: ChangeDetectorRef) {} - change($event: string) { - console.log($event); - this.cdr.detectChanges(); - } -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col > x-select { - width: 15rem; - display: block; - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSelectBorderedComponent { - data = data; - constructor() {} -} diff --git a/lib/ng-nest/ui/skeleton/skeleton.component.spec.ts b/lib/ng-nest/ui/skeleton/skeleton.component.spec.ts index 63bf43680..35a11c0eb 100644 --- a/lib/ng-nest/ui/skeleton/skeleton.component.spec.ts +++ b/lib/ng-nest/ui/skeleton/skeleton.component.spec.ts @@ -1,45 +1,33 @@ -import { XIconComponent } from '@ng-nest/ui/icon'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { - Component, - DebugElement, - ChangeDetectorRef, - ViewEncapsulation, - provideExperimentalZonelessChangeDetection -} from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { XSkeletonComponent } from '@ng-nest/ui/skeleton'; -import { FormsModule } from '@angular/forms'; -import { XSkeletonPrefix, XSkeletonRow } from './skeleton.property'; -import { XButtonComponent } from '@ng-nest/ui/button'; -import { XContainerComponent } from '@ng-nest/ui/container'; -import { XSwitchComponent } from '@ng-nest/ui/switch'; -import { XAvatarComponent } from '@ng-nest/ui/avatar'; -import { XLinkComponent } from '@ng-nest/ui/link'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - +import { XSkeletonComponent, XSkeletonData, XSkeletonPrefix, XSkeletonRow } from '@ng-nest/ui/skeleton'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +@Component({ + standalone: true, + imports: [XSkeletonComponent], + template: ` ` +}) +class XTestSkeletonComponent {} + +@Component({ + standalone: true, + imports: [XSkeletonComponent], + template: ` ` +}) +class XTestSkeletonPropertyComponent { + data = signal(XSkeletonData); + loading = signal(true); + active = signal(false); + border = signal(false); +} + describe(XSkeletonPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXSkeletonComponent], - imports: [ - BrowserAnimationsModule, - - FormsModule, - XSkeletonComponent, - XSwitchComponent, - XButtonComponent, - XContainerComponent, - XRowComponent, - XColComponent, - XAvatarComponent, - XIconComponent, - XLinkComponent - ], + imports: [XTestSkeletonComponent, XTestSkeletonPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -47,197 +35,36 @@ describe(XSkeletonPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let skeleton: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXSkeletonComponent); + fixture = TestBed.createComponent(XTestSkeletonComponent); fixture.detectChanges(); - skeleton = fixture.debugElement.query(By.directive(XSkeletonComponent)); }); - it('should create.', () => { - expect(skeleton).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XSkeletonComponent)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestSkeletonPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestSkeletonPropertyComponent); + // component = fixture.componentInstance; + fixture.detectChanges(); + }); + it('data.', () => { + expect(true).toBe(true); + }); + it('loading.', () => { + expect(true).toBe(true); + }); + it('active.', () => { + expect(true).toBe(true); + }); + it('border.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - template: ` -
- -
- -
-
- -
-
- -
    -
  • - -

    生于忧患,死于安乐

    -

    - 舜发于畎亩之中,傅说举于版筑之间,胶鬲举于鱼盐之中,管夷吾举于士,孙叔敖举于海,百里奚举于市。故天将降大任于是人也,必先苦其心志,劳其筋骨,饿其体肤,空乏其身,行拂乱其所为,所以动心忍性,曾益其所不能。 -

    -
    -
  • -
-
-
- -
-
- -
    -
  • - - - - - - - - -

    生于忧患,死于安乐 {{ i + 1 }}

    -

    - 舜发于畎亩之中,傅说举于版筑之间,胶鬲举于鱼盐之中,管夷吾举于士,孙叔敖举于海,百里奚举于市。故天将降大任于是人也,必先苦其心志,劳其筋骨,饿其体肤,空乏其身,行拂乱其所为,所以动心忍性,曾益其所不能。 -

    -
    -
    - - - 18 - - - 50 - - - 100 - - - -
    2020-03-17 22:22
    -
    -
    -
    - - - -
    -
    -
  • -
-
-
- -
-
- `, - styles: [ - ` - .test-skeletion { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 2rem; - } - .row .news li { - padding-bottom: 1rem; - } - .row .news li:not(:first-child) { - padding-top: 1rem; - border-top: 0.0625rem solid var(--x-border-200); - } - .row .news h3 { - margin: 0; - } - .row .news p { - margin: 0.5rem 0; - } - .row .news .content { - display: flex; - flex-direction: column; - justify-content: space-between; - } - ` - ], - encapsulation: ViewEncapsulation.None -}) -class TestXSkeletonComponent { - dataCustom: XSkeletonRow[] = [ - { - flex: true, - space: '1rem', - cols: [ - { type: 'avatar', width: '3rem', height: '3rem' }, - { - rows: [ - { cols: [{ type: 'title', width: '10rem' }] }, - { cols: [{}] }, - { cols: [{}] }, - { cols: [{ span: 16 }] }, - { - space: '1rem', - flex: true, - cols: [ - { width: '3rem' }, - { width: '3rem' }, - { width: '3rem' }, - { type: 'transparent' }, - { width: '9rem' } - ] - } - ] - }, - { type: 'img', width: '10rem', height: '9rem' } - ] - } - ]; - dataTable: XSkeletonRow[] = [ - { - flex: true, - space: '1rem', - cols: [ - { type: 'title', width: '3rem' }, - { type: 'title', span: 4 }, - { type: 'title', span: 6 }, - { type: 'title', span: 4 }, - { type: 'title', span: 10 } - ] - }, - { - flex: true, - space: '1rem', - cols: [{ width: '3rem' }, { span: 4 }, { span: 6 }, { span: 4 }, { span: 10 }] - }, - { - flex: true, - space: '1rem', - cols: [{ width: '3rem' }, { span: 4 }, { span: 6 }, { span: 4 }, { span: 10 }] - }, - { - flex: true, - space: '1rem', - cols: [{ width: '3rem' }, { span: 4 }, { span: 6 }, { span: 4 }, { span: 10 }] - }, - { - flex: true, - space: '1rem', - cols: [{ width: '3rem' }, { span: 4 }, { span: 6 }, { span: 4 }, { span: 10 }] - } - ]; - loading = false; - loadingList = true; - list = new Array(3).fill({}); - constructor(private cdr: ChangeDetectorRef) {} - change() { - this.cdr.detectChanges(); - } -} diff --git a/lib/ng-nest/ui/slider-select/slider-select.component.spec.ts b/lib/ng-nest/ui/slider-select/slider-select.component.spec.ts index 03dd86658..b60547f2e 100644 --- a/lib/ng-nest/ui/slider-select/slider-select.component.spec.ts +++ b/lib/ng-nest/ui/slider-select/slider-select.component.spec.ts @@ -1,40 +1,113 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal, TemplateRef, viewChild } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XSliderSelectComponent } from '@ng-nest/ui/slider-select'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { XSliderSelectPrefix } from './slider-select.property'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { XTabsComponent, XTabComponent } from '@ng-nest/ui/tabs'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { XSliderSelectComponent, XSliderSelectMark, XSliderSelectPrefix } from '@ng-nest/ui/slider-select'; import { provideHttpClientTesting } from '@angular/common/http/testing'; -import { XIconComponent } from '@ng-nest/ui/icon'; -import { XButtonComponent } from '@ng-nest/ui/button'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XAlign, XDirection, XJustify, XTemplate } from '@ng-nest/ui/core'; +import { CdkDragEnd, CdkDragMove, CdkDragStart } from '@angular/cdk/drag-drop'; + +@Component({ + standalone: true, + imports: [XSliderSelectComponent], + template: ` ` +}) +class XTestSliderSelectComponent {} + +@Component({ + standalone: true, + imports: [XSliderSelectComponent], + template: ` + + + ` +}) +class XTestSliderSelectPropertyComponent { + min = signal(0); + max = signal(100); + step = signal(100); + precision = signal(null); + showTooltip = signal(true); + reverse = signal(false); + vertical = signal(false); + range = signal(false); + customButton = signal(null); + marks = signal([]); + tooltipCustom = signal(null); + pointer = signal(false); + label = signal(''); + labelWidth = signal(''); + labelAlign = signal('start'); + justify = signal('start'); + align = signal('start'); + direction = signal('column'); + placeholder = signal(''); + disabled = signal(false); + required = signal(false); + readonly = signal(false); + valueTpl = signal | null>(null); + valueTplContext = signal(null); + before = signal(null); + beforeTemplate = viewChild>('beforeTemplate'); + after = signal(null); + afterTemplate = viewChild>('afterTemplate'); + pattern = signal(null); + message = signal([]); + active = signal(false); + inputValidator = signal<((value: any) => boolean) | null>(null); + + dragStartEmitResult = signal(null); + dragStartEmit(start: CdkDragStart) { + this.dragStartEmitResult.set(start); + } + dragMoveEmitResult = signal(null); + dragMoveEmit(move: CdkDragMove) { + this.dragMoveEmitResult.set(move); + } + dragEndEmitResult = signal(null); + dragEndEmit(end: CdkDragEnd) { + this.dragEndEmitResult.set(end); + } +} describe(XSliderSelectPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ - TestXSliderSelectComponent, - TestXSliderSelectLabelComponent, - TestXSliderSelectLimitComponent, - TestXSliderSelectPrecisionComponent, - TestXSliderSelectDisabledComponent, - TestXSliderSelectTabsComponent - ], - imports: [ - BrowserAnimationsModule, - XSliderSelectComponent, - FormsModule, - ReactiveFormsModule, - XRowComponent, - XColComponent, - XTabsComponent, - XTabComponent, - XIconComponent, - XButtonComponent - ], + imports: [XTestSliderSelectComponent, XTestSliderSelectPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -42,288 +115,114 @@ describe(XSliderSelectPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXSliderSelectComponent); + fixture = TestBed.createComponent(XTestSliderSelectComponent); fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XSliderSelectComponent)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XSliderSelectComponent)); + expect(com).toBeDefined(); }); }); - describe(`label.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXSliderSelectLabelComponent); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestSliderSelectPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestSliderSelectPropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXSliderSelectLabelComponent)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('min.', () => { + expect(true).toBe(true); }); - }); - describe(`limit.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXSliderSelectLimitComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXSliderSelectLimitComponent)); + it('max.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('step.', () => { + expect(true).toBe(true); }); - }); - describe(`precision.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXSliderSelectPrecisionComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXSliderSelectPrecisionComponent)); + it('precision.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('showTooltip.', () => { + expect(true).toBe(true); }); - }); - describe(`disabled.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXSliderSelectDisabledComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXSliderSelectDisabledComponent)); + it('reverse.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('vertical.', () => { + expect(true).toBe(true); }); - }); - describe(`tabs.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXSliderSelectTabsComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXSliderSelectDisabledComponent)); + it('range.', () => { + expect(true).toBe(true); + }); + it('customButton.', () => { + expect(true).toBe(true); + }); + it('marks.', () => { + expect(true).toBe(true); + }); + it('tooltipCustom.', () => { + expect(true).toBe(true); + }); + it('pointer.', () => { + expect(true).toBe(true); + }); + it('label.', () => { + expect(true).toBe(true); + }); + it('labelWidth.', () => { + expect(true).toBe(true); + }); + it('labelAlign.', () => { + expect(true).toBe(true); + }); + it('justify.', () => { + expect(true).toBe(true); + }); + it('align.', () => { + expect(true).toBe(true); + }); + it('direction.', () => { + expect(true).toBe(true); + }); + it('placeholder.', () => { + expect(true).toBe(true); + }); + it('disabled.', () => { + expect(true).toBe(true); + }); + it('required.', () => { + expect(true).toBe(true); + }); + it('readonly.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('valueTpl.', () => { + expect(true).toBe(true); + }); + it('valueTplContext.', () => { + expect(true).toBe(true); + }); + it('before.', () => { + expect(true).toBe(true); + }); + it('after.', () => { + expect(true).toBe(true); + }); + it('pattern.', () => { + expect(true).toBe(true); + }); + it('message.', () => { + expect(true).toBe(true); + }); + it('active.', () => { + expect(true).toBe(true); + }); + it('inputValidator.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - template: ` - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSliderSelectComponent { - model = 60; -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSliderSelectLimitComponent { - model1 = 0; - model2 = 0; - model3 = 0; -} - -@Component({ - template: ` - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSliderSelectPrecisionComponent {} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSliderSelectLabelComponent { - model: number = 0; -} - -@Component({ - template: ` - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSliderSelectDisabledComponent { - model = 60; -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSliderSelectTabsComponent { - model1 = 0.3; - model2 = 0.44; -} diff --git a/lib/ng-nest/ui/slider/slider.component.spec.ts b/lib/ng-nest/ui/slider/slider.component.spec.ts index 993262f3b..fb83a43db 100644 --- a/lib/ng-nest/ui/slider/slider.component.spec.ts +++ b/lib/ng-nest/ui/slider/slider.component.spec.ts @@ -1,28 +1,75 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal, TemplateRef, viewChild } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XSliderComponent } from '@ng-nest/ui/slider'; -import { XSliderPrefix, XSliderNode } from './slider.property'; -import { XData } from '@ng-nest/ui/core'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { XIconComponent } from '@ng-nest/ui/icon'; -import { XTabsComponent, XTabComponent } from '@ng-nest/ui/tabs'; - +import { XSliderComponent, XSliderLayout, XSliderNode, XSliderPrefix, XSliderTrigger } from '@ng-nest/ui/slider'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XDataArray, XJustify, XSize } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XSliderComponent], + template: ` ` +}) +class XTestSliderComponent {} + +@Component({ + standalone: true, + imports: [XSliderComponent], + template: ` + + + + {{ node.label }} + ` +}) +class XTestSliderPropertyComponent { + data = signal>([]); + animated = signal(true); + activatedIndex = signal(0); + trigger = signal('click'); + layout = signal('row'); + justify = signal('start'); + nodeJustify = signal('center'); + nodeTpl = signal | null>(null); + nodeTemplate = viewChild>('nodeTemplate'); + size = signal('medium'); + showExpand = signal(false); + autoShowArrow = signal(true); + expandMaxHeight = signal('15rem'); + showAnchor = signal(false); + + indexChangeResult = signal(null); + indexChange(index: number) { + this.indexChangeResult.set(index); + } + + nodeChangeResult = signal(null); + nodeChange(node: XSliderNode) { + this.nodeChangeResult.set(node); + } +} describe(XSliderPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXSliderComponent], - imports: [ - XSliderComponent, - - BrowserAnimationsModule, - XIconComponent, - XTabsComponent, - XTabComponent - ], + imports: [XTestSliderComponent, XTestSliderPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -30,95 +77,69 @@ describe(XSliderPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let slider: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXSliderComponent); + fixture = TestBed.createComponent(XTestSliderComponent); fixture.detectChanges(); - slider = fixture.debugElement.query(By.directive(XSliderComponent)); }); - it('should create.', () => { - expect(slider).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XSliderComponent)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestSliderPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestSliderPropertyComponent); + // component = fixture.componentInstance; + fixture.detectChanges(); + }); + it('data.', () => { + expect(true).toBe(true); + }); + it('animated.', () => { + expect(true).toBe(true); + }); + it('activatedIndex.', () => { + expect(true).toBe(true); + }); + it('trigger.', () => { + expect(true).toBe(true); + }); + it('layout.', () => { + expect(true).toBe(true); + }); + it('justify.', () => { + expect(true).toBe(true); + }); + it('nodeJustify.', () => { + expect(true).toBe(true); + }); + it('nodeTpl.', () => { + expect(true).toBe(true); + }); + it('size.', () => { + expect(true).toBe(true); + }); + it('showExpand.', () => { + expect(true).toBe(true); + }); + it('autoShowArrow.', () => { + expect(true).toBe(true); + }); + it('expandMaxHeight.', () => { + expect(true).toBe(true); + }); + it('showAnchor.', () => { + expect(true).toBe(true); + }); + it('indexChange.', () => { + expect(true).toBe(true); + }); + it('nodeChange.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - template: ` - -
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- - -
- - {{ node.label }} -
-
-
-
- - - - - -
- - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 1rem; - } - .custom-node x-icon { - margin-right: 0.125rem; - } - ` - ] -}) -class TestXSliderComponent { - data: XData = ['用户管理', '配置管理', '角色管理', '任务', '工作', '消息', '流程', '新闻']; - dataCustom: XData = [ - { label: '用户管理', icon: 'fto-box' }, - { label: '配置管理', icon: 'fto-settings' }, - '角色管理', - '任务', - '工作', - '消息', - '流程', - '新闻' - ]; -} diff --git a/lib/ng-nest/ui/statistic/countdown.component.spec.ts b/lib/ng-nest/ui/statistic/countdown.component.spec.ts new file mode 100644 index 000000000..7f4959817 --- /dev/null +++ b/lib/ng-nest/ui/statistic/countdown.component.spec.ts @@ -0,0 +1,94 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { Component, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { XCountdownComponent, XCountdownPrefix } from '@ng-nest/ui/statistic'; +import { provideHttpClientTesting } from '@angular/common/http/testing'; +import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XStyle, XTemplate } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XCountdownComponent], + template: ` ` +}) +class XTestCountdownComponent {} + +@Component({ + standalone: true, + imports: [XCountdownComponent], + template: ` + + + ` +}) +class XTestCountdownPropertyComponent { + value = signal(null); + label = signal(null); + prefix = signal(null); + suffix = signal(null); + valueStyle = signal({}); + format = signal('HH:mm:ss'); + finish() {} +} + +describe(XCountdownPrefix, () => { + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [XTestCountdownComponent, XTestCountdownPropertyComponent], + providers: [ + provideHttpClient(withInterceptorsFromDi()), + provideHttpClientTesting(), + provideExperimentalZonelessChangeDetection() + ] + }).compileComponents(); + }); + describe('default.', () => { + let fixture: ComponentFixture; + beforeEach(() => { + fixture = TestBed.createComponent(XTestCountdownComponent); + fixture.detectChanges(); + }); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XCountdownComponent)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestCountdownPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestCountdownPropertyComponent); + // component = fixture.componentInstance; + fixture.detectChanges(); + }); + it('value.', () => { + expect(true).toBe(true); + }); + it('label.', () => { + expect(true).toBe(true); + }); + it('prefix.', () => { + expect(true).toBe(true); + }); + it('suffix.', () => { + expect(true).toBe(true); + }); + it('valueStyle.', () => { + expect(true).toBe(true); + }); + it('format.', () => { + expect(true).toBe(true); + }); + it('finish.', () => { + expect(true).toBe(true); + }); + }); +}); diff --git a/lib/ng-nest/ui/statistic/statistic.component.spec.ts b/lib/ng-nest/ui/statistic/statistic.component.spec.ts index 2fb572a3b..0e2ca4696 100644 --- a/lib/ng-nest/ui/statistic/statistic.component.spec.ts +++ b/lib/ng-nest/ui/statistic/statistic.component.spec.ts @@ -1,37 +1,44 @@ -import { XIconComponent } from '@ng-nest/ui/icon'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { XStatisticComponent, XCountdownComponent } from '@ng-nest/ui/statistic'; -import { FormsModule } from '@angular/forms'; -import { XStatisticPrefix } from './statistic.property'; -import { XButtonComponent } from '@ng-nest/ui/button'; -import { XContainerComponent } from '@ng-nest/ui/container'; -import { XCardComponent } from '@ng-nest/ui/card'; -import { XAddDays } from '@ng-nest/ui/core'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - +import { XStatisticComponent, XStatisticPrefix } from '@ng-nest/ui/statistic'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XStyle, XTemplate } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XStatisticComponent], + template: ` ` +}) +class XTestStatisticComponent {} + +@Component({ + standalone: true, + imports: [XStatisticComponent], + template: ` + + + ` +}) +class XTestStatisticPropertyComponent { + value = signal(null); + label = signal(null); + prefix = signal(null); + suffix = signal(null); + valueStyle = signal({}); +} describe(XStatisticPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXStatisticComponent], - imports: [ - BrowserAnimationsModule, - - FormsModule, - XStatisticComponent, - XCountdownComponent, - XButtonComponent, - XCardComponent, - XContainerComponent, - XRowComponent, - XColComponent, - XIconComponent - ], + imports: [XTestStatisticComponent, XTestStatisticPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -39,94 +46,39 @@ describe(XStatisticPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let statistic: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXStatisticComponent); + fixture = TestBed.createComponent(XTestStatisticComponent); + fixture.detectChanges(); + }); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XStatisticComponent)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestStatisticPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestStatisticPropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - statistic = fixture.debugElement.query(By.directive(XStatisticComponent)); }); - it('should create.', () => { - expect(statistic).toBeDefined(); + it('value.', () => { + expect(true).toBe(true); + }); + it('label.', () => { + expect(true).toBe(true); + }); + it('prefix.', () => { + expect(true).toBe(true); + }); + it('suffix.', () => { + expect(true).toBe(true); + }); + it('valueStyle.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - template: ` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - x-row x-col { - padding-top: 0.5rem; - padding-bottom: 0.5rem; - } - ` - ] -}) -class TestXStatisticComponent { - deadline = XAddDays(new Date(), 2).getTime(); -} diff --git a/lib/ng-nest/ui/steps/steps.component.spec.ts b/lib/ng-nest/ui/steps/steps.component.spec.ts index 3098b6144..439e70e4c 100644 --- a/lib/ng-nest/ui/steps/steps.component.spec.ts +++ b/lib/ng-nest/ui/steps/steps.component.spec.ts @@ -1,28 +1,48 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, ChangeDetectorRef, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal, TemplateRef } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XStepsComponent } from '@ng-nest/ui/steps'; -import { XStepsPrefix } from './steps.property'; -import { XButtonComponent, XButtonsComponent } from '@ng-nest/ui/button'; -import { XTabsComponent, XTabComponent } from '@ng-nest/ui/tabs'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - +import { XStepsComponent, XStepsLayout, XStepsNode, XStepsPrefix, XStepsStatus } from '@ng-nest/ui/steps'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XDataArray } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XStepsComponent], + template: ` ` +}) +class XTestStepsComponent {} + +@Component({ + standalone: true, + imports: [XStepsComponent], + template: ` + + + ` +}) +class XTestStepsPropertyComponent { + data = signal>([]); + layout = signal('row'); + activatedIndex = signal(0); + startIndex = signal(0); + status = signal(null); + customTpl = signal | null>(null); + nodeStatus = signal(false); +} describe(XStepsPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXStepsComponent, TestXStepsDotComponent], - imports: [ - BrowserAnimationsModule, - - XStepsComponent, - XButtonComponent, - XButtonsComponent, - XTabsComponent, - XTabComponent - ], + imports: [XTestStepsComponent, XTestStepsPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -30,213 +50,45 @@ describe(XStepsPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let steps: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXStepsComponent); - steps = fixture.debugElement.query(By.directive(XStepsComponent)); + fixture = TestBed.createComponent(XTestStepsComponent); fixture.detectChanges(); }); - it('should create.', () => { - expect(steps).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XStepsComponent)); + expect(com).toBeDefined(); }); }); - describe(`custom.`, () => { - let fixture: ComponentFixture; - let steps: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXStepsDotComponent); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestStepsPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestStepsPropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - steps = fixture.debugElement.query(By.directive(XStepsComponent)); }); - it('should create.', () => { - expect(steps).toBeDefined(); + it('data.', () => { + expect(true).toBe(true); + }); + it('layout.', () => { + expect(true).toBe(true); + }); + it('activatedIndex.', () => { + expect(true).toBe(true); + }); + it('startIndex.', () => { + expect(true).toBe(true); + }); + it('status.', () => { + expect(true).toBe(true); + }); + it('customTpl.', () => { + expect(true).toBe(true); + }); + it('nodeStatus.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - template: ` -
- -
-
- 下一步 -
-
- -
-
- -
-
- -
- -
- -
-
- -
内容1
-
内容2
-
内容3
-
-
-
- - 上一步 - 下一步 - 提交 - -
-
- -
-
- -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row { - margin-top: 2rem; - } - .row:not(:first-child) { - margin-top: 1rem; - } - .custom-steps-content { - height: 10rem; - border: 0.0625rem solid var(--x-border); - border-radius: 0.125rem; - line-height: 10rem; - text-align: center; - } - ` - ] -}) -class TestXStepsComponent { - activatedIndex = 0; - data = ['步骤 1', '步骤 2', '步骤 3']; - dataDefault = [ - { label: '完成', description: '这是描述内容。' }, - { label: '进行中', description: '这是描述内容。' }, - { label: '等待', description: '这是描述内容。' } - ]; - dataIcon = [ - { label: '登录', icon: 'fto-user' }, - { label: '验证', icon: 'fto-user-check' }, - { label: '付款', icon: 'fto-credit-card' }, - { label: '完成', icon: 'fto-smile' } - ]; - activatedTab = 0; - dataError = ['完成', '执行错误', '等待']; - - constructor(private cdr: ChangeDetectorRef) {} - - next() { - this.activatedIndex++; - if (this.activatedIndex > this.data.length - 1) this.activatedIndex = 0; - this.cdr.detectChanges(); - } - - preTab() { - this.activatedTab -= 1; - this.cdr.detectChanges(); - } - - nextTab() { - this.activatedTab += 1; - this.cdr.detectChanges(); - } - - doneTab() { - console.log('提交'); - } -} - -@Component({ - template: ` -
- -
- - - - - - - -
-
-
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row { - margin-top: 2rem; - } - .row:not(:first-child) { - margin-top: 1rem; - } - .custom-class { - width: 0.5rem; - height: 0.5rem; - border-radius: 0.5rem; - margin-top: 0.75rem; - background-color: var(--x-primary); - } - .custom-class.wait { - background-color: var(--x-background-a900); - } - .custom-loading-circular { - animation: loading-rotate 2s linear infinite; - height: 1.75rem; - width: 1.75rem; - } - .custom-loading-path { - animation: loading-dash 1.5s ease-in-out infinite; - stroke-dasharray: 90, 150; - stroke-dashoffset: 0; - stroke-width: 2; - stroke: var(--x-primary); - stroke-linecap: round; - } - @keyframes loading-rotate { - 100% { - transform: rotate(360deg); - } - } - - @keyframes loading-dash { - 0% { - stroke-dasharray: 1, 200; - stroke-dashoffset: 0; - } - 50% { - stroke-dasharray: 90, 150; - stroke-dashoffset: -2.5rem; - } - 100% { - stroke-dasharray: 90, 150; - stroke-dashoffset: -7.5rem; - } - } - ` - ] -}) -class TestXStepsDotComponent { - data = ['步骤 1', '步骤 2', '步骤 3']; - activatedIndex = 1; -} diff --git a/lib/ng-nest/ui/switch/switch.component.spec.ts b/lib/ng-nest/ui/switch/switch.component.spec.ts index c6f963219..3c0466423 100644 --- a/lib/ng-nest/ui/switch/switch.component.spec.ts +++ b/lib/ng-nest/ui/switch/switch.component.spec.ts @@ -1,34 +1,86 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, ChangeDetectorRef, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal, TemplateRef, viewChild } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XSwitchComponent } from '@ng-nest/ui/switch'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { XSwitchPrefix } from './switch.property'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - +import { XSwitchComponent, XSwitchPrefix } from '@ng-nest/ui/switch'; import { provideHttpClientTesting } from '@angular/common/http/testing'; -import { XRadioComponent } from '@ng-nest/ui/radio'; -import { XInputComponent } from '@ng-nest/ui/input'; -import { XIconComponent } from '@ng-nest/ui/icon'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XAlign, XDirection, XJustify, XSize, XTemplate } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XSwitchComponent], + template: ` ` +}) +class XTestSwitchComponent {} + +@Component({ + standalone: true, + imports: [XSwitchComponent], + template: ` + + + before + after + ` +}) +class XTestSwitchPropertyComponent { + loading = signal(false); + manual = signal(false); + checkedText = signal(null); + unCheckedText = signal(null); + size = signal('medium'); + pointer = signal(false); + label = signal(''); + labelWidth = signal(''); + labelAlign = signal('start'); + justify = signal('start'); + align = signal('start'); + direction = signal('column'); + placeholder = signal(''); + disabled = signal(false); + required = signal(false); + readonly = signal(false); + valueTpl = signal | null>(null); + valueTplContext = signal(null); + before = signal(null); + beforeTemplate = viewChild>('beforeTemplate'); + after = signal(null); + afterTemplate = viewChild>('afterTemplate'); + pattern = signal(null); + message = signal([]); + active = signal(false); + inputValidator = signal<((value: any) => boolean) | null>(null); +} describe(XSwitchPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXSwitchComponent, TestXSwitchLabelComponent, TestXSwitchDisabledComponent], - imports: [ - BrowserAnimationsModule, - - XSwitchComponent, - FormsModule, - ReactiveFormsModule, - XRowComponent, - XColComponent, - XRadioComponent, - XInputComponent, - XIconComponent - ], + imports: [XTestSwitchComponent, XTestSwitchPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -36,149 +88,96 @@ describe(XSwitchPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXSwitchComponent); + fixture = TestBed.createComponent(XTestSwitchComponent); fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XSwitchComponent)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XSwitchComponent)); + expect(com).toBeDefined(); }); }); - describe(`label.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXSwitchLabelComponent); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestSwitchPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestSwitchPropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXSwitchLabelComponent)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('loading.', () => { + expect(true).toBe(true); }); - }); - describe(`disabled.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXSwitchDisabledComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXSwitchDisabledComponent)); + it('manual.', () => { + expect(true).toBe(true); + }); + it('checkedText.', () => { + expect(true).toBe(true); + }); + it('unCheckedText.', () => { + expect(true).toBe(true); + }); + it('size.', () => { + expect(true).toBe(true); + }); + it('pointer.', () => { + expect(true).toBe(true); + }); + it('label.', () => { + expect(true).toBe(true); + }); + it('labelWidth.', () => { + expect(true).toBe(true); + }); + it('labelAlign.', () => { + expect(true).toBe(true); + }); + it('justify.', () => { + expect(true).toBe(true); + }); + it('align.', () => { + expect(true).toBe(true); + }); + it('direction.', () => { + expect(true).toBe(true); + }); + it('placeholder.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('disabled.', () => { + expect(true).toBe(true); + }); + it('required.', () => { + expect(true).toBe(true); + }); + it('readonly.', () => { + expect(true).toBe(true); + }); + it('valueTpl.', () => { + expect(true).toBe(true); + }); + it('valueTplContext.', () => { + expect(true).toBe(true); + }); + it('before.', () => { + expect(true).toBe(true); + }); + it('after.', () => { + expect(true).toBe(true); + }); + it('pattern.', () => { + expect(true).toBe(true); + }); + it('message.', () => { + expect(true).toBe(true); + }); + it('active.', () => { + expect(true).toBe(true); + }); + it('inputValidator.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - template: ` - - - - - - - - - - - - `, - styles: [ - ` - :host { - height: 900px; - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSwitchComponent { - model1!: boolean; - model2 = true; - constructor(private cdr: ChangeDetectorRef) {} - change() { - this.cdr.detectChanges(); - } -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSwitchLabelComponent { - constructor() {} -} - -@Component({ - template: ` - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXSwitchDisabledComponent { - model = true; -} diff --git a/lib/ng-nest/ui/table/table.component.html b/lib/ng-nest/ui/table/table.component.html index 95af44213..2c78856a5 100644 --- a/lib/ng-nest/ui/table/table.component.html +++ b/lib/ng-nest/ui/table/table.component.html @@ -130,6 +130,9 @@ [totalTpl]="totalTpl()" [simple]="simple()" [simpleIndexWidth]="simpleIndexWidth()" + [jumpTooltipText]="jumpTooltipText()" + [inputSizeTooltipText]="inputSizeTooltipText()" + [inputIndexSizeSureType]="inputIndexSizeSureType()" > } diff --git a/lib/ng-nest/ui/table/table.component.spec.ts b/lib/ng-nest/ui/table/table.component.spec.ts index dff2fd053..37decac58 100644 --- a/lib/ng-nest/ui/table/table.component.spec.ts +++ b/lib/ng-nest/ui/table/table.component.spec.ts @@ -1,71 +1,163 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { - Component, - DebugElement, - Injectable, - ChangeDetectorRef, - provideExperimentalZonelessChangeDetection -} from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XTableComponent } from '@ng-nest/ui/table'; -import { FormsModule } from '@angular/forms'; -import { XTablePrefix, XTableColumn, XTableCellConfig } from './table.property'; import { - XRepositoryAbstract, - XQuery, - XResultList, - XGroupItem, - XFilter, - XChunk, - XGroupBy, - XSort, - XId, - XOrderBy -} from '@ng-nest/ui/core'; -import { Observable, interval } from 'rxjs'; -import { map as rxjsMap, delay } from 'rxjs/operators'; -import { XIconComponent } from '@ng-nest/ui/icon'; -import { XAvatarComponent } from '@ng-nest/ui/avatar'; -import { XButtonComponent } from '@ng-nest/ui/button'; -import { XInputComponent } from '@ng-nest/ui/input'; -import { XSelectComponent } from '@ng-nest/ui/select'; -import { XSwitchComponent } from '@ng-nest/ui/switch'; -import { XLinkComponent } from '@ng-nest/ui/link'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { XDescriptionModule } from '@ng-nest/ui/description'; + XPaginationPosition, + XTableCellConfig, + XTableColumn, + XTableComponent, + XTableDragWidthEvent, + XTableHeadCheckbox, + XTableHeaderPosition, + XTablePrefix, + XTableRow, + XTableTemplate +} from '@ng-nest/ui/table'; import { provideHttpClientTesting } from '@angular/common/http/testing'; -import { XDialogComponent } from '@ng-nest/ui/dialog'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XData, XDataArray, XQuery, XSize, XSort, XTemplate } from '@ng-nest/ui/core'; +import { XPaginationInputIndexSizeSureType, XPaginationSizeData } from '@ng-nest/ui/pagination'; +import { XSelectNode } from '@ng-nest/ui/select'; + +@Component({ + standalone: true, + imports: [XTableComponent], + template: ` ` +}) +class XTestTableComponent {} + +@Component({ + standalone: true, + imports: [XTableComponent], + template: ` + + + ` +}) +class XTestTablePropertyComponent { + data = signal>([]); + columns = signal([]); + rowHeight = signal(42); + loading = signal(false); + bordered = signal(false); + showHeader = signal(true); + headerPosition = signal('top'); + activatedRow = signal(null); + headColumnTpl = signal({}); + headThTpl = signal(null); + bodyColumnTpl = signal({}); + bodyTdTpl = signal(null); + rowClass = signal<((row: XTableRow, index: number) => { [className: string]: boolean }) | null>(null); + headSearchTpl = signal(null); + + sortChangeResult = signal(null); + sortChange(sort: XSort[]) { + this.sortChangeResult.set(sort); + } + + headCheckboxChangeResult = signal(null); + headCheckboxChange(headCheckbox: XTableHeadCheckbox) { + this.headCheckboxChangeResult.set(headCheckbox); + } + + bodyCheckboxChangeResult = signal(null); + bodyCheckboxChange(row: XTableRow) { + this.bodyCheckboxChangeResult.set(row); + } + + allowSelectRow = signal(true); + allowCheckRow = signal(true); + virtualScroll = signal(false); + bodyHeight = signal(null); + itemSize = signal(42); + minBufferPx = signal(100); + maxBufferPx = signal(200); + adaptionHeight = signal(null); + docPercent = signal(1); + checkedRow = signal<{ [property: string]: any[] }>({}); + manual = signal(true); + scroll = signal<{ x: number; y: number } | null>(null); + header = signal(null); + footer = signal(null); + cellConfig = signal(null); + rowSize = signal('medium'); + paginationPosition = signal('bottom-left'); + hiddenWrapBorder = signal(false); + hiddenPaginationBorder = signal(false); + showPagination = signal(true); + treeTable = signal(true); + expandedAll = signal(false); + expandedLevel = signal(-1); + expanded = signal([]); + expandTpl = signal(null); + showEmpty = signal(true); + emptyImg = signal(null); + emptyContent = signal(null); + index = signal(1); + size = signal(10); + total = signal(0); + query = signal({}); + pageLinkSize = signal(5); + showEllipsis = signal(true); + showTotal = signal(true); + space = signal('0.25rem'); + showBackground = signal(false); + showSize = signal(false); + sizeWidth = signal('6.875rem'); + showInputSize = signal(false); + inputSizeTooltipText = signal(''); + inputSizeWidth = signal('3.125rem'); + sizeData = signal>(XPaginationSizeData); + disabled = signal(false); + showJump = signal(false); + jumpTooltipText = signal(''); + jumpWidth = signal('3.125rem'); + totalTpl = signal(null); + simple = signal(false); + simpleIndexWidth = signal('8.125rem'); + inputIndexSizeSureType = signal('enter'); + + columnDragStartedResult = signal(null); + columnDragStarted(column: XTableColumn) { + this.columnDragStartedResult.set(column); + } + + columnDragEndedResult = signal(null); + columnDragEnded(column: XTableColumn) { + this.columnDragEndedResult.set(column); + } + + columnDropListDroppedResult = signal(null); + columnDropListDropped(columns: XTableColumn[]) { + this.columnDropListDroppedResult.set(columns); + } + + columnDragWidthStartedResult = signal(null); + columnDragWidthStarted(event: XTableDragWidthEvent) { + this.columnDragWidthStartedResult.set(event); + } + + columnDragWidthMovedResult = signal(null); + columnDragWidthMoved(event: XTableDragWidthEvent) { + this.columnDragWidthMovedResult.set(event); + } + columnDragWidthEndedResult = signal(null); + columnDragWidthEnded(event: XTableDragWidthEvent) { + this.columnDragWidthEndedResult.set(event); + } +} describe(XTablePrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ - TestXTableComponent, - TestXTableScrollComponent, - TestXTableAdaptionComponent, - TestXTableBorderedComponent, - TestXTableFunctionComponent, - TestXTableMergeColumnComponent, - TestXTableWidthDragComponent, - TestXTableCheckboxComponent, - TestXTableRowSizeComponent, - TestXTablePaginationComponent - ], - imports: [ - BrowserAnimationsModule, - FormsModule, - XDescriptionModule, - XTableComponent, - XIconComponent, - XAvatarComponent, - XButtonComponent, - XLinkComponent, - XInputComponent, - XSelectComponent, - XSwitchComponent, - XDialogComponent - ], + imports: [XTestTableComponent, XTestTablePropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -73,797 +165,30 @@ describe(XTablePrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let table: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTableComponent); - fixture.detectChanges(); - table = fixture.debugElement.query(By.directive(XTableComponent)); - }); - it('should create.', () => { - expect(table).toBeDefined(); - }); - }); - describe(`scroll.`, () => { - let fixture: ComponentFixture; - let table: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTableScrollComponent); - fixture.detectChanges(); - table = fixture.debugElement.query(By.directive(XTableComponent)); - }); - it('should create.', () => { - expect(table).toBeDefined(); - }); - }); - describe(`adaption.`, () => { - let fixture: ComponentFixture; - let table: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXTableAdaptionComponent); + fixture = TestBed.createComponent(XTestTableComponent); fixture.detectChanges(); - table = fixture.debugElement.query(By.directive(XTableComponent)); }); - it('should create.', () => { - expect(table).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XTableComponent)); + expect(com).toBeDefined(); }); }); - describe(`bordered.`, () => { - let fixture: ComponentFixture; - let table: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTableBorderedComponent); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestTablePropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestTablePropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - table = fixture.debugElement.query(By.directive(XTableComponent)); - }); - it('should create.', () => { - expect(table).toBeDefined(); }); - }); - describe(`column width drag.`, () => { - let fixture: ComponentFixture; - let table: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTableWidthDragComponent); - fixture.detectChanges(); - table = fixture.debugElement.query(By.directive(XTableComponent)); - }); - it('should create.', () => { - expect(table).toBeDefined(); - }); - }); - describe(`observable.`, () => { - let fixture: ComponentFixture; - let table: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTableFunctionComponent); - fixture.detectChanges(); - table = fixture.debugElement.query(By.directive(XTableComponent)); - }); - it('should create.', () => { - expect(table).toBeDefined(); - }); - }); - describe(`merge column.`, () => { - let fixture: ComponentFixture; - let table: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTableMergeColumnComponent); - fixture.detectChanges(); - table = fixture.debugElement.query(By.directive(XTableComponent)); - }); - it('should create.', () => { - expect(table).toBeDefined(); - }); - }); - describe(`checkbox.`, () => { - let fixture: ComponentFixture; - let table: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTableCheckboxComponent); - fixture.detectChanges(); - table = fixture.debugElement.query(By.directive(XTableComponent)); + it('top.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(table).toBeDefined(); - }); - }); - describe(`row size.`, () => { - let fixture: ComponentFixture; - let table: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTableRowSizeComponent); - fixture.detectChanges(); - table = fixture.debugElement.query(By.directive(XTableComponent)); - }); - it('should create.', () => { - expect(table).toBeDefined(); - }); - }); - describe(`pagination.`, () => { - let fixture: ComponentFixture; - let table: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTablePaginationComponent); - fixture.detectChanges(); - table = fixture.debugElement.query(By.directive(XTableComponent)); - }); - it('should create.', () => { - expect(table).toBeDefined(); + it('left.', () => { + expect(true).toBe(true); }); }); }); - -@Injectable() -class UsersServiceTest extends XRepositoryAbstract { - organizations = ['制造中心', '研发中心', '财务中心', '营销中心', '行政中心']; - positions = ['技术员', '销售', '经理', '总监', '生产员']; - users: User[] = Array.from({ length: 10000 }).map((_x, i) => { - i++; - return { - id: i, - name: '姓名' + i, - position: this.positions[Math.floor(Math.random() * 10 + 1) % 5], - email: '邮箱' + i, - phone: '手机' + i, - organization: this.organizations[Math.floor(Math.random() * 10 + 1) % 5] - }; - }); - - getList(index: number, size: number, query?: XQuery): Observable> { - return new Observable((x) => { - let data: User[] | XGroupItem[] = []; - data = this.setFilter(this.users, query?.filter as XFilter[]); - if (query?.group) { - data = this.setGroup(data, query.group); - } - if (query?.sort) { - data = this.setSort(data, query.sort); - } - let chunks = XChunk(data, size); - if ((index as number) <= chunks.length) { - x.next({ total: data.length, list: chunks[index - 1] }); - } else { - x.next({ total: data.length, list: [] }); - } - x.complete(); - }); - } - get(_id: number | string): Observable { - return new Observable(); - } - post(_entity: User): Observable { - return new Observable(); - } - put(_entity: User): Observable { - return new Observable(); - } - delete(_id: number | string): Observable { - return new Observable(); - } - - private setFilter(data: User[], filters: XFilter[]): User[] { - let result = data; - if (filters && filters.length > 0) { - filters.forEach((x) => { - result = result.filter((y) => y[x.field!].indexOf(x.value) >= 0); - }); - } - return result; - } - - private setGroup(data: User[], group: string): XGroupItem[] { - return XGroupBy(data, group).map((value, key) => { - let groupItem: XGroupItem = { id: key, count: value.length }; - groupItem[group] = key; - return groupItem; - }); - } - - private setSort(data: User[] | XGroupItem[], sort: XSort[]): User[] | XGroupItem[] { - return XOrderBy( - data, - sort.map((x) => x.field!), - sort.map((x) => x.value) as ('desc' | 'asc')[] - ) as User[] | XGroupItem[]; - } -} - -interface User extends XId { - name?: string; - account?: string; - password?: string; - email?: string; - phone?: string; - organization?: string; - [property: string]: any; -} - -@Component({ - template: ` -
- -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row { - padding: 1rem; - } - .row:not(:first-child) { - margin-top: 1rem; - } - ` - ], - providers: [UsersServiceTest] -}) -class TestXTableComponent { - data = (index: number, size: number, query: XQuery) => this.service.getList(index, size, query).pipe(delay(2000)); - columns: XTableColumn[] = [ - { id: 'index', label: '序号', type: 'index' }, - { id: 'name', label: '用户', sort: true }, - { id: 'position', label: '职位', sort: true }, - { id: 'email', label: '邮箱' }, - { id: 'phone', label: '电话' }, - { id: 'organization', label: '组织机构', sort: true } - ]; - - constructor(private service: UsersServiceTest) {} - - ngOnInit() {} -} - -@Component({ - template: ` -
- - -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row { - padding: 1rem; - } - .row:not(:first-child) { - margin-top: 1rem; - } - ` - ], - providers: [UsersServiceTest] -}) -class TestXTableScrollComponent { - data = (index: number, size: number, query: XQuery) => this.service.getList(index, size, query).pipe(delay(2000)); - columns: XTableColumn[] = [ - { id: 'index', label: '序号', width: 100, left: 0, type: 'index' }, - { id: 'name', label: '用户', width: 200, sort: true }, - { id: 'position', label: '职位', width: 300, sort: true }, - { id: 'email', label: '邮箱', width: 300 }, - { id: 'phone', label: '电话', width: 300 }, - { id: 'organization', label: '组织机构', flex: 1, sort: true } - ]; - - constructor(private service: UsersServiceTest) {} - - ngOnInit() {} -} - -@Component({ - template: ` -
- - -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row { - padding: 1rem; - } - .row:not(:first-child) { - margin-top: 1rem; - } - ` - ], - providers: [UsersServiceTest] -}) -class TestXTableBorderedComponent { - data = (index: number, size: number, query: XQuery) => this.service.getList(index, size, query).pipe(delay(2000)); - columns: XTableColumn[] = [ - { id: 'index', label: '序号', width: 100, left: 0, type: 'index' }, - { id: 'name', label: '用户', width: 200, sort: true }, - { id: 'position', label: '职位', width: 300, sort: true }, - { id: 'email', label: '邮箱', width: 300 }, - { id: 'phone', label: '电话', width: 300 }, - { id: 'organization', label: '组织机构', flex: 1, sort: true } - ]; - - constructor(private service: UsersServiceTest) {} - - ngOnInit() {} -} - -@Component({ - template: ` -
- - -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row { - padding: 1rem; - } - .row:not(:first-child) { - margin-top: 1rem; - } - ` - ], - providers: [UsersServiceTest] -}) -class TestXTableWidthDragComponent { - data = (index: number, size: number, query: XQuery) => this.service.getList(index, size, query).pipe(delay(2000)); - columns: XTableColumn[] = [ - { id: 'index', label: '序号', width: 100, left: 0, type: 'index' }, - { id: 'name', label: '用户', width: 150, sort: true, dragWidth: true }, - { id: 'position', label: '职位', width: 150, sort: true, dragWidth: true }, - { id: 'email', label: '邮箱', width: 200, dragWidth: true }, - { id: 'phone', label: '电话', width: 200, dragWidth: true }, - { id: 'organization', label: '组织机构', flex: 1, sort: true } - ]; - - constructor( - private service: UsersServiceTest, - private cdr: ChangeDetectorRef - ) {} - - ngOnInit() {} - - ngAfterViewInit() { - interval(10).subscribe(() => this.cdr.detectChanges()); - } -} - -@Component({ - template: ` - 弹框表格自适应 - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row { - padding: 1rem; - } - .row:not(:first-child) { - margin-top: 1rem; - } - ` - ], - providers: [UsersServiceTest] -}) -class TestXTableAdaptionComponent { - query: XQuery = {}; - index = 1; - size = 1000; - total = 0; - data: User[] = []; - columns: XTableColumn[] = [ - { id: 'index', label: '序号', width: 100, left: 0, type: 'index' }, - { id: 'name', label: '用户', width: 200, sort: true }, - { id: 'position', label: '职位', width: 300, sort: true }, - { id: 'email', label: '邮箱', width: 300 }, - { id: 'phone', label: '电话', width: 300 }, - { id: 'organization', label: '组织机构', flex: 1, sort: true } - ]; - - visible = false; - - constructor( - private service: UsersServiceTest, - private cdr: ChangeDetectorRef - ) {} - - ngOnInit() {} - - ngAfterViewInit() { - interval(10).subscribe(() => this.cdr.detectChanges()); - } - - getData() { - this.service.getList(this.index, this.size, this.query).subscribe((x) => { - [this.data, this.total] = [x.list as User[], Number(x.total)]; - this.cdr.detectChanges(); - }); - } - - indexChange(index: number) { - this.index = index; - this.getData(); - } - - sortChange(sort: XSort[]) { - this.query.sort = sort; - this.getData(); - } - - dialog() { - this.getData(); - this.visible = true; - this.cdr.detectChanges(); - } - - close() { - this.visible = false; - this.cdr.detectChanges(); - } -} - -@Component({ - template: ` -
- -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row { - padding: 1rem; - } - .row:not(:first-child) { - margin-top: 1rem; - } - ` - ], - providers: [UsersServiceTest] -}) -class TestXTableFunctionComponent { - data = (index: number, size: number, query: XQuery) => - this.service.getList(index, size, query).pipe( - rxjsMap((x) => { - console.log(x); - return x; - }) - ); - - columns: XTableColumn[] = [ - { id: 'index', label: '序号', flex: 0.5, left: 0, type: 'index' }, - { id: 'name', label: '用户', flex: 1.5, sort: true }, - { id: 'position', label: '职位', flex: 0.5, sort: true }, - { id: 'email', label: '邮箱', flex: 1 }, - { id: 'phone', label: '电话', flex: 1 }, - { id: 'organization', label: '组织机构', flex: 1, sort: true } - ]; - - constructor( - private service: UsersServiceTest, - private cdr: ChangeDetectorRef - ) {} - - ngAfterViewInit() { - interval(10).subscribe(() => this.cdr.detectChanges()); - } -} - -@Component({ - template: ` -
- -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row { - padding: 1rem; - } - .row:not(:first-child) { - margin-top: 1rem; - } - ` - ], - providers: [UsersServiceTest] -}) -class TestXTableMergeColumnComponent { - data = (index: number, size: number, query: XQuery) => - this.service.getList(index, size, query).pipe( - rxjsMap((x) => { - console.log(x); - return x; - }) - ); - - columns: XTableColumn[] = [ - { id: 'index', label: '序号', flex: 0.5, left: 0, type: 'index' }, - { id: 'name', label: '用户', flex: 1.5, sort: true }, - { id: 'position', label: '职位', flex: 1, sort: true }, - { id: 'email', label: '邮箱', flex: 1 }, - { id: 'phone', label: '电话', flex: 1 }, - { id: 'organization', label: '组织机构', flex: 1, sort: true } - ]; - - cellConfig: XTableCellConfig = { - thead: { - cells: [ - { gridArea: '1 / 1 / 3 / 2', id: 'index' }, - { gridArea: '1 / 2 / 2 / 5', label: '详细信息' }, - { gridArea: '2 / 2 / 3 / 3', id: 'name' }, - { gridArea: '2 / 3 / 3 / 4', id: 'position' }, - { gridArea: '2 / 4 / 3 / 5', id: 'email' }, - { gridArea: '1 / 5 / 3 / 6', id: 'phone' }, - { gridArea: '1 / 6 / 3 / 7', id: 'organization' } - ] - }, - tbody: { - cells: [ - { gridArea: '1 / 1', id: 'index' }, - { gridArea: '1 / 2', id: 'name' }, - { gridArea: '1 / 3', id: 'position' }, - { gridArea: '1 / 4', id: 'email' }, - { gridArea: '1 / 5', id: 'phone' }, - { gridArea: '1 / 6', id: 'organization' } - ] - } - }; - - constructor( - private service: UsersServiceTest, - private cdr: ChangeDetectorRef - ) {} - - ngAfterViewInit() { - interval(10).subscribe(() => this.cdr.detectChanges()); - } -} - -@Component({ - template: ` -
- -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row { - padding: 1rem; - } - .row:not(:first-child) { - margin-top: 1rem; - } - ` - ], - providers: [UsersServiceTest] -}) -class TestXTableCheckboxComponent { - data = (index: number, size: number, query: XQuery) => this.service.getList(index, size, query).pipe(delay(1000)); - columns: XTableColumn[] = [ - { id: 'checked', label: '', rowChecked: true, headChecked: true, type: 'checkbox', width: 60 }, - { id: 'index', label: '序号', flex: 0.5, type: 'index' }, - { id: 'name', label: '用户', flex: 1.5, sort: true }, - { id: 'position', label: '职位', flex: 0.5, sort: true }, - { id: 'email', label: '邮箱', flex: 1 }, - { id: 'phone', label: '电话', flex: 1 }, - { id: 'organization', label: '组织机构', flex: 1, sort: true } - ]; - - constructor(private service: UsersServiceTest) {} - - ngOnInit() {} -} - -@Component({ - template: ` -
- -
-
- -
-
- -
-
- -
-
- -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row { - padding: 1rem; - } - .row:not(:first-child) { - margin-top: 1rem; - } - ` - ], - providers: [UsersServiceTest] -}) -class TestXTableRowSizeComponent { - data = (index: number, size: number, query: XQuery) => this.service.getList(index, size, query).pipe(delay(2000)); - columns: XTableColumn[] = [ - { id: 'index', label: '序号', flex: 0.5, left: 0, type: 'index' }, - { id: 'name', label: '用户', flex: 1.5, sort: true }, - { id: 'position', label: '职位', flex: 0.5, sort: true }, - { id: 'email', label: '邮箱', flex: 1 }, - { id: 'phone', label: '电话', flex: 1 }, - { id: 'organization', label: '组织机构', flex: 1, sort: true } - ]; - - constructor(private service: UsersServiceTest) {} - - ngOnInit() {} -} - -@Component({ - template: ` -
- - - -
- -
- {{ row.name }} - {{ row.organization }} -
-
-
-
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row { - padding: 1rem; - width: 30rem; - } - .row:not(:first-child) { - margin-top: 1rem; - } - .custom-td { - display: flex; - align-items: center; - color: var(--x-text); - } - .custom-td x-icon { - font-size: 4rem; - padding: 1rem; - } - .custom-td-inner { - margin-left: $--x-font-size; - display: flex; - flex-direction: column; - } - .custom-td-name { - font-weight: 600; - } - .custom-td-organization { - } - ` - ], - providers: [UsersServiceTest] -}) -class TestXTablePaginationComponent { - size = 100; - data = (index: number, size: number, query: XQuery) => this.service.getList(index, size, query).pipe(delay(2000)); - columns: XTableColumn[] = [{ id: 'name', label: '用户', flex: 1.5, sort: true }]; - - constructor(private service: UsersServiceTest) {} - - ngOnInit() {} -} diff --git a/lib/ng-nest/ui/tabs/tabs.component.spec.ts b/lib/ng-nest/ui/tabs/tabs.component.spec.ts index d226b42cf..297679155 100644 --- a/lib/ng-nest/ui/tabs/tabs.component.spec.ts +++ b/lib/ng-nest/ui/tabs/tabs.component.spec.ts @@ -1,32 +1,80 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, ChangeDetectorRef, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal, TemplateRef } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XTabsComponent, XTabComponent } from '@ng-nest/ui/tabs'; -import { XTabsPrefix, XTabsLayout } from './tabs.property'; -import { XRadioComponent } from '@ng-nest/ui/radio'; -import { FormsModule } from '@angular/forms'; -import { XIconComponent } from '@ng-nest/ui/icon'; -import { XJustify } from '@ng-nest/ui/core'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - -import { XButtonComponent } from '@ng-nest/ui/button'; +import { + XActivatedTab, + XTabsComponent, + XTabsLayout, + XTabsNode, + XTabsPrefix, + XTabsTrigger, + XTabsType +} from '@ng-nest/ui/tabs'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XDataArray, XJustify, XSize } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XTabsComponent], + template: ` ` +}) +class XTestTabsComponent {} + +@Component({ + standalone: true, + imports: [XTabsComponent], + template: ` + + + ` +}) +class XTestTabsPropertyComponent { + data = signal>([]); + justify = signal('start'); + type = signal('block'); + layout = signal('top'); + trigger = signal('click'); + activatedIndex = signal(0); + animated = signal(true); + nodeTpl = signal | null>(null); + size = signal('medium'); + nodeJustify = signal(null); + sliderHidden = signal(false); + actionTpl = signal | null>(null); + showExpand = signal(false); + expandMaxHeight = signal('15rem'); + linkRouter = signal(false); + linkExact = signal(true); + + indexChangeResult = signal(null); + indexChange(tab: XActivatedTab) { + this.indexChangeResult.set(tab); + } +} describe(XTabsPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXTabsComponent], - imports: [ - BrowserAnimationsModule, - - FormsModule, - XTabsComponent, - XTabComponent, - XRadioComponent, - XIconComponent, - XButtonComponent - ], + imports: [XTestTabsComponent, XTestTabsPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -34,125 +82,75 @@ describe(XTabsPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXTabsComponent); + fixture = TestBed.createComponent(XTestTabsComponent); + fixture.detectChanges(); + }); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XTabsComponent)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestTabsPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestTabsPropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XTabsComponent)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('data.', () => { + expect(true).toBe(true); + }); + it('justify.', () => { + expect(true).toBe(true); + }); + it('type.', () => { + expect(true).toBe(true); + }); + it('layout.', () => { + expect(true).toBe(true); + }); + it('trigger.', () => { + expect(true).toBe(true); + }); + it('activatedIndex.', () => { + expect(true).toBe(true); + }); + it('animated.', () => { + expect(true).toBe(true); + }); + it('nodeTpl.', () => { + expect(true).toBe(true); + }); + it('size.', () => { + expect(true).toBe(true); + }); + it('nodeJustify.', () => { + expect(true).toBe(true); + }); + it('sliderHidden.', () => { + expect(true).toBe(true); + }); + it('actionTpl.', () => { + expect(true).toBe(true); + }); + it('showExpand.', () => { + expect(true).toBe(true); + }); + it('expandMaxHeight.', () => { + expect(true).toBe(true); + }); + it('linkRouter.', () => { + expect(true).toBe(true); + }); + it('linkExact.', () => { + expect(true).toBe(true); + }); + it('indexChange.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - selector: 'test-x-tabs', - template: ` - -
- - -
{{ label }}
-
-
-
-
- - -
{{ label }}
-
-
-
-
- - -
{{ label }}
-
-
-
- -
- -
-
- -
-
- - -
{{ label }}
-
-
-
-
- - -
{{ label }}
-
-
-
-
- - -
{{ label }}
-
-
-
-
- - - - - 用户管理 - -
用户管理
-
- - - - 配置管理 - -
配置管理
-
- -
角色管理
-
- -
任务
-
-
-
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 1rem; - } - .tab-content { - padding: 0.625rem; - } - ` - ] -}) -class TestXTabsComponent { - labels = ['用户管理', '配置管理', '角色管理', '任务']; - layoutRadios = ['top', 'right', 'bottom', 'left']; - layout: XTabsLayout = 'top'; - justifyRadios = ['start', 'center', 'end']; - justify: XJustify = 'start'; - - customLabels = ['用户管理', '配置管理', '角色管理', '任务']; - constructor(private cdr: ChangeDetectorRef) {} - - change() { - this.cdr.detectChanges(); - } -} diff --git a/lib/ng-nest/ui/tag/tag.component.spec.ts b/lib/ng-nest/ui/tag/tag.component.spec.ts index 61fe61929..c74c956a2 100644 --- a/lib/ng-nest/ui/tag/tag.component.spec.ts +++ b/lib/ng-nest/ui/tag/tag.component.spec.ts @@ -1,180 +1,121 @@ -import { XIconComponent } from '@ng-nest/ui/icon'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, ChangeDetectorRef, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { XTagComponent } from '@ng-nest/ui/tag'; -import { FormsModule } from '@angular/forms'; -import { XTagPrefix } from './tag.property'; -import { XButtonComponent } from '@ng-nest/ui/button'; -import { XContainerComponent } from '@ng-nest/ui/container'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - +import { XTagComponent, XTagPrefix } from '@ng-nest/ui/tag'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XSize, XType } from '@ng-nest/ui/core'; +import { provideAnimations } from '@angular/platform-browser/animations'; + +@Component({ + standalone: true, + imports: [XTagComponent], + template: ` ` +}) +class XTestTagComponent {} + +@Component({ + standalone: true, + imports: [XTagComponent], + template: ` + + + ` +}) +class XTestTagPropertyComponent { + type = signal('initial'); + size = signal('medium'); + bordered = signal(true); + closable = signal(false); + dark = signal(false); + disabled = signal(false); + checked = signal(false); + manual = signal(false); + selected = signal(false); + style = signal<{ [cssStyle: string]: any } | null>(null); + + closeResult = signal(null); + close(event: Event) { + this.closeResult.set(event); + } +} describe(XTagPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXTagComponent], - imports: [ - BrowserAnimationsModule, - - FormsModule, - XTagComponent, - XButtonComponent, - XContainerComponent, - XRowComponent, - XColComponent, - XIconComponent - ], + imports: [XTestTagComponent, XTestTagPropertyComponent], providers: [ + provideAnimations(), provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), provideExperimentalZonelessChangeDetection() - ] + ], + teardown: { destroyAfterEach: false } }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let tag: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXTagComponent); + fixture = TestBed.createComponent(XTestTagComponent); fixture.detectChanges(); - tag = fixture.debugElement.query(By.directive(XTagComponent)); }); - it('should create.', () => { - expect(tag).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XTagComponent)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestTagPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestTagPropertyComponent); + // component = fixture.componentInstance; + fixture.detectChanges(); + }); + it('type.', () => { + expect(true).toBe(true); + }); + it('size.', () => { + expect(true).toBe(true); + }); + it('bordered.', () => { + expect(true).toBe(true); + }); + it('closable.', () => { + expect(true).toBe(true); + }); + it('dark.', () => { + expect(true).toBe(true); + }); + it('disabled.', () => { + expect(true).toBe(true); + }); + it('checked.', () => { + expect(true).toBe(true); + }); + it('manual.', () => { + expect(true).toBe(true); + }); + it('selected.', () => { + expect(true).toBe(true); + }); + it('style.', () => { + expect(true).toBe(true); + }); + it('close.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - template: ` - -
- 标签 - 标签 - 标签 - 标签 - 标签 - 标签 -
-
- 标签 - 标签 - 标签 - 标签 - 标签 - 标签 -
- -
- 标签 - 标签 - 标签 - 标签 - 标签 -
-
- 标签 - 标签 - 标签 - 标签 - 标签 - 标签 -
-
- 标签 - 标签 - 标签 - 标签 - 标签 - 标签 -
-
- 标签 - 标签 - 标签 - 标签 - 标签 -
-
- {{ tag }} -
- -
- 标签 - 标签 - 标签 - 标签 - 标签 - 标签 -
-
- 标签 - 标签 - 标签 - 标签 - 标签 - 标签 -
- -
- 标签 - 标签 - 标签 - 标签 - 标签 - 标签 -
-
- 标签 - 标签 - 标签 - 标签 - 标签 - 标签 -
-
- 标签 - 标签 - 标签 - 标签 - 标签 -
-
- {{ tag }} -
-
- 标签 - 标签 - 标签 - 标签 - 标签 -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 1rem; - } - .row x-tag:not(:first-child) { - margin-left: 1rem; - } - ` - ] -}) -class TestXTagComponent { - tags = ['标签一', '标签二', '标签三', '标签四', '标签五']; - constructor(private cdr: ChangeDetectorRef) {} - close(tag: string) { - this.tags.splice(this.tags.indexOf(tag), 1); - this.cdr.detectChanges(); - } -} diff --git a/lib/ng-nest/ui/text-retract/text-retract.component.spec.ts b/lib/ng-nest/ui/text-retract/text-retract.component.spec.ts index fbf434344..ec8cd5500 100644 --- a/lib/ng-nest/ui/text-retract/text-retract.component.spec.ts +++ b/lib/ng-nest/ui/text-retract/text-retract.component.spec.ts @@ -1,21 +1,31 @@ -import { XIconComponent } from '@ng-nest/ui/icon'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, ChangeDetectorRef, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { XTextRetractComponent } from '@ng-nest/ui/text-retract'; -import { FormsModule } from '@angular/forms'; -import { XTextRetractPrefix } from './text-retract.property'; -import { XI18nService, en_US, zh_CN } from '@ng-nest/ui/i18n'; -import { XButtonComponent } from '@ng-nest/ui/button'; +import { XTextRetractComponent, XTextRetractPrefix } from '@ng-nest/ui/text-retract'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +@Component({ + standalone: true, + imports: [XTextRetractComponent], + template: ` ` +}) +class XTestTextRetractComponent {} + +@Component({ + standalone: true, + imports: [XTextRetractComponent], + template: ` ` +}) +class XTestTextRetractPropertyComponent { + content = signal(''); + max = signal(256); +} + describe(XTextRetractPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXTextRetractComponent], - imports: [FormsModule, XTextRetractComponent, XRowComponent, XColComponent, XButtonComponent, XIconComponent], + imports: [XTestTextRetractComponent, XTestTextRetractPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -23,51 +33,30 @@ describe(XTextRetractPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let textRetract: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXTextRetractComponent); + fixture = TestBed.createComponent(XTestTextRetractComponent); fixture.detectChanges(); - textRetract = fixture.debugElement.query(By.directive(XTextRetractComponent)); }); - it('should create.', () => { - expect(textRetract).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XTextRetractComponent)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestTextRetractPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestTextRetractPropertyComponent); + // component = fixture.componentInstance; + fixture.detectChanges(); + }); + it('content.', () => { + expect(true).toBe(true); + }); + it('max.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - template: ` - 切换为英文 - 切换为中文 -
- -
- ` -}) -class TestXTextRetractComponent { - content = `天将降大任于是人也,必先苦其心志,劳其筋骨,饿其体肤,空乏其身,行拂乱其所为也,所以动心忍性,增益其所不能。 - 天将降大任于是人也,必先苦其心志,劳其筋骨,饿其体肤,空乏其身,行拂乱其所为也,所以动心忍性,增益其所不能。 - 天将降大任于是人也,必先苦其心志,劳其筋骨,饿其体肤,空乏其身,行拂乱其所为也,所以动心忍性,增益其所不能。 - 天将降大任于是人也,必先苦其心志,劳其筋骨,饿其体肤,空乏其身,行拂乱其所为也,所以动心忍性,增益其所不能。 - 天将降大任于是人也,必先苦其心志,劳其筋骨,饿其体肤,空乏其身,行拂乱其所为也,所以动心忍性,增益其所不能。 - 天将降大任于是人也,必先苦其心志,劳其筋骨,饿其体肤,空乏其身,行拂乱其所为也,所以动心忍性,增益其所不能。 - 天将降大任于是人也,必先苦其心志,劳其筋骨,饿其体肤,空乏其身,行拂乱其所为也,所以动心忍性,增益其所不能。 - 天将降大任于是人也,必先苦其心志,劳其筋骨,饿其体肤,空乏其身,行拂乱其所为也,所以动心忍性,增益其所不能。`; - - constructor( - private i18nService: XI18nService, - private cdr: ChangeDetectorRef - ) {} - - english() { - this.i18nService.setLocale(en_US); - this.cdr.detectChanges(); - } - - chinese() { - this.i18nService.setLocale(zh_CN); - this.cdr.detectChanges(); - } -} diff --git a/lib/ng-nest/ui/textarea/textarea.component.spec.ts b/lib/ng-nest/ui/textarea/textarea.component.spec.ts index cad9e3612..d1611df04 100644 --- a/lib/ng-nest/ui/textarea/textarea.component.spec.ts +++ b/lib/ng-nest/ui/textarea/textarea.component.spec.ts @@ -1,37 +1,93 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, ChangeDetectorRef, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal, TemplateRef, viewChild } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XTextareaComponent } from '@ng-nest/ui/textarea'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { XTextareaPrefix } from './textarea.property'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { interval } from 'rxjs'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - +import { XTextareaComponent, XTextareaIconLayoutType, XTextareaPrefix } from '@ng-nest/ui/textarea'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XAlign, XDirection, XJustify, XTemplate } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XTextareaComponent], + template: ` ` +}) +class XTestTextareaComponent {} + +@Component({ + standalone: true, + imports: [XTextareaComponent], + template: ` + + + before + after + ` +}) +class XTestTextareaPropertyComponent { + clearable = signal(false); + icon = signal(''); + iconLayout = signal('right'); + iconSpin = signal(false); + maxlength = signal(null); + height = signal('6rem'); + pointer = signal(false); + label = signal(''); + labelWidth = signal(''); + labelAlign = signal('start'); + justify = signal('start'); + align = signal('start'); + direction = signal('column'); + placeholder = signal(''); + disabled = signal(false); + required = signal(false); + readonly = signal(false); + valueTpl = signal | null>(null); + valueTplContext = signal(null); + before = signal(null); + beforeTemplate = viewChild>('beforeTemplate'); + after = signal(null); + afterTemplate = viewChild>('afterTemplate'); + pattern = signal(null); + message = signal([]); + active = signal(false); + inputValidator = signal<((value: any) => boolean) | null>(null); + + clearEmitResult = signal(null); + clearEmit(value: string) { + this.clearEmitResult.set(value); + } +} describe(XTextareaPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ - TestXTextareaComponent, - TestXTextareaLabelComponent, - TestXTextareaIconComponent, - TestXTextareaClearableComponent, - TestXTextareaDisabledComponent, - TestXTextareaRequiredComponent, - TestXTextareaLengthComponent - ], - imports: [ - BrowserAnimationsModule, - - XTextareaComponent, - FormsModule, - ReactiveFormsModule, - XRowComponent, - XColComponent - ], + imports: [XTestTextareaComponent, XTestTextareaPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -39,370 +95,99 @@ describe(XTextareaPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXTextareaComponent); + fixture = TestBed.createComponent(XTestTextareaComponent); fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XTextareaComponent)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XTextareaComponent)); + expect(com).toBeDefined(); }); }); - describe(`label.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTextareaLabelComponent); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestTextareaPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestTextareaPropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXTextareaLabelComponent)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('clearable.', () => { + expect(true).toBe(true); }); - }); - describe(`icon.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTextareaIconComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXTextareaIconComponent)); + it('icon.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('iconLayout.', () => { + expect(true).toBe(true); }); - }); - describe(`clearable.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTextareaClearableComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXTextareaClearableComponent)); + it('iconSpin.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('maxlength.', () => { + expect(true).toBe(true); }); - }); - describe(`disabled.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTextareaDisabledComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXTextareaDisabledComponent)); + it('height.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('pointer.', () => { + expect(true).toBe(true); }); - }); - describe(`required.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTextareaRequiredComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXTextareaRequiredComponent)); + it('label.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('labelWidth.', () => { + expect(true).toBe(true); }); - }); - describe(`length.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTextareaLengthComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXTextareaLengthComponent)); + it('labelAlign.', () => { + expect(true).toBe(true); + }); + it('justify.', () => { + expect(true).toBe(true); + }); + it('align.', () => { + expect(true).toBe(true); + }); + it('direction.', () => { + expect(true).toBe(true); + }); + it('placeholder.', () => { + expect(true).toBe(true); + }); + it('disabled.', () => { + expect(true).toBe(true); + }); + it('required.', () => { + expect(true).toBe(true); + }); + it('readonly.', () => { + expect(true).toBe(true); + }); + it('valueTpl.', () => { + expect(true).toBe(true); + }); + it('valueTplContext.', () => { + expect(true).toBe(true); + }); + it('before.', () => { + expect(true).toBe(true); + }); + it('after.', () => { + expect(true).toBe(true); + }); + it('pattern.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('message.', () => { + expect(true).toBe(true); + }); + it('active.', () => { + expect(true).toBe(true); + }); + it('inputValidator.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - template: ` - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXTextareaComponent { - constructor(private cdr: ChangeDetectorRef) { - interval(1000).subscribe(() => { - this.cdr.detectChanges(); - }); - } -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXTextareaLabelComponent {} - -@Component({ - template: ` - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXTextareaIconComponent {} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXTextareaClearableComponent { - model: any; - modelValue = '显示清除按钮'; - modelIcon: any; - constructor(private cdr: ChangeDetectorRef) {} - change() { - this.cdr.detectChanges(); - } -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXTextareaDisabledComponent { - model = '输入框禁用'; - modelClearable = '禁用状态下,不显示清除按钮'; -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXTextareaRequiredComponent { - value: any; - constructor(private cdr: ChangeDetectorRef) {} - change() { - this.cdr.detectChanges(); - } -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXTextareaLengthComponent { - value: any; - constructor(private cdr: ChangeDetectorRef) {} - change() { - this.cdr.detectChanges(); - } -} diff --git a/lib/ng-nest/ui/time-picker/time-picker.component.spec.ts b/lib/ng-nest/ui/time-picker/time-picker.component.spec.ts index ac188e36f..990cc1313 100644 --- a/lib/ng-nest/ui/time-picker/time-picker.component.spec.ts +++ b/lib/ng-nest/ui/time-picker/time-picker.component.spec.ts @@ -1,41 +1,110 @@ -import { interval } from 'rxjs'; import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { XTimePickerComponent } from './time-picker.component'; -import { Component, DebugElement, ChangeDetectorRef, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal, TemplateRef, viewChild } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XTimePickerModule } from '@ng-nest/ui/time-picker'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { XTimePickerPrefix } from './time-picker.property'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - -import { XRadioComponent } from '@ng-nest/ui/radio'; +import { + XTimePickerComponent, + XTimePickerDisabledTime, + XTimePickerPrefix, + XTimePickerPreset, + XTimePickerType +} from '@ng-nest/ui/time-picker'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XAlign, XCorner, XData, XDirection, XJustify, XSize, XTemplate } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XTimePickerComponent], + template: ` ` +}) +class XTestTimePickerComponent {} + +@Component({ + standalone: true, + imports: [XTimePickerComponent], + template: ` + + + before + after + ` +}) +class XTestTimePickerPropertyComponent { + type = signal('time'); + format = signal('HH:mm:ss'); + placement = signal('bottom-start'); + use12Hours = signal(false); + bordered = signal(true); + hourStep = signal(1); + minuteStep = signal(1); + secondStep = signal(1); + preset = signal>([]); + disabledTime = signal(null); + size = signal('medium'); + pointer = signal(false); + label = signal(''); + labelWidth = signal(''); + labelAlign = signal('start'); + justify = signal('start'); + align = signal('start'); + direction = signal('column'); + placeholder = signal(''); + disabled = signal(false); + required = signal(false); + readonly = signal(false); + valueTpl = signal | null>(null); + valueTplContext = signal(null); + before = signal(null); + beforeTemplate = viewChild>('beforeTemplate'); + after = signal(null); + afterTemplate = viewChild>('afterTemplate'); + pattern = signal(null); + message = signal([]); + active = signal(false); + inputValidator = signal<((value: any) => boolean) | null>(null); + + nodeEmitResult = signal(null); + nodeEmit(value: number) { + this.nodeEmitResult.set(value); + } +} describe(XTimePickerPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ - TestXTimePickerComponent, - TestXTimePickerLabelComponent, - TestXTimePickerDisabledComponent, - TestXTimePickerRequiredComponent, - TestXTimePickerHourOrMinuteComponent, - TestXTimePickerSizeComponent, - TestXTimePickerBorderedComponent - ], - imports: [ - BrowserAnimationsModule, - - XTimePickerModule, - FormsModule, - ReactiveFormsModule, - XRowComponent, - XColComponent, - XRadioComponent - ], + imports: [XTestTimePickerComponent, XTestTimePickerPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -43,380 +112,114 @@ describe(XTimePickerPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXTimePickerComponent); + fixture = TestBed.createComponent(XTestTimePickerComponent); fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XTimePickerComponent)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XTimePickerComponent)); + expect(com).toBeDefined(); }); }); - describe(`label.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTimePickerLabelComponent); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestTimePickerPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestTimePickerPropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXTimePickerLabelComponent)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('type.', () => { + expect(true).toBe(true); }); - }); - describe(`disabled.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTimePickerDisabledComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXTimePickerDisabledComponent)); + it('format.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('placement.', () => { + expect(true).toBe(true); }); - }); - describe(`required.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTimePickerRequiredComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXTimePickerRequiredComponent)); + it('use12Hours.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('bordered.', () => { + expect(true).toBe(true); }); - }); - describe(`hour or minute.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTimePickerHourOrMinuteComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXTimePickerHourOrMinuteComponent)); + it('hourStep.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('minuteStep.', () => { + expect(true).toBe(true); }); - }); - describe(`size.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTimePickerSizeComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXTimePickerComponent)); + it('secondStep.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('preset.', () => { + expect(true).toBe(true); }); - }); - describe(`bordered.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTimePickerBorderedComponent); - fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(TestXTimePickerComponent)); + it('disabledTime.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('size.', () => { + expect(true).toBe(true); }); - }); -}); - -@Component({ - template: ` - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXTimePickerComponent { - model1: any; - model2 = new Date(); - constructor(private cdr: ChangeDetectorRef) { - interval(0).subscribe(() => { - this.cdr.detectChanges(); + it('pointer.', () => { + expect(true).toBe(true); }); - } -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXTimePickerLabelComponent { - model: any; - constructor(private cdr: ChangeDetectorRef) { - interval(50).subscribe(() => { - this.cdr.detectChanges(); + it('label.', () => { + expect(true).toBe(true); }); - } -} - -@Component({ - template: ` - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXTimePickerDisabledComponent { - model = new Date(); -} - -@Component({ - template: ` - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXTimePickerRequiredComponent { - model: any; - constructor(private cdr: ChangeDetectorRef) { - interval(50).subscribe(() => { - this.cdr.detectChanges(); + it('labelWidth.', () => { + expect(true).toBe(true); }); - } -} - -@Component({ - template: ` - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXTimePickerHourOrMinuteComponent { - model: any; - constructor(private cdr: ChangeDetectorRef) { - interval(50).subscribe(() => { - this.cdr.detectChanges(); + it('labelAlign.', () => { + expect(true).toBe(true); }); - } -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col > x-time-picker { - width: 15rem; - display: block; - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXTimePickerSizeComponent { - radioData = ['big', 'large', 'medium', 'small', 'mini']; - size = 'medium'; - model: any; - constructor(private cdr: ChangeDetectorRef) {} - change($event: string) { - console.log($event); - this.cdr.detectChanges(); - } -} - -@Component({ - template: ` - - - - - - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col > x-time-picker { - width: 15rem; - display: block; - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXTimePickerBorderedComponent { - model: any; - constructor() {} -} + it('justify.', () => { + expect(true).toBe(true); + }); + it('align.', () => { + expect(true).toBe(true); + }); + it('direction.', () => { + expect(true).toBe(true); + }); + it('placeholder.', () => { + expect(true).toBe(true); + }); + it('disabled.', () => { + expect(true).toBe(true); + }); + it('required.', () => { + expect(true).toBe(true); + }); + it('readonly.', () => { + expect(true).toBe(true); + }); + it('valueTpl.', () => { + expect(true).toBe(true); + }); + it('valueTplContext.', () => { + expect(true).toBe(true); + }); + it('before.', () => { + expect(true).toBe(true); + }); + it('after.', () => { + expect(true).toBe(true); + }); + it('pattern.', () => { + expect(true).toBe(true); + }); + it('message.', () => { + expect(true).toBe(true); + }); + it('active.', () => { + expect(true).toBe(true); + }); + it('inputValidator.', () => { + expect(true).toBe(true); + }); + }); +}); diff --git a/lib/ng-nest/ui/timeline/timeline.component.spec.ts b/lib/ng-nest/ui/timeline/timeline.component.spec.ts index 146266015..84909c129 100644 --- a/lib/ng-nest/ui/timeline/timeline.component.spec.ts +++ b/lib/ng-nest/ui/timeline/timeline.component.spec.ts @@ -1,31 +1,37 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XTimelineComponent } from '@ng-nest/ui/timeline'; -import { XTimelinePrefix, XTimelineNode } from './timeline.property'; -import { XAddDays, XAddHours } from '@ng-nest/ui/core'; -import { XCardComponent } from '@ng-nest/ui/card'; -import { XTimeAgoPipe } from '@ng-nest/ui/time-ago'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - -import { XRadioComponent } from '@ng-nest/ui/radio'; -import { FormsModule } from '@angular/forms'; +import { XTimelineComponent, XTimelineMode, XTimelineNode, XTimelinePrefix } from '@ng-nest/ui/timeline'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XDataArray, XSize, XTemplate, XType } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XTimelineComponent], + template: ` ` +}) +class XTestTimelineComponent {} + +@Component({ + standalone: true, + imports: [XTimelineComponent], + template: ` + + ` +}) +class XTestTimelinePropertyComponent { + data = signal>([]); + type = signal(null); + size = signal('medium'); + wrapper = signal(null); + mode = signal('left'); +} describe(XTimelinePrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXTimelineComponent], - imports: [ - BrowserAnimationsModule, - FormsModule, - - XTimelineComponent, - XCardComponent, - XTimeAgoPipe, - XRadioComponent - ], + imports: [XTestTimelineComponent, XTestTimelinePropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -33,259 +39,39 @@ describe(XTimelinePrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let timeline: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXTimelineComponent); + fixture = TestBed.createComponent(XTestTimelineComponent); + fixture.detectChanges(); + }); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XTimelineComponent)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestTimelinePropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestTimelinePropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - timeline = fixture.debugElement.query(By.directive(XTimelineComponent)); }); - it('should create.', () => { - expect(timeline).toBeDefined(); + it('data.', () => { + expect(true).toBe(true); + }); + it('type.', () => { + expect(true).toBe(true); + }); + it('size.', () => { + expect(true).toBe(true); + }); + it('wrapper.', () => { + expect(true).toBe(true); + }); + it('mode.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - template: ` - -
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- - -
- {{ node.time | xTimeAgo }} - -

{{ node.label }}

-

{{ node.content }}

-
-
-
-
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 1rem; - } - .custom-wrapper > span { - color: var(--x-text-400); - display: inline-block; - margin-bottom: 0.25rem; - } - .custom-wrapper h4 { - margin: 0; - } - .custom-wrapper p { - margin: 0; - } - ` - ] -}) -class TestXTimelineComponent { - now = new Date(); - data: XTimelineNode[] = [ - { - label: '新增请假', - content: '李三 请假时间 2020-2-23 至 2020-3-1', - time: XAddDays(this.now, -3) - }, - { - label: '主管审批', - content: '王斯 已批准', - time: XAddDays(this.now, -2) - }, - { - label: '申请人销假', - content: '李三 销假', - time: XAddDays(this.now, -1) - }, - { - label: '人事复核', - content: '汪清 复核通过', - time: XAddHours(this.now, -12) - }, - { - label: '结束', - content: '', - time: XAddHours(this.now, -6) - } - ]; - dataType: XTimelineNode[] = [ - { - label: '新增请假', - content: '李三 请假时间 2020-2-23 至 2020-3-1', - type: 'primary', - time: XAddDays(this.now, -3) - }, - { - label: '主管审批', - content: '王斯 已批准', - type: 'success', - time: XAddDays(this.now, -2) - }, - { - label: '申请人销假', - content: '李三 销假', - type: 'warning', - time: XAddDays(this.now, -1) - }, - { - label: '人事复核', - content: '汪清 复核通过', - type: 'danger', - time: XAddHours(this.now, -12) - }, - { - label: '结束', - content: '', - type: 'info', - time: XAddHours(this.now, -6) - } - ]; - dataIcon: XTimelineNode[] = [ - { - label: '新增请假', - content: '李三 请假时间 2020-2-23 至 2020-3-1', - type: 'primary', - icon: 'fto-user', - time: XAddDays(this.now, -3) - }, - { - label: '主管审批', - content: '王斯 已批准', - type: 'success', - icon: 'fto-user', - time: XAddDays(this.now, -2) - }, - { - label: '申请人销假', - content: '李三 销假', - type: 'warning', - icon: 'fto-user', - time: XAddDays(this.now, -1) - }, - { - label: '人事复核', - content: '汪清 复核通过', - type: 'danger', - icon: 'fto-user', - time: XAddHours(this.now, -12) - }, - { - label: '结束', - content: '', - type: 'info', - icon: 'fto-user', - time: XAddHours(this.now, -6) - } - ]; - dataColor: XTimelineNode[] = [ - { - label: '新增请假', - content: '李三 请假时间 2020-2-23 至 2020-3-1', - icon: 'fto-user', - color: 'black', - time: XAddDays(this.now, -3) - }, - { - label: '主管审批', - content: '王斯 已批准', - icon: 'fto-user', - color: 'red', - time: XAddDays(this.now, -2) - }, - { - label: '申请人销假', - content: '李三 销假', - icon: 'fto-user', - color: 'blue', - time: XAddDays(this.now, -1) - }, - { - label: '人事复核', - content: '汪清 复核通过', - icon: 'fto-user', - color: 'rgba(51, 51, 51, 0.72)', - time: XAddHours(this.now, -12) - }, - { - label: '结束', - content: '', - icon: 'fto-user', - color: '#ffff00', - time: XAddHours(this.now, -6) - } - ]; - dataSize: XTimelineNode[] = [ - { - label: '新增请假', - content: '李三 请假时间 2020-2-23 至 2020-3-1', - type: 'primary', - icon: 'fto-user', - size: 'large', - time: XAddDays(this.now, -3) - }, - { - label: '主管审批', - content: '王斯 已批准', - type: 'success', - icon: 'fto-user', - size: 'medium', - time: XAddDays(this.now, -2) - }, - { - label: '申请人销假', - content: '李三 销假', - type: 'warning', - icon: 'fto-user', - size: 'small', - time: XAddDays(this.now, -1) - }, - { - label: '人事复核', - content: '汪清 复核通过', - type: 'danger', - icon: 'fto-user', - size: 'mini', - time: XAddHours(this.now, -12) - }, - { - label: '结束', - content: '', - type: 'info', - icon: 'fto-user', - time: XAddHours(this.now, -6) - } - ]; -} diff --git a/lib/ng-nest/ui/tooltip/tooltip.directive.spec.ts b/lib/ng-nest/ui/tooltip/tooltip.directive.spec.ts index 63f55cbd3..1628d90d0 100644 --- a/lib/ng-nest/ui/tooltip/tooltip.directive.spec.ts +++ b/lib/ng-nest/ui/tooltip/tooltip.directive.spec.ts @@ -1,19 +1,56 @@ -import { XButtonComponent } from '@ng-nest/ui/button'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, ChangeDetectorRef, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, ElementRef, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XTooltipDirective } from '@ng-nest/ui/tooltip'; -import { XTooltipPrefix } from './tooltip.property'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - +import { XTooltipDirective, XTooltipPrefix } from '@ng-nest/ui/tooltip'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XPlacement, XTemplate } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XTooltipDirective], + template: ` ` +}) +class XTestTooltipComponent {} + +@Component({ + standalone: true, + imports: [XTooltipDirective], + template: ` + + + ` +}) +class XTestTooltipPropertyComponent { + content = signal(null); + placement = signal('top'); + visible = signal(false); + panelClass = signal(''); + connectTo = signal | HTMLElement | null>(null); + backgroundColor = signal(''); + color = signal(''); + manual = signal(false); + mouseEnterDelay = signal(150); + mouseLeaveDelay = signal(100); + disabled = signal(false); +} describe(XTooltipPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXTooltipComponent], - imports: [BrowserAnimationsModule, BrowserAnimationsModule, XTooltipDirective, XButtonComponent], + imports: [XTestTooltipComponent, XTestTooltipPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -21,95 +58,57 @@ describe(XTooltipPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXTooltipComponent); + fixture = TestBed.createComponent(XTestTooltipComponent); fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XTooltipDirective)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XTooltipDirective)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestTooltipPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestTooltipPropertyComponent); + // component = fixture.componentInstance; + fixture.detectChanges(); + }); + it('content.', () => { + expect(true).toBe(true); + }); + it('placement.', () => { + expect(true).toBe(true); + }); + it('visible.', () => { + expect(true).toBe(true); + }); + it('panelClass.', () => { + expect(true).toBe(true); + }); + it('connectTo.', () => { + expect(true).toBe(true); + }); + it('backgroundColor.', () => { + expect(true).toBe(true); + }); + it('color.', () => { + expect(true).toBe(true); + }); + it('manual.', () => { + expect(true).toBe(true); + }); + it('mouseEnterDelay.', () => { + expect(true).toBe(true); + }); + it('mouseLeaveDelay.', () => { + expect(true).toBe(true); + }); + it('disabled.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - selector: 'test-x-tooltip', - template: ` - -
-
- 上左 - 上中 - 上右 -
-
- 左上左中左下 -
-
- 右上右中右下 -
-
- 下左下中下右 -
-
-
- 自定义控制显示/隐藏 -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .box { - padding: 5rem 10rem; - width: 45rem; - } - .box .top { - text-align: center; - } - .box .left { - float: left; - width: 5rem; - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - } - .box .right { - float: right; - width: 5rem; - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - } - .box .bottom { - clear: both; - text-align: center; - } - ` - ] -}) -class TestXTooltipComponent { - visible = false; - constructor(private cdr: ChangeDetectorRef) {} - - custom() { - this.visible = !this.visible; - this.cdr.detectChanges(); - } -} diff --git a/lib/ng-nest/ui/transfer/transfer.component.spec.ts b/lib/ng-nest/ui/transfer/transfer.component.spec.ts index 238ae4b80..44d68a466 100644 --- a/lib/ng-nest/ui/transfer/transfer.component.spec.ts +++ b/lib/ng-nest/ui/transfer/transfer.component.spec.ts @@ -1,129 +1,154 @@ -import { XIconComponent } from '@ng-nest/ui/icon'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal, TemplateRef } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { XTransferComponent } from '@ng-nest/ui/transfer'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { XTransferPrefix, XTransferNode } from './transfer.property'; -import { XButtonComponent } from '@ng-nest/ui/button'; -import { XContainerComponent } from '@ng-nest/ui/container'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - -import { XTreeComponent } from '@ng-nest/ui/tree'; +import { + XTransferComponent, + XTransferListStyle, + XTransferNode, + XTransferPrefix, + XTransferType +} from '@ng-nest/ui/transfer'; import { provideHttpClientTesting } from '@angular/common/http/testing'; -import { XSelectComponent } from '@ng-nest/ui/select'; -import { XInputComponent } from '@ng-nest/ui/input'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XData, XQuery, XTemplate } from '@ng-nest/ui/core'; +import { XTableColumn } from '@ng-nest/ui/table'; +import { provideAnimations } from '@angular/platform-browser/animations'; + +@Component({ + standalone: true, + imports: [XTransferComponent], + template: ` ` +}) +class XTestTransferComponent {} + +@Component({ + standalone: true, + imports: [XTransferComponent], + template: ` + + + ` +}) +class XTestTransferPropertyComponent { + data = signal>([]); + type = signal('list'); + titles = signal(null); + listStyle = signal(null); + hiddenCheckAll = signal(null); + drag = signal(false); + search = signal(false); + tableHeadSearchTpl = signal(null); + nodeTpl = signal | null>(null); + titleTpl = signal | null>(null); + footerTpl = signal | null>(null); + tableColumns = signal(null); + tableIndex = signal(1); + tableSize = signal(10); + tableQuery = signal({}); + tableTotal = signal(0); + inverse = signal(false); +} describe(XTransferPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXTransferComponent], - imports: [ - BrowserAnimationsModule, - - FormsModule, - ReactiveFormsModule, - XTransferComponent, - XButtonComponent, - XContainerComponent, - XRowComponent, - XColComponent, - XIconComponent, - XTreeComponent, - XSelectComponent, - XInputComponent - ], + imports: [XTestTransferComponent, XTestTransferPropertyComponent], providers: [ + provideAnimations(), provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), provideExperimentalZonelessChangeDetection() - ] + ], + teardown: { destroyAfterEach: false } }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let transfer: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXTransferComponent); + fixture = TestBed.createComponent(XTestTransferComponent); fixture.detectChanges(); - transfer = fixture.debugElement.query(By.directive(XTransferComponent)); }); - it('should create.', () => { - expect(transfer).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XTransferComponent)); + expect(com).toBeDefined(); }); }); -}); - -@Component({ - template: ` - -
- - - - {{ item.node?.label }} - - -
- {{ checkedCount <= 0 ? '' : checkedCount + ' /' }} {{ count }} 项 - {{ title }} -
-
-
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 1rem; - } - .custom-icon { - margin-right: 0.125rem; - font-size: 0.925rem; - } - .custom-title { - flex: 1; - display: flex; - align-items: center; - justify-content: space-between; - } - ` - ] -}) -class TestXTransferComponent { - value = [1, 3, 7]; - data: XTransferNode[] = Array.from({ length: 15 }).map((_x, i) => { - return { - id: i + 1, - label: '用户 ' + (i + 1), - icon: 'fto-user', - disabled: [3, 5, 9].indexOf(i + 1) >= 0 - }; + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestTransferPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestTransferPropertyComponent); + // component = fixture.componentInstance; + fixture.detectChanges(); + }); + it('data.', () => { + expect(true).toBe(true); + }); + it('type.', () => { + expect(true).toBe(true); + }); + it('titles.', () => { + expect(true).toBe(true); + }); + it('listStyle.', () => { + expect(true).toBe(true); + }); + it('hiddenCheckAll.', () => { + expect(true).toBe(true); + }); + it('drag.', () => { + expect(true).toBe(true); + }); + it('search.', () => { + expect(true).toBe(true); + }); + it('tableHeadSearchTpl.', () => { + expect(true).toBe(true); + }); + it('nodeTpl.', () => { + expect(true).toBe(true); + }); + it('titleTpl.', () => { + expect(true).toBe(true); + }); + it('footerTpl.', () => { + expect(true).toBe(true); + }); + it('tableColumns.', () => { + expect(true).toBe(true); + }); + it('tableIndex.', () => { + expect(true).toBe(true); + }); + it('tableSize.', () => { + expect(true).toBe(true); + }); + it('tableQuery.', () => { + expect(true).toBe(true); + }); + it('tableTotal.', () => { + expect(true).toBe(true); + }); + it('inverse.', () => { + expect(true).toBe(true); + }); }); - constructor() { - // interval(10).subscribe(x => { - // of(true) - // .pipe(delay(10)) - // .subscribe(() => { - // this.cdr.detectChanges(); - // }); - // }); - } - change($event: any) { - console.log($event); - } -} +}); diff --git a/lib/ng-nest/ui/transfer/transfer.component.ts b/lib/ng-nest/ui/transfer/transfer.component.ts index 62c24c184..01391f7cb 100644 --- a/lib/ng-nest/ui/transfer/transfer.component.ts +++ b/lib/ng-nest/ui/transfer/transfer.component.ts @@ -667,7 +667,7 @@ export class XTransferComponent extends XTransferProperty implements OnInit, OnC } private setFooterTpl() { - if (XIsUndefined(this.footerTpl())) return; + if (XIsEmpty(this.footerTpl())) return; if (this.footerTpl()!.length > 0) { this.left.update((x) => { x.footerTpl = this.footerTpl()![0]; @@ -683,7 +683,7 @@ export class XTransferComponent extends XTransferProperty implements OnInit, OnC } private setTableHeadSearchTpl() { - if (XIsUndefined(this.tableHeadSearchTpl())) return; + if (XIsEmpty(this.tableHeadSearchTpl())) return; if (this.tableHeadSearchTpl()!.length > 0) { this.left.update((x) => { x.tableHeadSearchTpl = this.tableHeadSearchTpl()![0]; diff --git a/lib/ng-nest/ui/tree-file/tree-file.component.spec.ts b/lib/ng-nest/ui/tree-file/tree-file.component.spec.ts index fae14a6e0..ade663702 100644 --- a/lib/ng-nest/ui/tree-file/tree-file.component.spec.ts +++ b/lib/ng-nest/ui/tree-file/tree-file.component.spec.ts @@ -1,33 +1,58 @@ -import { XIconComponent } from '@ng-nest/ui/icon'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, Injectable, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { XTreeFileComponent } from '@ng-nest/ui/tree-file'; -import { FormsModule } from '@angular/forms'; -import { XTreeFilePrefix, XTreeFileNode } from './tree-file.property'; -import { XButtonComponent } from '@ng-nest/ui/button'; -import { XContainerComponent } from '@ng-nest/ui/container'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; - +import { XTreeFileComponent, XTreeFileNode, XTreeFilePrefix } from '@ng-nest/ui/tree-file'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XData } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XTreeFileComponent], + template: ` ` +}) +class XTestTreeFileComponent {} + +@Component({ + standalone: true, + imports: [XTreeFileComponent], + template: ` + + + ` +}) +class XTestTreeFilePropertyComponent { + data = signal>([]); + domain = signal(''); + toggle = signal(true); + showToggle = signal(true); + showTree = signal(true); + showCrumb = signal(true); + maxHeight = signal('37.5rem'); + spacing = signal('1rem'); + activatedId = signal(null); + expanded = signal([]); + expandedAll = signal(false); + expandedLevel = signal(-1); +} describe(XTreeFilePrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXTreeFileComponent], - imports: [ - FormsModule, - - BrowserAnimationsModule, - XTreeFileComponent, - XButtonComponent, - XContainerComponent, - XRowComponent, - XColComponent, - XIconComponent - ], + imports: [XTestTreeFileComponent, XTestTreeFilePropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -35,130 +60,60 @@ describe(XTreeFilePrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let treeFile: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXTreeFileComponent); + fixture = TestBed.createComponent(XTestTreeFileComponent); fixture.detectChanges(); - treeFile = fixture.debugElement.query(By.directive(XTreeFileComponent)); }); - it('should create.', () => { - expect(treeFile).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XTreeFileComponent)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestTreeFilePropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestTreeFilePropertyComponent); + // component = fixture.componentInstance; + fixture.detectChanges(); + }); + it('data.', () => { + expect(true).toBe(true); + }); + it('domain.', () => { + expect(true).toBe(true); + }); + it('toggle.', () => { + expect(true).toBe(true); + }); + it('showToggle.', () => { + expect(true).toBe(true); + }); + it('showTree.', () => { + expect(true).toBe(true); + }); + it('showCrumb.', () => { + expect(true).toBe(true); + }); + it('maxHeight.', () => { + expect(true).toBe(true); + }); + it('spacing.', () => { + expect(true).toBe(true); + }); + it('activatedId.', () => { + expect(true).toBe(true); + }); + it('expanded.', () => { + expect(true).toBe(true); + }); + it('expandedAll.', () => { + expect(true).toBe(true); + }); + it('expandedLevel.', () => { + expect(true).toBe(true); }); }); }); - -@Injectable() -class TreeFileServiceTest { - data: XTreeFileNode[] = [ - { id: 1, label: '针对上一步改变的文件' }, - { id: 2, label: 'my-app' }, - { - id: 5, - label: 'app.component.html', - type: 'html', - url: 'ui/getting-started/demo/1__my-app/src/app/app.component.html', - pid: 1 - }, - { - id: 6, - label: 'app.component.scss', - type: 'css', - url: 'ui/getting-started/demo/1__my-app/src/app/app.component.scss', - pid: 1 - }, - { - id: 7, - label: 'app.component.ts', - type: 'typescript', - url: 'ui/getting-started/demo/1__my-app/src/app/app.component.ts', - pid: 1 - }, - { - id: 8, - label: 'angular.json', - type: 'json', - url: 'ui/getting-started/demo/1__my-app/angular.json', - pid: 1 - }, - { id: 9, label: 'src', pid: 2 }, - { id: 10, label: 'app', pid: 9 }, - { id: 11, label: 'assets', pid: 9 }, - { - id: 13, - label: 'app.component.html', - pid: 10, - type: 'html', - url: 'ui/getting-started/demo/1__my-app/src/app/app.component.html', - highlightLines: { - primary: '1-3, 5', - success: '7-10, 13', - warning: '15-20, 23', - danger: '30-32, 35', - info: '40-44, 48' - } - }, - { id: 14, label: 'app.component.scss', pid: 10 }, - { - id: 15, - label: 'app.component.ts', - pid: 10, - type: 'typescript', - url: 'ui/getting-started/demo/1__my-app/src/app/app.component.ts' - }, - { - id: 16, - label: '1.png', - pid: 10, - type: 'png', - url: 'ui/getting-started/demo/3__img/1.png' - }, - { id: 17, label: 'assets', pid: 9 }, - { id: 18, label: 'assets', pid: 9 }, - { id: 19, label: 'assets', pid: 9 }, - { id: 20, label: 'assets', pid: 9 }, - { id: 21, label: 'assets', pid: 9 }, - { id: 22, label: 'assets', pid: 9 }, - { id: 23, label: 'assets', pid: 9 }, - { id: 24, label: 'assets', pid: 9 }, - { id: 25, label: 'assets', pid: 9 }, - { id: 26, label: 'assets', pid: 9 }, - { id: 27, label: 'assets', pid: 9 }, - { id: 28, label: 'assets', pid: 9 }, - { id: 29, label: 'assets', pid: 9 }, - { id: 30, label: 'assets', pid: 9 }, - { id: 31, label: 'assets', pid: 9 }, - { id: 32, label: 'assets', pid: 9 }, - { id: 33, label: 'assets', pid: 9 }, - { id: 34, label: 'assets', pid: 9 } - ]; -} - -@Component({ - template: ` - -
- -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 1rem; - } - .row x-tree-file:not(:first-child) { - margin-left: 2rem; - } - ` - ], - providers: [TreeFileServiceTest] -}) -class TestXTreeFileComponent { - constructor(public service: TreeFileServiceTest) {} -} diff --git a/lib/ng-nest/ui/tree-select/tree-select.component.spec.ts b/lib/ng-nest/ui/tree-select/tree-select.component.spec.ts index eae5366fa..c267c2e31 100644 --- a/lib/ng-nest/ui/tree-select/tree-select.component.spec.ts +++ b/lib/ng-nest/ui/tree-select/tree-select.component.spec.ts @@ -1,31 +1,123 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal, TemplateRef, viewChild } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XTreeSelectComponent } from '@ng-nest/ui/tree-select'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { XTreeSelectPrefix, XTreeSelectNode } from './tree-select.property'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { XData } from '@ng-nest/ui/core'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { XRadioComponent } from '@ng-nest/ui/radio'; -import { XInputComponent } from '@ng-nest/ui/input'; +import { XTreeSelectComponent, XTreeSelectNode, XTreeSelectPrefix } from '@ng-nest/ui/tree-select'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XAlign, XData, XDirection, XJustify, XSize, XTemplate } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XTreeSelectComponent], + template: ` ` +}) +class XTestTreeSelectComponent {} + +@Component({ + standalone: true, + imports: [XTreeSelectComponent], + template: ` + + + before + after + ` +}) +class XTestTreeSelectPropertyComponent { + data = signal>([]); + clearable = signal(true); + async = signal(false); + placement = signal('bottom'); + multiple = signal(false); + selectAll = signal(false); + selectAllText = signal(''); + nodeTpl = signal | null>(null); + expandedLevel = signal(-1); + bordered = signal(true); + portalMaxHeight = signal('12rem'); + search = signal(false); + caseSensitive = signal(true); + debounceTime = signal(200); + maxTagCount = signal(-1); + maxTagContent = signal(null); + virtualScroll = signal(false); + showPath = signal(false); + separator = signal('/'); + onlyLeaf = signal(false); + size = signal('medium'); + pointer = signal(false); + label = signal(''); + labelWidth = signal(''); + labelAlign = signal('start'); + justify = signal('start'); + align = signal('start'); + direction = signal('column'); + placeholder = signal(''); + disabled = signal(false); + required = signal(false); + readonly = signal(false); + valueTpl = signal | null>(null); + valueTplContext = signal(null); + before = signal(null); + beforeTemplate = viewChild>('beforeTemplate'); + after = signal(null); + afterTemplate = viewChild>('afterTemplate'); + pattern = signal(null); + message = signal([]); + active = signal(false); + inputValidator = signal<((value: any) => boolean) | null>(null); + + nodeEmitResult = signal(null); + nodeEmit(node: XTreeSelectNode) { + this.nodeEmitResult.set(node); + } +} describe(XTreeSelectPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [TestXTreeSelectComponent], - imports: [ - BrowserAnimationsModule, - XTreeSelectComponent, - FormsModule, - ReactiveFormsModule, - XInputComponent, - XRowComponent, - XColComponent, - XRadioComponent - ], + imports: [XTestTreeSelectComponent, XTestTreeSelectPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -33,51 +125,147 @@ describe(XTreeSelectPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let debugElement: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXTreeSelectComponent); + fixture = TestBed.createComponent(XTestTreeSelectComponent); fixture.detectChanges(); - debugElement = fixture.debugElement.query(By.directive(XTreeSelectComponent)); }); - it('should create.', () => { - expect(debugElement).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XTreeSelectComponent)); + expect(com).toBeDefined(); + }); + }); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestTreeSelectPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestTreeSelectPropertyComponent); + // component = fixture.componentInstance; + fixture.detectChanges(); + }); + it('data.', () => { + expect(true).toBe(true); + }); + it('clearable.', () => { + expect(true).toBe(true); + }); + it('async.', () => { + expect(true).toBe(true); + }); + it('placement.', () => { + expect(true).toBe(true); + }); + it('multiple.', () => { + expect(true).toBe(true); + }); + it('selectAll.', () => { + expect(true).toBe(true); + }); + it('selectAllText.', () => { + expect(true).toBe(true); + }); + it('nodeTpl.', () => { + expect(true).toBe(true); + }); + it('expandedLevel.', () => { + expect(true).toBe(true); + }); + it('bordered.', () => { + expect(true).toBe(true); + }); + it('portalMaxHeight.', () => { + expect(true).toBe(true); + }); + it('search.', () => { + expect(true).toBe(true); + }); + it('caseSensitive.', () => { + expect(true).toBe(true); + }); + it('debounceTime.', () => { + expect(true).toBe(true); + }); + it('maxTagCount.', () => { + expect(true).toBe(true); + }); + it('maxTagContent.', () => { + expect(true).toBe(true); + }); + it('virtualScroll.', () => { + expect(true).toBe(true); + }); + it('showPath.', () => { + expect(true).toBe(true); + }); + it('separator.', () => { + expect(true).toBe(true); + }); + it('onlyLeaf.', () => { + expect(true).toBe(true); + }); + it('size.', () => { + expect(true).toBe(true); + }); + it('pointer.', () => { + expect(true).toBe(true); + }); + it('label.', () => { + expect(true).toBe(true); + }); + it('labelWidth.', () => { + expect(true).toBe(true); + }); + it('labelAlign.', () => { + expect(true).toBe(true); + }); + it('justify.', () => { + expect(true).toBe(true); + }); + it('align.', () => { + expect(true).toBe(true); + }); + it('direction.', () => { + expect(true).toBe(true); + }); + it('placeholder.', () => { + expect(true).toBe(true); + }); + it('disabled.', () => { + expect(true).toBe(true); + }); + it('required.', () => { + expect(true).toBe(true); + }); + it('readonly.', () => { + expect(true).toBe(true); + }); + it('valueTpl.', () => { + expect(true).toBe(true); + }); + it('valueTplContext.', () => { + expect(true).toBe(true); + }); + it('before.', () => { + expect(true).toBe(true); + }); + it('after.', () => { + expect(true).toBe(true); + }); + it('pattern.', () => { + expect(true).toBe(true); + }); + it('message.', () => { + expect(true).toBe(true); + }); + it('active.', () => { + expect(true).toBe(true); + }); + it('inputValidator.', () => { + expect(true).toBe(true); + }); + it('nodeEmit.', () => { + expect(true).toBe(true); }); }); }); - -const data: XData = [ - 'AAAA', - 'AAA', - 'BBBB', - 'CCCC', - 'DDDD', - 'EEEE', - 'FFFF', - 'GGGG', - 'HHHH', - 'IIII', - 'JJJJ' -]; - -@Component({ - template: ` `, - styles: [ - ` - :host { - height: 900px; - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXTreeSelectComponent { - data = data; - constructor() {} -} diff --git a/lib/ng-nest/ui/tree/tree.component.spec.ts b/lib/ng-nest/ui/tree/tree.component.spec.ts index 5010cc499..9b894fd7a 100644 --- a/lib/ng-nest/ui/tree/tree.component.spec.ts +++ b/lib/ng-nest/ui/tree/tree.component.spec.ts @@ -1,56 +1,136 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { - Component, - DebugElement, - Injectable, - ChangeDetectorRef, - viewChild, - provideExperimentalZonelessChangeDetection -} from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal, TemplateRef } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XTreeComponent } from '@ng-nest/ui/tree'; -import { XTreePrefix, XTreeNode, XTreeAction } from './tree.property'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { Observable } from 'rxjs'; -import { XButtonComponent } from '@ng-nest/ui/button'; -import { XLinkComponent } from '@ng-nest/ui/link'; -import { XFormComponent, XFormRow } from '@ng-nest/ui/form'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { UntypedFormGroup } from '@angular/forms'; -import { XRepositoryService, XHttpService, XGuid } from '@ng-nest/ui/core'; -import { map } from 'rxjs/operators'; -import { XMessageService } from '@ng-nest/ui/message'; - -import { XIconComponent } from '@ng-nest/ui/icon'; -import { XInputNumberComponent } from '@ng-nest/ui/input-number'; +import { XTreeAction, XTreeComponent, XTreeNode, XTreeNodeDragEvent, XTreePrefix } from '@ng-nest/ui/tree'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XAlign, XData } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XTreeComponent], + template: ` ` +}) +class XTestTreeComponent {} + +@Component({ + standalone: true, + imports: [XTreeComponent], + template: ` + + + ` +}) +class XTestTreePropertyComponent { + data = signal>([]); + checkbox = signal(false); + lazy = signal(false); + activatedId = signal(null); + expanded = signal([]); + checked = signal([]); + expandedAll = signal(false); + expandedLevel = signal(-1); + nodeOpen = signal(false); + spacing = signal('1.5rem'); + labelTpl = signal | null>(null); + nodeHeight = signal(''); + allowManyActivated = signal(false); + drag = signal(false); + activatedChangeResult = signal(null); + activatedChange(node: XTreeNode) { + this.activatedChangeResult.set(node); + } + + checkboxChangeResult = signal(null); + checkboxChange(node: XTreeNode) { + this.checkboxChangeResult.set(node); + } + + manual = signal(true); + levelCheck = signal(true); + nodeNowrap = signal(true); + nodeAlignItems = signal('center'); + actions = signal([]); + scrollElement = signal(null); + virtualScroll = signal(false); + virtualScrollHeight = signal('400px'); + heightAdaption = signal(null); + itemSize = signal(34); + minBufferPx = signal(100); + maxBufferPx = signal(200); + multiple = signal(false); + objectArray = signal(false); + keywordText = signal(null); + caseSensitive = signal(true); + onlyLeaf = signal(false); + expandedIcon = signal | null>(null); + showLine = signal(false); + + nodeClickResult = signal(null); + nodeClick(node: XTreeNode) { + this.nodeClickResult.set(node); + } + + nodeDragStartedResult = signal(null); + nodeDragStarted(event: XTreeNodeDragEvent) { + this.nodeDragStartedResult.set(event); + } + + nodeDragEndedResult = signal(null); + nodeDragEnded(event: XTreeNodeDragEvent) { + this.nodeDragEndedResult.set(event); + } + + nodeDragMovedResult = signal(null); + nodeDragMoved(event: XTreeNodeDragEvent) { + this.nodeDragMovedResult.set(event); + } +} describe(XTreePrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ - TestXTreeComponent, - TestXTreeLazyComponent, - TestXTreeCheckedComponent, - TestXTreeDiabledComponent, - TestXTreeCustomComponent, - TestXTreeEventComponent, - TestXTreeOperationComponent - ], - imports: [ - BrowserAnimationsModule, - - XTreeComponent, - XRowComponent, - XColComponent, - XButtonComponent, - XLinkComponent, - XFormComponent, - XLinkComponent, - XInputNumberComponent, - XIconComponent - ], + imports: [XTestTreeComponent, XTestTreePropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -58,595 +138,142 @@ describe(XTreePrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let tree: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXTreeComponent); + fixture = TestBed.createComponent(XTestTreeComponent); fixture.detectChanges(); - tree = fixture.debugElement.query(By.directive(XTreeComponent)); }); - it('should create.', () => { - expect(tree).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XTreeComponent)); + expect(com).toBeDefined(); }); }); - describe(`lazy.`, () => { - let fixture: ComponentFixture; - let tree: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTreeLazyComponent); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestTreePropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestTreePropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - tree = fixture.debugElement.query(By.directive(XTreeComponent)); }); - it('should create.', () => { - expect(tree).toBeDefined(); + it('data.', () => { + expect(true).toBe(true); }); - }); - describe(`checked.`, () => { - let fixture: ComponentFixture; - let tree: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTreeCheckedComponent); - fixture.detectChanges(); - tree = fixture.debugElement.query(By.directive(XTreeComponent)); + it('checkbox.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(tree).toBeDefined(); + it('lazy.', () => { + expect(true).toBe(true); }); - }); - describe(`disabled.`, () => { - let fixture: ComponentFixture; - let tree: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTreeDiabledComponent); - fixture.detectChanges(); - tree = fixture.debugElement.query(By.directive(XTreeComponent)); + it('activatedId.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(tree).toBeDefined(); + it('expanded.', () => { + expect(true).toBe(true); }); - }); - describe(`custom.`, () => { - let fixture: ComponentFixture; - let tree: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTreeCustomComponent); - fixture.detectChanges(); - tree = fixture.debugElement.query(By.directive(XTreeComponent)); + it('checked.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(tree).toBeDefined(); + it('expandedAll.', () => { + expect(true).toBe(true); }); - }); - describe(`event.`, () => { - let fixture: ComponentFixture; - let tree: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXTreeEventComponent); - fixture.detectChanges(); - tree = fixture.debugElement.query(By.directive(XTreeComponent)); + it('expandedLevel.', () => { + expect(true).toBe(true); + }); + it('nodeOpen.', () => { + expect(true).toBe(true); + }); + it('spacing.', () => { + expect(true).toBe(true); + }); + it('labelTpl.', () => { + expect(true).toBe(true); + }); + it('nodeHeight.', () => { + expect(true).toBe(true); + }); + it('allowManyActivated.', () => { + expect(true).toBe(true); + }); + it('drag.', () => { + expect(true).toBe(true); + }); + it('activatedChange.', () => { + expect(true).toBe(true); + }); + it('checkboxChange.', () => { + expect(true).toBe(true); + }); + it('manual.', () => { + expect(true).toBe(true); + }); + it('levelCheck.', () => { + expect(true).toBe(true); + }); + it('nodeNowrap.', () => { + expect(true).toBe(true); + }); + it('nodeAlignItems.', () => { + expect(true).toBe(true); + }); + it('actions.', () => { + expect(true).toBe(true); + }); + it('scrollElement.', () => { + expect(true).toBe(true); + }); + it('virtualScroll.', () => { + expect(true).toBe(true); + }); + + it('virtualScrollHeight.', () => { + expect(true).toBe(true); + }); + it('heightAdaption.', () => { + expect(true).toBe(true); + }); + it('itemSize.', () => { + expect(true).toBe(true); + }); + it('minBufferPx.', () => { + expect(true).toBe(true); + }); + it('maxBufferPx.', () => { + expect(true).toBe(true); + }); + it('multiple.', () => { + expect(true).toBe(true); + }); + it('objectArray.', () => { + expect(true).toBe(true); + }); + it('keywordText.', () => { + expect(true).toBe(true); + }); + it('caseSensitive.', () => { + expect(true).toBe(true); + }); + it('onlyLeaf.', () => { + expect(true).toBe(true); + }); + it('expandedIcon.', () => { + expect(true).toBe(true); + }); + it('showLine.', () => { + expect(true).toBe(true); + }); + it('nodeClick.', () => { + expect(true).toBe(true); + }); + it('nodeDragStarted.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(tree).toBeDefined(); + it('nodeDragEnded.', () => { + expect(true).toBe(true); + }); + it('nodeDragMoved.', () => { + expect(true).toBe(true); }); }); - // describe(`operation.`, () => { - // let fixture: ComponentFixture; - // let tree: DebugElement; - // beforeEach(() => { - // fixture = TestBed.createComponent(TestXTreeOperationComponent); - // fixture.detectChanges(); - // tree = fixture.debugElement.query(By.directive(XTreeComponent)); - // }); - // it('should create.', () => { - // expect(tree).toBeDefined(); - // }); - // }); }); - -@Injectable() -class TreeServiceTest { - data: XTreeNode[] = [ - { id: 1, label: '一级 1', nowrap: false, alignItems: 'start' }, - { id: 2, label: '一级 2', height: '3rem' }, - { id: 3, label: '一级 3' }, - { id: 5, label: '二级 1-1', pid: 1 }, - { id: 6, label: '二级 1-2', pid: 1 }, - { id: 7, label: '二级 1-3', pid: 1 }, - { id: 8, label: '二级 1-4', pid: 1, disabled: true }, - { id: 9, label: '二级 2-1', pid: 2 }, - { id: 10, label: '二级 2-2', pid: 2 }, - { id: 11, label: '二级 2-3', pid: 2 }, - { id: 12, label: '二级 2-4', pid: 2 }, - { id: 13, label: '二级 3-1', pid: 3 }, - { id: 14, label: '二级 3-2', pid: 3 }, - { id: 15, label: '二级 3-3', pid: 3, disabled: true }, - { id: 16, label: '二级 3-4', pid: 3 }, - { id: 21, label: '三级 1-1-1', pid: 5 }, - { id: 22, label: '三级 1-1-2', pid: 5 }, - { id: 23, label: '三级 1-1-3', pid: 5 }, - { id: 24, label: '三级 1-1-4', pid: 5 } - ]; - - getTreeList = (pid = undefined): Observable => { - return new Observable((x) => { - let result = this.data - .filter((y) => y.pid === pid) - .map((x) => { - x.leaf = this.data.find((y) => y.pid === x.id) ? true : false; - return x; - }); - setTimeout(() => { - x.next(result); - x.complete(); - }, 500); - }); - }; -} - -@Component({ - template: ` - - - - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 1rem; - } - ` - ], - providers: [TreeServiceTest] -}) -class TestXTreeComponent { - constructor(public service: TreeServiceTest) {} -} - -@Component({ - template: ` - - - - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 1rem; - } - ` - ], - providers: [TreeServiceTest] -}) -class TestXTreeLazyComponent { - constructor(public service: TreeServiceTest) {} -} - -@Component({ - template: ` - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 1rem; - } - ` - ], - providers: [TreeServiceTest] -}) -class TestXTreeCheckedComponent { - constructor(public service: TreeServiceTest) {} -} - -@Component({ - template: ` - - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 1rem; - } - ` - ], - providers: [TreeServiceTest] -}) -class TestXTreeDiabledComponent { - constructor(public service: TreeServiceTest) {} -} - -@Component({ - template: ` - - - - - -
- {{ node.label }} - - 新增 - 修改 - 删除 - -
-
-
-
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 1rem; - } - .custom-label { - display: flex; - align-items: center; - } - .custom-links { - margin-left: 1rem; - } - .custom-links x-link:not(:first-child) { - margin-left: 1rem; - } - ` - ], - providers: [TreeServiceTest] -}) -class TestXTreeCustomComponent { - constructor(public service: TreeServiceTest) {} -} - -@Component({ - template: ` - - - -
    -
  • 当前激活的节点:{{ activatedNode?.label }}
  • -
  • - 通过 Key 值设置选中的节点 -
  • -
  • 获取选中的节点的 Key 值
  • -
  • - {{ expandedAll ? '全部收起' : '全部展开' }} -
  • -
  • {{ content | json }}
  • -
-
- - - - -
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 1rem; - } - .operations > li:not(:first-child) { - margin-top: 1rem; - } - ` - ], - providers: [TreeServiceTest] -}) -class TestXTreeEventComponent { - treeCom = viewChild.required('treeCom'); - activatedNode!: XTreeNode; - selectedNodes: XTreeNode[] = []; - expandedAll: boolean = true; - content: any; - constructor(public service: TreeServiceTest) {} - - activatedChange(node: XTreeNode) { - this.activatedNode = node; - } - - getCheckedKeys() { - this.content = this.treeCom().getCheckedKeys(); - } - - setCheckedKeys(keys = []) { - this.treeCom().setCheckedKeys(keys); - } - - setExpandedAll() { - this.expandedAll = !this.expandedAll; - } -} - -@Injectable() -class OrganizationService extends XRepositoryService { - constructor(public override http: XHttpService) { - super(http, { api: 'http://localhost:3000/', controller: { name: 'organization' } }); - } -} - -interface Organization extends XTreeNode { - label?: string; - type?: string; - icon?: string; - pid?: string; - path?: string; -} - -@Component({ - template: ` - - - - 添加根节点 - - - - - -
- - - 确 认 - - 取 消 - -
-
-
- `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .row:not(:first-child) { - margin-top: 1rem; - } - .operations > li:not(:first-child) { - margin-top: 1rem; - } - ` - ], - providers: [OrganizationService] -}) -class TestXTreeOperationComponent { - treeCom = viewChild.required('treeCom'); - formGroup = new UntypedFormGroup({}); - - get disabled() { - return !['edit', 'add', 'add-root'].includes(this.type); - } - - type = 'info'; - - selected!: Organization; - - activatedId!: string; - - data = () => this.service.getList(1, Number.MAX_SAFE_INTEGER).pipe(map((x) => x.list)); - - actions: XTreeAction[] = [ - { - id: 'add', - label: '新增', - icon: 'fto-plus-square', - handler: (node: Organization) => { - this.action('add', node); - } - }, - { - id: 'edit', - label: '修改', - icon: 'fto-edit', - handler: (node: Organization) => { - this.action('edit', node); - } - }, - { - id: 'delete', - label: '删除', - icon: 'fto-trash-2', - handler: (node: Organization) => { - this.action('delete', node); - } - } - ]; - - controls: XFormRow[] = [ - { - controls: [ - { - control: 'input', - id: 'label', - label: '名称', - required: true - }, - { control: 'input', id: 'icon', label: '图标' }, - { - control: 'select', - id: 'type', - label: '类型', - data: [ - { id: 'group', label: '事业部' }, - { id: 'subsidiary', label: '子公司' }, - { id: 'department', label: '部门' } - ], - value: 'department' - } - ] - }, - { - hidden: true, - controls: [ - { - control: 'input', - id: 'id' - }, - { - control: 'input', - id: 'pid' - } - ] - } - ]; - constructor( - private service: OrganizationService, - private message: XMessageService, - private cdr: ChangeDetectorRef - ) {} - - action(type: string, node: Organization) { - switch (type) { - case 'info': - this.type = type; - this.selected = node; - this.service.get(node?.id).subscribe((x) => { - this.formGroup.patchValue(x); - this.cdr.detectChanges(); - }); - break; - case 'add': - this.type = type; - this.selected = node; - this.formGroup.reset(); - this.formGroup.patchValue({ - id: XGuid(), - pid: node.id, - type: 'department' - }); - this.cdr.detectChanges(); - break; - case 'add-root': - this.type = type; - this.formGroup.reset(); - this.formGroup.patchValue({ - id: XGuid(), - pid: null, - type: '' - }); - this.cdr.detectChanges(); - break; - case 'edit': - this.type = type; - this.service.get(node?.id).subscribe((x) => { - this.formGroup.patchValue(x); - this.cdr.detectChanges(); - }); - break; - case 'delete': - this.service.delete(node.id).subscribe(() => { - this.treeCom().removeNode(node); - this.formGroup.reset(); - this.message.success('删除成功!'); - }); - break; - case 'save': - if (this.type === 'add' || this.type === 'add-root') { - this.service.post(this.formGroup.value).subscribe((x) => { - this.type = 'info'; - this.treeCom().addNode(x); - this.cdr.detectChanges(); - this.message.success('新增成功!'); - }); - } else if (this.type === 'edit') { - this.service.put(this.formGroup.value).subscribe(() => { - this.type = 'info'; - this.treeCom().updateNode(node, this.formGroup.value); - this.cdr.detectChanges(); - this.message.success('修改成功!'); - }); - } - break; - case 'cancel': - break; - } - } -} diff --git a/lib/ng-nest/ui/upload/upload.component.spec.ts b/lib/ng-nest/ui/upload/upload.component.spec.ts index 537a26aed..6d2dbf790 100644 --- a/lib/ng-nest/ui/upload/upload.component.spec.ts +++ b/lib/ng-nest/ui/upload/upload.component.spec.ts @@ -1,35 +1,85 @@ -import { XButtonComponent } from '@ng-nest/ui/button'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Component, DebugElement, provideExperimentalZonelessChangeDetection } from '@angular/core'; +import { Component, provideExperimentalZonelessChangeDetection, signal } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { XRowComponent, XColComponent } from '@ng-nest/ui/layout'; -import { XUploadComponent } from '@ng-nest/ui/upload'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { XUploadPrefix } from './upload.property'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { XIconComponent } from '@ng-nest/ui/icon'; +import { XUploadComponent, XUploadMultipleModel, XUploadNode, XUploadPrefix, XUploadType } from '@ng-nest/ui/upload'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { XTemplate } from '@ng-nest/ui/core'; + +@Component({ + standalone: true, + imports: [XUploadComponent], + template: ` ` +}) +class XTestUploadComponent {} + +@Component({ + standalone: true, + imports: [XUploadComponent], + template: ` + + + ` +}) +class XTestUploadPropertyComponent { + text = signal(null); + action = signal(''); + accept = signal(''); + type = signal('list'); + imgFallback = signal(''); + imgCut = signal(false); + multiple = signal(false); + download = signal(true); + multipleModel = signal('cover'); + filesTpl = signal(null); + maxLimit = signal(-1); + headers = signal<{ [key: string]: any } | null>(null); + + removeClickResult = signal<{ file: XUploadNode; index: number } | null>(null); + removeClick(item: { file: XUploadNode; index: number }) { + this.removeClickResult.set(item); + } + + uploadReadyResult = signal(null); + uploadReady(node: XUploadNode) { + this.uploadReadyResult.set(node); + } + uploadingResult = signal(null); + uploading(node: XUploadNode) { + this.uploadingResult.set(node); + } + uploadSuccessResult = signal(null); + uploadSuccess(node: XUploadNode) { + this.uploadSuccessResult.set(node); + } + uploadErrorResult = signal(null); + uploadError(node: XUploadNode) { + this.uploadErrorResult.set(node); + } +} describe(XUploadPrefix, () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ - TestXUploadComponent, - TestXUploadDisabledComponent, - TestXUploadImgComponent, - TestXUploadImgCutComponent - ], - imports: [ - BrowserAnimationsModule, - FormsModule, - ReactiveFormsModule, - XIconComponent, - XUploadComponent, - XButtonComponent, - XRowComponent, - XColComponent - ], + imports: [XTestUploadComponent, XTestUploadPropertyComponent], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -37,198 +87,75 @@ describe(XUploadPrefix, () => { ] }).compileComponents(); }); - describe(`default.`, () => { - let fixture: ComponentFixture; - let upload: DebugElement; + describe('default.', () => { + let fixture: ComponentFixture; beforeEach(() => { - fixture = TestBed.createComponent(TestXUploadComponent); + fixture = TestBed.createComponent(XTestUploadComponent); fixture.detectChanges(); - upload = fixture.debugElement.query(By.directive(XUploadComponent)); }); - it('should create.', () => { - expect(upload).toBeDefined(); + it('define.', () => { + const com = fixture.debugElement.query(By.directive(XUploadComponent)); + expect(com).toBeDefined(); }); }); - describe(`img.`, () => { - let fixture: ComponentFixture; - let upload: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXUploadImgComponent); + describe(`input.`, async () => { + let fixture: ComponentFixture; + // let component: XTestUploadPropertyComponent; + beforeEach(async () => { + fixture = TestBed.createComponent(XTestUploadPropertyComponent); + // component = fixture.componentInstance; fixture.detectChanges(); - upload = fixture.debugElement.query(By.directive(XUploadComponent)); }); - it('should create.', () => { - expect(upload).toBeDefined(); + it('text.', () => { + expect(true).toBe(true); }); - }); - describe(`imgCut.`, () => { - let fixture: ComponentFixture; - let upload: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXUploadImgCutComponent); - fixture.detectChanges(); - upload = fixture.debugElement.query(By.directive(XUploadComponent)); + it('action.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(upload).toBeDefined(); + it('accept.', () => { + expect(true).toBe(true); }); - }); - describe(`disabled.`, () => { - let fixture: ComponentFixture; - let upload: DebugElement; - beforeEach(() => { - fixture = TestBed.createComponent(TestXUploadDisabledComponent); - fixture.detectChanges(); - upload = fixture.debugElement.query(By.directive(XUploadComponent)); + it('type.', () => { + expect(true).toBe(true); + }); + it('imgFallback.', () => { + expect(true).toBe(true); + }); + it('imgCut.', () => { + expect(true).toBe(true); + }); + it('multiple.', () => { + expect(true).toBe(true); + }); + it('download.', () => { + expect(true).toBe(true); + }); + it('multipleModel.', () => { + expect(true).toBe(true); + }); + it('filesTpl.', () => { + expect(true).toBe(true); + }); + it('maxLimit.', () => { + expect(true).toBe(true); + }); + it('headers.', () => { + expect(true).toBe(true); + }); + it('removeClick.', () => { + expect(true).toBe(true); }); - it('should create.', () => { - expect(upload).toBeDefined(); + it('uploadReady.', () => { + expect(true).toBe(true); + }); + it('uploading.', () => { + expect(true).toBe(true); + }); + it('uploadSuccess.', () => { + expect(true).toBe(true); + }); + it('uploadError.', () => { + expect(true).toBe(true); }); }); }); - -@Component({ - template: ` - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - x-row > x-col { - width: 14rem; - } - ` - ] -}) -class TestXUploadComponent { - model = []; -} - -@Component({ - template: ` - - - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXUploadDisabledComponent { - model: any; -} - -@Component({ - template: ` - - - - - - - 选择图片 - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .upload-icon { - font-size: 1.325rem; - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - x-row > x-col { - width: 14rem; - } - ` - ] -}) -class TestXUploadImgComponent { - model = []; -} - -@Component({ - template: ` - - - - - - - 选择图片 - - - - `, - styles: [ - ` - :host { - background-color: var(--x-background); - padding: 1rem; - border: 0.0625rem solid var(--x-border); - } - .upload-icon { - font-size: 1.325rem; - } - x-row > x-col:not(:first-child) { - margin-top: 1rem; - } - ` - ] -}) -class TestXUploadImgCutComponent { - files = [ - { - name: '3.png', - url: 'http://127.0.0.1:3000/upload/1614515464461-56.png' - }, - { - name: '2.png', - url: 'http://127.0.0.1:3000/upload/1614515464444-2.png' - }, - { - name: '4.png', - url: 'http://127.0.0.1:3000/upload/1614515464469-4.png' - }, - { - name: '433.png', - url: 'http://127.0.0.1:3000/upload/1614515464498-433.png' - } - ]; -} diff --git a/package-lock.json b/package-lock.json index 4f0974833..ecd98be75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ng-nest", - "version": "18.0.6", + "version": "18.0.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ng-nest", - "version": "18.0.6", + "version": "18.0.8", "dependencies": { "@angular/animations": "^18.2.0", "@angular/cdk": "^18.2.0", @@ -16978,6 +16978,116 @@ "resolved": "https://registry.npmmirror.com/tslib/-/tslib-2.7.0.tgz", "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==" }, + "node_modules/tslint": { + "version": "6.1.3", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-6.1.3.tgz", + "integrity": "sha512-IbR4nkT96EQOvKE2PW/djGz8iGNeJ4rF2mBfiYaR/nvUWYKJhLwimoJKgjIFEIDibBtOevj7BqCRL4oHeWWUCg==", + "deprecated": "TSLint has been deprecated in favor of ESLint. Please see https://github.com/palantir/tslint/issues/4534 for more information.", + "dev": true, + "peer": true, + "dependencies": { + "@babel/code-frame": "^7.0.0", + "builtin-modules": "^1.1.1", + "chalk": "^2.3.0", + "commander": "^2.12.1", + "diff": "^4.0.1", + "glob": "^7.1.1", + "js-yaml": "^3.13.1", + "minimatch": "^3.0.4", + "mkdirp": "^0.5.3", + "resolve": "^1.3.2", + "semver": "^5.3.0", + "tslib": "^1.13.0", + "tsutils": "^2.29.0" + }, + "bin": { + "tslint": "bin/tslint" + }, + "engines": { + "node": ">=4.8.0" + }, + "peerDependencies": { + "typescript": ">=2.3.0-dev || >=2.4.0-dev || >=2.5.0-dev || >=2.6.0-dev || >=2.7.0-dev || >=2.8.0-dev || >=2.9.0-dev || >=3.0.0-dev || >= 3.1.0-dev || >= 3.2.0-dev || >= 4.0.0-dev" + } + }, + "node_modules/tslint/node_modules/argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, + "peer": true, + "dependencies": { + "sprintf-js": "~1.0.2" + } + }, + "node_modules/tslint/node_modules/builtin-modules": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", + "integrity": "sha512-wxXCdllwGhI2kCC0MnvTGYTMvnVZTvqgypkiTI8Pa5tcz2i6VqsqwYGgqwXji+4RgCzms6EajE4IxiUH6HH8nQ==", + "dev": true, + "peer": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tslint/node_modules/js-yaml": { + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", + "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", + "dev": true, + "peer": true, + "dependencies": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/tslint/node_modules/semver": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", + "dev": true, + "peer": true, + "bin": { + "semver": "bin/semver" + } + }, + "node_modules/tslint/node_modules/sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==", + "dev": true, + "peer": true + }, + "node_modules/tslint/node_modules/tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true, + "peer": true + }, + "node_modules/tsutils": { + "version": "2.29.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", + "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", + "dev": true, + "peer": true, + "dependencies": { + "tslib": "^1.8.1" + }, + "peerDependencies": { + "typescript": ">=2.1.0 || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >=2.4.0-dev || >=2.5.0-dev || >=2.6.0-dev || >=2.7.0-dev || >=2.8.0-dev || >=2.9.0-dev || >= 3.0.0-dev || >= 3.1.0-dev" + } + }, + "node_modules/tsutils/node_modules/tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true, + "peer": true + }, "node_modules/tuf-js": { "version": "2.2.1", "resolved": "https://registry.npmmirror.com/tuf-js/-/tuf-js-2.2.1.tgz",