Skip to content

Commit

Permalink
test(module:*): deprecate internal APIs and remove references (#8870)
Browse files Browse the repository at this point in the history
  • Loading branch information
Laffery authored Nov 12, 2024
1 parent 41f6609 commit 472bb34
Show file tree
Hide file tree
Showing 16 changed files with 788 additions and 722 deletions.
40 changes: 24 additions & 16 deletions components/button/button-group.spec.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
import { BidiModule, Dir, Direction } from '@angular/cdk/bidi';
import { Component, Input, ViewChild } from '@angular/core';
import { fakeAsync } from '@angular/core/testing';
import { fakeAsync, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';

import { ɵcreateComponentBed as createComponentBed } from 'ng-zorro-antd/core/testing';

import { NzButtonGroupComponent, NzButtonGroupSize } from './button-group.component';

describe('button-group', () => {
it('should button group size work', () => {
const testBed = createComponentBed(TestButtonGroupComponent, { imports: [NzButtonGroupComponent] });
const buttonGroupElement = testBed.debugElement.query(By.directive(NzButtonGroupComponent)).nativeElement;
const fixture = TestBed.createComponent(TestButtonGroupComponent);
const component = fixture.componentInstance;

const buttonGroupElement = fixture.debugElement.query(By.directive(NzButtonGroupComponent)).nativeElement;
expect(buttonGroupElement.className).toBe('ant-btn-group');
testBed.component.nzSize = 'large';
testBed.fixture.detectChanges();

component.nzSize = 'large';
fixture.detectChanges();
expect(buttonGroupElement.classList).toContain('ant-btn-group-lg');
testBed.component.nzSize = 'small';
testBed.fixture.detectChanges();

component.nzSize = 'small';
fixture.detectChanges();
expect(buttonGroupElement.classList).toContain('ant-btn-group-sm');
});

it('should RTL classname work', fakeAsync(() => {
const testBed = createComponentBed(NzTestButtonGroupRtlComponent, {
imports: [BidiModule, NzButtonGroupComponent]
});
const buttonGroupElement = testBed.debugElement.query(By.directive(NzButtonGroupComponent)).nativeElement;
const fixture = TestBed.createComponent(NzTestButtonGroupRtlComponent);
const component = fixture.componentInstance;

fixture.detectChanges();
const buttonGroupElement = fixture.debugElement.query(By.directive(NzButtonGroupComponent)).nativeElement;
expect(buttonGroupElement.className).toBe('ant-btn-group ant-btn-group-rtl');
testBed.component.direction = 'ltr';
testBed.fixture.detectChanges();

component.direction = 'ltr';
fixture.detectChanges();
expect(buttonGroupElement.className).toBe('ant-btn-group');
}));
});

@Component({
template: ` <nz-button-group [nzSize]="nzSize"></nz-button-group> `
standalone: true,
imports: [NzButtonGroupComponent],
template: `<nz-button-group [nzSize]="nzSize"></nz-button-group>`
})
export class TestButtonGroupComponent {
@Input() nzSize: NzButtonGroupSize = 'default';
}

@Component({
standalone: true,
imports: [BidiModule, NzButtonGroupComponent],
template: `
<div [dir]="direction">
<nz-button-group></nz-button-group>
Expand Down
87 changes: 43 additions & 44 deletions components/color-picker/color-block.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,63 @@
import { Component, DebugElement } from '@angular/core';
import { ComponentFixture } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { provideNoopAnimations } from '@angular/platform-browser/animations';

import { NzColorBlockComponent, NzColorPickerModule } from 'ng-zorro-antd/color-picker';
import { ComponentBed, createComponentBed } from 'ng-zorro-antd/core/testing/component-bed';
import { NzSizeLDSType } from 'ng-zorro-antd/core/types';

describe('nz-color-block', () => {
describe('basic', () => {
let testBed: ComponentBed<NzTestColorBlockComponent>;
let fixture: ComponentFixture<NzTestColorBlockComponent>;
let testComponent: NzTestColorBlockComponent;
let resultEl: DebugElement;
let fixture: ComponentFixture<NzTestColorBlockComponent>;
let component: NzTestColorBlockComponent;
let resultEl: DebugElement;

beforeEach(() => {
testBed = createComponentBed(NzTestColorBlockComponent, {
imports: [NzColorPickerModule]
});
fixture = testBed.fixture;
fixture.detectChanges();
testComponent = testBed.component;
resultEl = fixture.debugElement.query(By.directive(NzColorBlockComponent));
beforeEach(() => {
TestBed.configureTestingModule({
providers: [provideNoopAnimations()]
});
fixture = TestBed.createComponent(NzTestColorBlockComponent);
fixture.detectChanges();
component = fixture.componentInstance;
resultEl = fixture.debugElement.query(By.directive(NzColorBlockComponent));
});

it('color-block basic', () => {
fixture.detectChanges();
const colorDom = resultEl.nativeElement.querySelector('.ant-color-picker-color-block-inner');
expect(colorDom.style.backgroundColor).toBe('rgb(22, 119, 255)');
});
it('color-block basic', () => {
fixture.detectChanges();
const colorDom = resultEl.nativeElement.querySelector('.ant-color-picker-color-block-inner');
expect(colorDom.style.backgroundColor).toBe('rgb(22, 119, 255)');
});

it('color-block color', () => {
testComponent.nzColor = '#ff6600';
fixture.detectChanges();
expect(resultEl.nativeElement.querySelector('.ant-color-picker-color-block-inner').style.backgroundColor).toBe(
'rgb(255, 102, 0)'
);
});
it('color-block color', () => {
component.nzColor = '#ff6600';
fixture.detectChanges();
expect(resultEl.nativeElement.querySelector('.ant-color-picker-color-block-inner').style.backgroundColor).toBe(
'rgb(255, 102, 0)'
);
});

it('color-block size', () => {
testComponent.nzSize = 'small';
fixture.detectChanges();
expect(resultEl.nativeElement.querySelector('ng-antd-color-block').parentNode.classList).toContain(
'ant-color-picker-inline-sm'
);
testComponent.nzSize = 'large';
fixture.detectChanges();
expect(resultEl.nativeElement.querySelector('ng-antd-color-block').parentNode.classList).toContain(
'ant-color-picker-inline-lg'
);
});
it('color-block size', () => {
component.nzSize = 'small';
fixture.detectChanges();
expect(resultEl.nativeElement.querySelector('ng-antd-color-block').parentNode.classList).toContain(
'ant-color-picker-inline-sm'
);
component.nzSize = 'large';
fixture.detectChanges();
expect(resultEl.nativeElement.querySelector('ng-antd-color-block').parentNode.classList).toContain(
'ant-color-picker-inline-lg'
);
});

it('color-block click', () => {
fixture.detectChanges();
resultEl.nativeElement.querySelector('.ant-color-picker-color-block').click();
expect(testComponent.isClick).toBeTrue();
});
it('color-block click', () => {
fixture.detectChanges();
resultEl.nativeElement.querySelector('.ant-color-picker-color-block').click();
expect(component.isClick).toBeTrue();
});
});

@Component({
standalone: true,
imports: [NzColorPickerModule],
template: `
<nz-color-block [nzColor]="nzColor" [nzSize]="nzSize" (nzOnClick)="clickHandle($event)"></nz-color-block>
`
Expand Down
Loading

0 comments on commit 472bb34

Please sign in to comment.