Skip to content

Commit

Permalink
test(spec): update test example file
Browse files Browse the repository at this point in the history
include highlight, input, input-number, keyword and list component
  • Loading branch information
ng-nest-moon committed Oct 29, 2024
1 parent d1992e8 commit 5a38caf
Show file tree
Hide file tree
Showing 10 changed files with 571 additions and 178 deletions.
2 changes: 1 addition & 1 deletion lib/ng-nest/ui/find/find.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ describe(XFindPrefix, () => {
]);
component.model.set({ id: 1, label: 'test1', name: 'name1' });
fixture.detectChanges();
await XSleep(0);
await XSleep(100);
const tag = fixture.debugElement.query(By.css('.x-find .x-tag'));
expect(tag.nativeElement.innerText).toBe('name1');
});
Expand Down
13 changes: 8 additions & 5 deletions lib/ng-nest/ui/highlight/highlight.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,21 @@ describe(XHighlightPrefix, () => {
expect(lines[1].nativeElement).toHaveClass('primary');
});
it('showCopy.', async () => {
// Need to allow the copy and paste function of code on the browser

const html = '<span class="x-highlight"></span>';
component.showCopy.set(true);
component.data.set(html);
component.type.set('html');
fixture.detectChanges();
const copy = fixture.debugElement.query(By.css('.x-highlight-copy'));
expect(copy).toBeTruthy();
copy.nativeElement.click();
component.input().nativeElement.focus();
fixture.detectChanges();
const text = await navigator.clipboard.readText();
expect(text).toBe(html);

// copy.nativeElement.click();
// component.input().nativeElement.focus();
// fixture.detectChanges();
// const text = await navigator.clipboard.readText();
// expect(text).toBe(html);
});
});
});
7 changes: 4 additions & 3 deletions lib/ng-nest/ui/input-number/input-number.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
[placeholder]="placeholder()"
[readonly]="readonly()"
[clearable]="clearable()"
[(ngModel)]="value"
[ngModel]="displayValue()"
(ngModelChange)="change($event)"
[valueTpl]="valueTpl() ? valueTpl() : valueTemplate"
[valueTpl]="valueTpl()"
[valueTplContext]="valueTplContext()"
[size]="size()"
[min]="min()"
[max]="max()"
[bordered]="bordered()"
[before]="hiddenButton() ? '' : beforeButtonTpl"
[after]="hiddenButton() ? '' : afterButtonTpl"
Expand All @@ -60,7 +62,6 @@
flat
></x-button>
</ng-template>
<ng-template #valueTemplate>{{ displayValue() }}</ng-template>
@if (invalid()) {
<div class="x-border-error x-top-left"></div>
<div class="x-border-error x-top-right"></div>
Expand Down
84 changes: 66 additions & 18 deletions lib/ng-nest/ui/input-number/input-number.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, provideExperimentalZonelessChangeDetection, signal, TemplateRef, viewChild } from '@angular/core';
import { By } from '@angular/platform-browser';
import { XInputNumberComponent, XInputNumberPrefix } from '@ng-nest/ui/input-number';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClient, withFetch } from '@angular/common/http';
import { XAlign, XDirection, XIsNumber, XJustify, XNumber, XSize, XSleep } from '@ng-nest/ui/core';
import { provideAnimations } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';

@Component({
standalone: true,
Expand All @@ -15,9 +16,10 @@ class XTestInputNumberComponent {}

@Component({
standalone: true,
imports: [XInputNumberComponent],
imports: [XInputNumberComponent, FormsModule],
template: `
<x-input-number
[(ngModel)]="value"
[min]="min()"
[max]="max()"
[step]="step()"
Expand Down Expand Up @@ -52,6 +54,7 @@ class XTestInputNumberComponent {}
`
})
class XTestInputNumberPropertyComponent {
value = signal<number | null>(null);
min = signal(Number.MIN_SAFE_INTEGER);
max = signal(Number.MAX_SAFE_INTEGER);
step = signal(1);
Expand Down Expand Up @@ -84,11 +87,8 @@ describe(XInputNumberPrefix, () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [XTestInputNumberComponent, XTestInputNumberPropertyComponent],
providers: [
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(),
provideExperimentalZonelessChangeDetection()
]
providers: [provideAnimations, provideHttpClient(withFetch()), provideExperimentalZonelessChangeDetection()],
teardown: { destroyAfterEach: false }
}).compileComponents();
});
describe('default.', () => {
Expand All @@ -111,28 +111,76 @@ describe(XInputNumberPrefix, () => {
fixture.detectChanges();
});
it('min.', () => {
expect(true).toBe(true);
component.min.set(10);
fixture.detectChanges();
const input = fixture.debugElement.query(By.css('.x-input-frame')).nativeElement;
const min = Number(input.getAttribute('min'));
expect(min).toBe(10);
});
it('max.', () => {
expect(true).toBe(true);
component.max.set(10);
fixture.detectChanges();
const input = fixture.debugElement.query(By.css('.x-input-frame')).nativeElement;
const max = Number(input.getAttribute('max'));
expect(max).toBe(10);
});
it('step.', () => {
expect(true).toBe(true);
component.step.set(10);
fixture.detectChanges();
const plus = fixture.debugElement.query(By.css('.x-input-number-plus')).nativeElement;
plus.click();
plus.click();
fixture.detectChanges();
expect(component.value()).toBe(20);
});
it('debounce.', () => {
expect(true).toBe(true);
it('debounce.', async () => {
const plus = fixture.debugElement.query(By.css('.x-input-number-plus')).nativeElement;
plus.dispatchEvent(new MouseEvent('mousedown'));
await XSleep(550);
plus.dispatchEvent(new MouseEvent('mouseup'));
expect(component.value()).toBe(Math.floor((550 - 150) / 40) - 1);

component.debounce.set(100);
component.value.set(0);
fixture.detectChanges();
plus.dispatchEvent(new MouseEvent('mousedown'));
await XSleep(550);
plus.dispatchEvent(new MouseEvent('mouseup'));
expect(component.value()).toBe(Math.floor((550 - 150) / 100) - 1);
});
it('precision.', () => {
expect(true).toBe(true);
component.precision.set(2);
component.step.set(0.1);
fixture.detectChanges();
const plus = fixture.debugElement.query(By.css('.x-input-number-plus')).nativeElement;
plus.click();
plus.click();
fixture.detectChanges();
expect(component.value()).toBe(0.2);
});
it('bordered.', () => {
expect(true).toBe(true);
const input = fixture.debugElement.query(By.css('.x-input'));
expect(input.nativeElement).toHaveClass('x-input-bordered');

component.bordered.set(false);
fixture.detectChanges();
expect(input.nativeElement).not.toHaveClass('x-input-bordered');
});
it('formatter.', () => {
expect(true).toBe(true);
it('formatter.', async () => {
component.formatter.set((value: number): XNumber => `$ ${value}`);
component.value.set(100);
fixture.detectChanges();
await XSleep(20);
const input = fixture.debugElement.query(By.css('.x-input-frame')).nativeElement;
expect(input.value).toBe('$ 100');
});
it('hiddenButton.', () => {
expect(true).toBe(true);
component.hiddenButton.set(true);
fixture.detectChanges();
const reduce = fixture.debugElement.query(By.css('.x-input-number-reduce'));
const plus = fixture.debugElement.query(By.css('.x-input-number-plus'));
expect(reduce).toBeFalsy();
expect(plus).toBeFalsy();
});
it('size.', () => {
const input = fixture.debugElement.query(By.css('.x-input'));
Expand Down
Loading

0 comments on commit 5a38caf

Please sign in to comment.