build: add bazel test rules for remainder of packages (#21053)
PR Close #21053
This commit is contained in:
38
packages/forms/test/BUILD.bazel
Normal file
38
packages/forms/test/BUILD.bazel
Normal file
@ -0,0 +1,38 @@
|
||||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
|
||||
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
|
||||
|
||||
ts_library(
|
||||
name = "test_lib",
|
||||
testonly = 1,
|
||||
srcs = glob(["**/*.ts"]),
|
||||
tsconfig = "//packages:tsconfig",
|
||||
deps = [
|
||||
"//packages/core",
|
||||
"//packages/core/testing",
|
||||
"//packages/forms",
|
||||
"//packages/platform-browser",
|
||||
"//packages/platform-browser/testing",
|
||||
"@rxjs",
|
||||
],
|
||||
)
|
||||
|
||||
jasmine_node_test(
|
||||
name = "test",
|
||||
bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"],
|
||||
deps = [
|
||||
":test_lib",
|
||||
"//packages/_testing_init:node",
|
||||
],
|
||||
)
|
||||
|
||||
ts_web_test(
|
||||
name = "test_web",
|
||||
bootstrap = [
|
||||
"//:angular_bootstrap_scripts",
|
||||
],
|
||||
# do not sort
|
||||
deps = [
|
||||
"//packages/_testing_init:browser",
|
||||
":test_lib",
|
||||
],
|
||||
)
|
@ -10,7 +10,7 @@ import {SimpleChange} from '@angular/core';
|
||||
import {fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
|
||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {AbstractControl, CheckboxControlValueAccessor, ControlValueAccessor, DefaultValueAccessor, FormArray, FormArrayName, FormControl, FormControlDirective, FormControlName, FormGroup, FormGroupDirective, FormGroupName, NgControl, NgForm, NgModel, NgModelGroup, SelectControlValueAccessor, SelectMultipleControlValueAccessor, ValidationErrors, Validator, Validators} from '@angular/forms';
|
||||
import {composeValidators, selectValueAccessor} from '../src/directives/shared';
|
||||
import {composeValidators, selectValueAccessor} from '@angular/forms/src/directives/shared';
|
||||
import {SpyNgControl, SpyValueAccessor} from './spies';
|
||||
|
||||
class DummyControlValueAccessor implements ControlValueAccessor {
|
||||
|
@ -9,10 +9,10 @@
|
||||
import {fakeAsync, tick} from '@angular/core/testing';
|
||||
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors} from '@angular/forms';
|
||||
import {Validators} from '@angular/forms/src/validators';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
import {Validators} from '../src/validators';
|
||||
|
||||
(function(){
|
||||
(function() {
|
||||
function asyncValidator(expected: string, timeouts = {}) {
|
||||
return (c: AbstractControl) => {
|
||||
let resolve: (result: any) => void = undefined !;
|
||||
|
@ -9,7 +9,7 @@
|
||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {FormBuilder} from '@angular/forms';
|
||||
|
||||
(function(){
|
||||
(function() {
|
||||
function syncValidator(_: any /** TODO #9100 */): any /** TODO #9100 */ { return null; }
|
||||
function asyncValidator(_: any /** TODO #9100 */) { return Promise.resolve(null); }
|
||||
|
||||
|
@ -11,9 +11,9 @@ import {fakeAsync, tick} from '@angular/core/testing';
|
||||
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {FormControl, FormGroup, Validators} from '@angular/forms';
|
||||
|
||||
import {FormArray} from '../src/model';
|
||||
import {FormArray} from '@angular/forms/src/model';
|
||||
|
||||
(function(){
|
||||
(function() {
|
||||
function asyncValidator(expected: string, timeouts = {}) {
|
||||
return (c: FormControl) => {
|
||||
let resolve: (result: any) => void = undefined !;
|
||||
|
@ -13,7 +13,7 @@ import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, Va
|
||||
import {of } from 'rxjs/observable/of';
|
||||
|
||||
|
||||
(function(){
|
||||
(function() {
|
||||
function simpleValidator(c: AbstractControl): ValidationErrors|null {
|
||||
return c.get('one') !.value === 'correct' ? null : {'broken': true};
|
||||
}
|
||||
@ -1070,12 +1070,12 @@ import {of } from 'rxjs/observable/of';
|
||||
});
|
||||
|
||||
it('should update tree validity', () => {
|
||||
form._updateTreeValidity();
|
||||
(form as any)._updateTreeValidity();
|
||||
expect(logger).toEqual(['one', 'two', 'nested', 'three', 'form']);
|
||||
});
|
||||
|
||||
it('should not emit events when turned off', () => {
|
||||
form._updateTreeValidity({emitEvent: false});
|
||||
(form as any)._updateTreeValidity({emitEvent: false});
|
||||
expect(logger).toEqual([]);
|
||||
});
|
||||
|
||||
|
@ -1560,6 +1560,7 @@ import {MyInput, MyInputForm} from './value_accessor_integration_spec';
|
||||
}));
|
||||
|
||||
it('should not update the view when the value initially came from the view', fakeAsync(() => {
|
||||
if (isNode) return;
|
||||
const fixture = initTest(FormControlNgModel);
|
||||
fixture.componentInstance.control = new FormControl('');
|
||||
fixture.detectChanges();
|
||||
|
@ -295,7 +295,7 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat
|
||||
|
||||
const form = fixture.debugElement.children[0].injector.get(NgForm);
|
||||
const name = form.control.get('name') as FormControl;
|
||||
expect(name._updateOn).toBeUndefined();
|
||||
expect((name as any)._updateOn).toBeUndefined();
|
||||
expect(name.updateOn).toEqual('change');
|
||||
}));
|
||||
|
||||
@ -309,7 +309,7 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat
|
||||
|
||||
const form = fixture.debugElement.children[0].injector.get(NgForm);
|
||||
const name = form.control.get('name') as FormControl;
|
||||
expect(name._updateOn).toEqual('blur');
|
||||
expect((name as any)._updateOn).toEqual('blur');
|
||||
expect(name.updateOn).toEqual('blur');
|
||||
}));
|
||||
|
||||
@ -555,7 +555,7 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat
|
||||
|
||||
const form = fixture.debugElement.children[0].injector.get(NgForm);
|
||||
const name = form.control.get('name') as FormControl;
|
||||
expect(name._updateOn).toEqual('submit');
|
||||
expect((name as any)._updateOn).toEqual('submit');
|
||||
expect(name.updateOn).toEqual('submit');
|
||||
}));
|
||||
|
||||
@ -891,12 +891,12 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat
|
||||
|
||||
const form = fixture.debugElement.children[0].injector.get(NgForm);
|
||||
const controlOne = form.control.get('one') !as FormControl;
|
||||
expect(controlOne._updateOn).toBeUndefined();
|
||||
expect((controlOne as any)._updateOn).toBeUndefined();
|
||||
expect(controlOne.updateOn)
|
||||
.toEqual('blur', 'Expected first control to inherit updateOn from parent form.');
|
||||
|
||||
const controlTwo = form.control.get('two') !as FormControl;
|
||||
expect(controlTwo._updateOn).toBeUndefined();
|
||||
expect((controlTwo as any)._updateOn).toBeUndefined();
|
||||
expect(controlTwo.updateOn)
|
||||
.toEqual('blur', 'Expected last control to inherit updateOn from parent form.');
|
||||
}));
|
||||
@ -932,12 +932,13 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat
|
||||
|
||||
const form = fixture.debugElement.children[0].injector.get(NgForm);
|
||||
const controlOne = form.control.get('one') !as FormControl;
|
||||
expect(controlOne._updateOn).toBeUndefined();
|
||||
expect((controlOne as any)._updateOn).toBeUndefined();
|
||||
expect(controlOne.updateOn)
|
||||
.toEqual('change', 'Expected control updateOn to inherit form updateOn.');
|
||||
|
||||
const controlTwo = form.control.get('two') !as FormControl;
|
||||
expect(controlTwo._updateOn).toEqual('blur', 'Expected control to set blur override.');
|
||||
expect((controlTwo as any)._updateOn)
|
||||
.toEqual('blur', 'Expected control to set blur override.');
|
||||
expect(controlTwo.updateOn)
|
||||
.toEqual('blur', 'Expected control updateOn to override form updateOn.');
|
||||
}));
|
||||
|
@ -9,15 +9,15 @@
|
||||
import {fakeAsync, tick} from '@angular/core/testing';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {AbstractControl, AsyncValidatorFn, FormArray, FormControl, Validators} from '@angular/forms';
|
||||
import {normalizeAsyncValidator} from '@angular/forms/src/directives/normalize_validator';
|
||||
import {AsyncValidator, ValidationErrors, ValidatorFn} from '@angular/forms/src/directives/validators';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
import {timer} from 'rxjs/observable/timer';
|
||||
import {first} from 'rxjs/operator/first';
|
||||
import {map} from 'rxjs/operator/map';
|
||||
import {normalizeAsyncValidator} from '../src/directives/normalize_validator';
|
||||
import {AsyncValidator, ValidationErrors, ValidatorFn} from '../src/directives/validators';
|
||||
|
||||
(function(){
|
||||
(function() {
|
||||
function validator(key: string, error: any): ValidatorFn {
|
||||
return (c: AbstractControl) => {
|
||||
const r: ValidationErrors = {};
|
||||
|
@ -164,6 +164,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
|
||||
describe('in reactive forms', () => {
|
||||
|
||||
it(`should support primitive values`, () => {
|
||||
if (isNode) return;
|
||||
const fixture = initTest(FormControlNameSelect);
|
||||
fixture.detectChanges();
|
||||
|
||||
@ -183,6 +184,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
|
||||
});
|
||||
|
||||
it(`should support objects`, () => {
|
||||
if (isNode) return;
|
||||
const fixture = initTest(FormControlSelectNgValue);
|
||||
fixture.detectChanges();
|
||||
|
||||
@ -201,6 +203,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
|
||||
});
|
||||
|
||||
it('should compare options using provided compareWith function', () => {
|
||||
if (isNode) return;
|
||||
const fixture = initTest(FormControlSelectWithCompareFn);
|
||||
fixture.detectChanges();
|
||||
|
||||
@ -211,6 +214,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
|
||||
});
|
||||
|
||||
it('should support re-assigning the options array with compareWith', () => {
|
||||
if (isNode) return;
|
||||
const fixture = initTest(FormControlSelectWithCompareFn);
|
||||
fixture.detectChanges();
|
||||
|
||||
@ -239,6 +243,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
|
||||
|
||||
describe('in template-driven forms', () => {
|
||||
it('with option values that are objects', fakeAsync(() => {
|
||||
if (isNode) return;
|
||||
const fixture = initTest(NgModelSelectForm);
|
||||
const comp = fixture.componentInstance;
|
||||
comp.cities = [{'name': 'SF'}, {'name': 'NYC'}, {'name': 'Buffalo'}];
|
||||
@ -263,6 +268,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
|
||||
}));
|
||||
|
||||
it('when new options are added', fakeAsync(() => {
|
||||
if (isNode) return;
|
||||
const fixture = initTest(NgModelSelectForm);
|
||||
const comp = fixture.componentInstance;
|
||||
comp.cities = [{'name': 'SF'}, {'name': 'NYC'}];
|
||||
@ -300,6 +306,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
|
||||
}));
|
||||
|
||||
it('when option values have same content, but different identities', fakeAsync(() => {
|
||||
if (isNode) return;
|
||||
const fixture = initTest(NgModelSelectForm);
|
||||
const comp = fixture.componentInstance;
|
||||
comp.cities = [{'name': 'SF'}, {'name': 'NYC'}, {'name': 'NYC'}];
|
||||
@ -347,6 +354,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
|
||||
});
|
||||
|
||||
it('should compare options using provided compareWith function', fakeAsync(() => {
|
||||
if (isNode) return;
|
||||
const fixture = initTest(NgModelSelectWithCustomCompareFnForm);
|
||||
const comp = fixture.componentInstance;
|
||||
comp.selectedCity = {id: 1, name: 'SF'};
|
||||
@ -361,6 +369,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
|
||||
}));
|
||||
|
||||
it('should support re-assigning the options array with compareWith', fakeAsync(() => {
|
||||
if (isNode) return;
|
||||
const fixture = initTest(NgModelSelectWithCustomCompareFnForm);
|
||||
fixture.componentInstance.selectedCity = {id: 1, name: 'SF'};
|
||||
fixture.componentInstance.cities = [{id: 1, name: 'SF'}, {id: 2, name: 'NY'}];
|
||||
@ -400,6 +409,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
|
||||
describe('in reactive forms', () => {
|
||||
|
||||
it('should support primitive values', () => {
|
||||
if (isNode) return;
|
||||
const fixture = initTest(FormControlSelectMultiple);
|
||||
fixture.detectChanges();
|
||||
|
||||
@ -410,6 +420,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
|
||||
});
|
||||
|
||||
it('should support objects', () => {
|
||||
if (isNode) return;
|
||||
const fixture = initTest(FormControlSelectMultipleNgValue);
|
||||
fixture.detectChanges();
|
||||
|
||||
@ -427,6 +438,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
|
||||
});
|
||||
|
||||
it('should compare options using provided compareWith function', fakeAsync(() => {
|
||||
if (isNode) return;
|
||||
const fixture = initTest(FormControlSelectMultipleWithCompareFn);
|
||||
fixture.detectChanges();
|
||||
tick();
|
||||
@ -478,6 +490,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
|
||||
|
||||
it('should reflect state of model after option selected and new options subsequently added',
|
||||
fakeAsync(() => {
|
||||
if (isNode) return;
|
||||
setSelectedCities([]);
|
||||
|
||||
selectOptionViaUI('1: Object');
|
||||
@ -491,6 +504,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
|
||||
|
||||
it('should reflect state of model after option selected and then other options removed',
|
||||
fakeAsync(() => {
|
||||
if (isNode) return;
|
||||
setSelectedCities([]);
|
||||
|
||||
selectOptionViaUI('1: Object');
|
||||
@ -512,6 +526,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
|
||||
});
|
||||
|
||||
it('should compare options using provided compareWith function', fakeAsync(() => {
|
||||
if (isNode) return;
|
||||
const fixture = initTest(NgModelSelectMultipleWithCustomCompareFnForm);
|
||||
const comp = fixture.componentInstance;
|
||||
comp.cities = [{id: 1, name: 'SF'}, {id: 2, name: 'LA'}];
|
||||
|
Reference in New Issue
Block a user