Skip to content

Commit

Permalink
feat(ng-dev): add ComponentContextNext. This will replace `Componen…
Browse files Browse the repository at this point in the history
…tContext` in a future major version release. See migration notes in the class-level docs for `ComponentContext`. Closes #15.
  • Loading branch information
ersimont committed Dec 26, 2020
1 parent bc259ec commit 90bc99f
Show file tree
Hide file tree
Showing 24 changed files with 944 additions and 208 deletions.
3 changes: 3 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion TODO.md
@@ -1,5 +1,8 @@
- add support/help for `--tag next` to `publish-libs.ts`
- Investigate error while build `ng-dev`:
> WARNING: No name was provided for external module '@s-libs/js-core' in output.globals – guessing 'jsCore'
> WARNING: No name was provided for external module '@s-libs/micro-dash' in output.globals – guessing 'microDash'
- landing page to link to all API docs
- Set width/height/border for the wrapper component in `ComponentContextNext`
- coveralls
- help may be here, to combine multiple coverage runs into one report: https://github.com/angular/angular-cli/issues/11268
- Watch for when typedoc can support that "lib" mode that would eliminate the need for @hidden
47 changes: 20 additions & 27 deletions projects/integration/src/app/api-tests/ng-core.spec.ts
Expand Up @@ -24,7 +24,7 @@ import {
provideValueAccessor,
WrappedFormControlSuperclass,
} from '@s-libs/ng-core';
import { ComponentContext, expectSingleCallAndReset } from '@s-libs/ng-dev';
import { ComponentContextNext, expectSingleCallAndReset } from '@s-libs/ng-dev';
import { BehaviorSubject, combineLatest, Observable, Subject } from 'rxjs';
import { map } from 'rxjs/operators';

Expand Down Expand Up @@ -122,13 +122,12 @@ describe('ng-core', () => {
}
}

class TestComponentContext extends ComponentContext<TestComponent> {
class TestComponentContext extends ComponentContextNext<TestComponent> {
color$ = new BehaviorSubject('Grey');
protected componentType = TestComponent;

constructor() {
super({
declarations: [ColorTextComponent, TestComponent],
super(TestComponent, {
declarations: [ColorTextComponent],
providers: [
{ provide: 'color$', useFactory: () => this.color$ },
// this can go away with component harnesses eventually
Expand Down Expand Up @@ -212,8 +211,8 @@ describe('ng-core', () => {
`,
})
class TestComponent {
@Input() string = '';
emissions = 0;
string = '';
date = new Date();
shouldDisable = false;
}
Expand Down Expand Up @@ -255,13 +254,11 @@ describe('ng-core', () => {
}
}

class TestComponentContext extends ComponentContext<TestComponent> {
protected componentType = TestComponent;

class TestComponentContext extends ComponentContextNext<TestComponent> {
constructor() {
super({
super(TestComponent, {
imports: [FormsModule, ReactiveFormsModule],
declarations: [DateComponent, StringComponent, TestComponent],
declarations: [DateComponent, StringComponent],
// this can go away with component harnesses eventually
providers: [
{ provide: ComponentFixtureAutoDetect, useValue: true },
Expand Down Expand Up @@ -294,11 +291,11 @@ describe('ng-core', () => {
flushMicrotasks();
}

ctx.run({ input: { string: 'initial value' } }, () => {
ctx.run({ inputs: { string: 'initial value' } }, () => {
expect(stringInput().value).toBe('initial value');

setValue(stringInput(), 'edited value');
expect(ctx.fixture.componentInstance.string).toBe('edited value');
expect(ctx.getComponentInstance().string).toBe('edited value');
});
});

Expand All @@ -319,8 +316,8 @@ describe('ng-core', () => {
`,
})
class TestComponent {
value = 0;
shouldDisable = false;
@Input() value = 0;
@Input() shouldDisable = false;
}

@Component({
Expand Down Expand Up @@ -350,13 +347,11 @@ describe('ng-core', () => {
}
}

class TestComponentContext extends ComponentContext<TestComponent> {
protected componentType = TestComponent;

class TestComponentContext extends ComponentContextNext<TestComponent> {
constructor() {
super({
super(TestComponent, {
imports: [FormsModule],
declarations: [CounterComponent, TestComponent],
declarations: [CounterComponent],
// this can go away with component harnesses eventually
providers: [
{ provide: ComponentFixtureAutoDetect, useValue: true },
Expand Down Expand Up @@ -410,7 +405,7 @@ describe('ng-core', () => {
flushMicrotasks();
}

ctx.run({ input: { shouldDisable: true } }, () => {
ctx.run({ inputs: { shouldDisable: true } }, () => {
expect(incrementButton().disabled).toBe(true);

click(toggleDisabledButton());
Expand Down Expand Up @@ -445,14 +440,12 @@ describe('ng-core', () => {
showThings = true;
}

class TestComponentContext extends ComponentContext<TestComponent> {
class TestComponentContext extends ComponentContextNext<TestComponent> {
subject = new Subject();

protected componentType = TestComponent;

constructor() {
super({
declarations: [DestroyableDirective, TestComponent],
super(TestComponent, {
declarations: [DestroyableDirective],
providers: [{ provide: Subject, useFactory: () => this.subject }],
});
}
Expand All @@ -461,7 +454,7 @@ describe('ng-core', () => {
ctx.run(() => {
expect(ctx.subject.observers.length).toBe(2);

ctx.fixture.componentInstance.showThings = false;
ctx.getComponentInstance().showThings = false;
ctx.fixture.detectChanges();
expect(ctx.subject.observers.length).toBe(0);
});
Expand Down
5 changes: 5 additions & 0 deletions projects/integration/src/app/api-tests/ng-dev.spec.ts
Expand Up @@ -2,6 +2,7 @@ import {
AngularContext,
AsyncMethodController,
ComponentContext,
ComponentContextNext,
TestCall,
createSpyObject,
expectCallsAndReset,
Expand All @@ -25,6 +26,10 @@ describe('ng-dev', () => {
expect(ComponentContext).toBeDefined();
});

it('has ComponentContextNext', () => {
expect(ComponentContextNext).toBeDefined();
});

it('has TestCall', () => {
expect(TestCall).toBeDefined();
});
Expand Down

0 comments on commit 90bc99f

Please sign in to comment.