Skip to content

Commit

Permalink
test(): specify test file standards
Browse files Browse the repository at this point in the history
It is also necessary to implement various input and output parameter assertions for the components
  • Loading branch information
ng-nest-moon committed Sep 12, 2024
1 parent 5f1c97a commit ae85d78
Show file tree
Hide file tree
Showing 35 changed files with 4,007 additions and 6,337 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
102 changes: 66 additions & 36 deletions lib/ng-nest/ui/page-header/page-header.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,87 @@
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: `<x-page-header></x-page-header> `
})
class XTestPageHeaderComponent {}

@Component({
standalone: true,
imports: [XPageHeaderComponent],
template: `
<x-page-header
[backIcon]="backIcon()"
[backText]="backText()"
[title]="title()"
[subTitle]="subTitle()"
(backClick)="backClick($event)"
>
</x-page-header>
`
})
class XTestPageHeaderPropertyComponent {
backIcon = signal('fto-arrow-left');
backText = signal('');
title = signal('');
subTitle = signal('');

backClickResult = signal<Event | null>(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(),
provideExperimentalZonelessChangeDetection()
]
}).compileComponents();
});
describe(`default.`, () => {
let fixture: ComponentFixture<TestXPageHeaderComponent>;
let pageheader: DebugElement;
describe('default.', () => {
let fixture: ComponentFixture<XTestPageHeaderComponent>;
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<XTestPageHeaderPropertyComponent>;
// 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: `
<div class="row">
<x-page-header title="标题" subTitle="小标题"> </x-page-header>
</div>
`,
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 {}
Loading

0 comments on commit ae85d78

Please sign in to comment.