Skip to content

Commit 3ec531b

Browse files
mmalerbaandrewseguin
authored andcommitted
move some things from cdk/testing to cdk/private/testing (#16621)
* move some things from cdk/testing to cdk/internal-testing this is in preparation for when we publish cdk/testing with the component harness infrastructure * rename * fix lint * address feedback
1 parent 5c87286 commit 3ec531b

File tree

81 files changed

+210
-107
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+210
-107
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
/src/cdk/coercion/** @jelbourn
6666
/src/cdk/collections/** @jelbourn @crisbeto @andrewseguin
6767
/src/cdk/drag-drop/** @crisbeto
68+
/src/cdk/private/testing/** @devversion
6869
/src/cdk/keycodes/** @jelbourn
6970
/src/cdk/layout/** @josephperrott
7071
/src/cdk/observers/** @jelbourn @crisbeto
@@ -75,7 +76,7 @@
7576
/src/cdk/scrolling/** @andrewseguin @crisbeto
7677
/src/cdk/stepper/** @mmalerba
7778
/src/cdk/table/** @andrewseguin
78-
/src/cdk/testing/** @devversion
79+
/src/cdk/testing/** @mmalerba @devversion
7980
/src/cdk/text-field/** @mmalerba
8081
/src/cdk/tree/** @jelbourn @andrewseguin
8182

src/cdk-experimental/scrolling/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ ng_e2e_test_library(
4040
name = "e2e_test_sources",
4141
srcs = glob(["**/*.e2e.spec.ts"]),
4242
deps = [
43-
"//src/cdk/testing/e2e",
43+
"//src/cdk/private/testing/e2e",
4444
],
4545
)
4646

4747
e2e_test_suite(
4848
name = "e2e_tests",
4949
deps = [
5050
":e2e_test_sources",
51-
"//src/cdk/testing/e2e",
51+
"//src/cdk/private/testing/e2e",
5252
],
5353
)

src/cdk/overlay/BUILD.bazel

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ ng_test_library(
5454
"//src/cdk/keycodes",
5555
"//src/cdk/platform",
5656
"//src/cdk/portal",
57+
"//src/cdk/private/testing",
5758
"//src/cdk/scrolling",
5859
"//src/cdk/testing",
5960
"@npm//@angular/common",
@@ -72,15 +73,15 @@ ng_e2e_test_library(
7273
name = "e2e_test_sources",
7374
srcs = glob(["**/*.e2e.spec.ts"]),
7475
deps = [
75-
"//src/cdk/testing/e2e",
76+
"//src/cdk/private/testing/e2e",
7677
],
7778
)
7879

7980
e2e_test_suite(
8081
name = "e2e_tests",
8182
deps = [
8283
":e2e_test_sources",
83-
"//src/cdk/testing/e2e",
84+
"//src/cdk/private/testing/e2e",
8485
],
8586
)
8687

src/cdk/overlay/overlay.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
NgZone,
1111
} from '@angular/core';
1212
import {Direction, Directionality} from '@angular/cdk/bidi';
13-
import {dispatchFakeEvent, MockNgZone} from '@angular/cdk/testing';
13+
import {MockNgZone} from '@angular/cdk/private/testing';
14+
import {dispatchFakeEvent} from '@angular/cdk/testing';
1415
import {
1516
ComponentPortal,
1617
PortalModule,

src/cdk/overlay/position/connected-position-strategy.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {ComponentPortal, PortalModule} from '@angular/cdk/portal';
22
import {CdkScrollable, ScrollingModule} from '@angular/cdk/scrolling';
3-
import {MockNgZone} from '@angular/cdk/testing';
3+
import {MockNgZone} from '@angular/cdk/private/testing';
44
import {Component, ElementRef, NgModule, NgZone} from '@angular/core';
55
import {inject, TestBed} from '@angular/core/testing';
66
import {Subscription} from 'rxjs';

src/cdk/overlay/position/flexible-connected-position-strategy.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {ComponentPortal, PortalModule} from '@angular/cdk/portal';
22
import {CdkScrollable, ScrollingModule, ViewportRuler} from '@angular/cdk/scrolling';
3-
import {MockNgZone} from '@angular/cdk/testing';
3+
import {MockNgZone} from '@angular/cdk/private/testing';
44
import {Component, ElementRef, NgModule, NgZone} from '@angular/core';
55
import {inject, TestBed} from '@angular/core/testing';
66
import {Subscription} from 'rxjs';

src/cdk/overlay/position/global-position-strategy.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {NgModule, NgZone, Component} from '@angular/core';
22
import {TestBed, inject} from '@angular/core/testing';
3-
import {MockNgZone} from '@angular/cdk/testing';
3+
import {MockNgZone} from '@angular/cdk/private/testing';
44
import {PortalModule, ComponentPortal} from '@angular/cdk/portal';
55
import {OverlayModule, Overlay, OverlayConfig, OverlayRef, OverlayContainer} from '../index';
66

src/cdk/overlay/scroll/block-scroll-strategy.e2e.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {browser, Key, element, by} from 'protractor';
2-
import {getScrollPosition} from '@angular/cdk/testing/e2e';
2+
import {getScrollPosition} from '@angular/cdk/private/testing/e2e';
33

44

55
describe('scroll blocking', () => {

src/cdk/private/testing/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//tools:defaults.bzl", "ts_library")
4+
5+
ts_library(
6+
name = "testing",
7+
srcs = glob(
8+
["**/*.ts"],
9+
exclude = ["**/*.spec.ts"],
10+
),
11+
module_name = "@angular/cdk/private/testing",
12+
deps = [
13+
"@npm//@angular/core",
14+
],
15+
)

src/cdk/testing/e2e/BUILD.bazel renamed to src/cdk/private/testing/e2e/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ exports_files(["tsconfig-e2e.json"])
77
ng_e2e_test_library(
88
name = "e2e",
99
srcs = glob(["**/*.ts"]),
10-
module_name = "@angular/cdk/testing/e2e",
10+
module_name = "@angular/cdk/private/testing/e2e",
1111
)
File renamed without changes.
File renamed without changes.

src/cdk/private/testing/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
export * from './public-api';

src/cdk/private/testing/public-api.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
export * from './wrapped-error-message';
10+
export * from './mock-ng-zone';

src/cdk/testing/dispatch-events.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,45 @@ import {
1313
createTouchEvent
1414
} from './event-objects';
1515

16-
/** Utility to dispatch any event on a Node. */
16+
/**
17+
* Utility to dispatch any event on a Node.
18+
* @docs-private
19+
*/
1720
export function dispatchEvent(node: Node | Window, event: Event): Event {
1821
node.dispatchEvent(event);
1922
return event;
2023
}
2124

22-
/** Shorthand to dispatch a fake event on a specified node. */
25+
/**
26+
* Shorthand to dispatch a fake event on a specified node.
27+
* @docs-private
28+
*/
2329
export function dispatchFakeEvent(node: Node | Window, type: string, canBubble?: boolean): Event {
2430
return dispatchEvent(node, createFakeEvent(type, canBubble));
2531
}
2632

27-
/** Shorthand to dispatch a keyboard event with a specified key code. */
33+
/**
34+
* Shorthand to dispatch a keyboard event with a specified key code.
35+
* @docs-private
36+
*/
2837
export function dispatchKeyboardEvent(node: Node, type: string, keyCode: number, target?: Element):
2938
KeyboardEvent {
3039
return dispatchEvent(node, createKeyboardEvent(type, keyCode, target)) as KeyboardEvent;
3140
}
3241

33-
/** Shorthand to dispatch a mouse event on the specified coordinates. */
42+
/**
43+
* Shorthand to dispatch a mouse event on the specified coordinates.
44+
* @docs-private
45+
*/
3446
export function dispatchMouseEvent(node: Node, type: string, x = 0, y = 0,
3547
event = createMouseEvent(type, x, y)): MouseEvent {
3648
return dispatchEvent(node, event) as MouseEvent;
3749
}
3850

39-
/** Shorthand to dispatch a touch event on the specified coordinates. */
51+
/**
52+
* Shorthand to dispatch a touch event on the specified coordinates.
53+
* @docs-private
54+
*/
4055
export function dispatchTouchEvent(node: Node, type: string, x = 0, y = 0) {
4156
return dispatchEvent(node, createTouchEvent(type, x, y));
4257
}

src/cdk/testing/element-focus.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88

99
import {dispatchFakeEvent} from './dispatch-events';
1010

11-
/**
12-
* Patches an elements focus and blur methods to emit events consistently and predictably.
13-
* This is necessary, because some browsers, like IE11, will call the focus handlers asynchronously,
14-
* while others won't fire them at all if the browser window is not focused.
15-
*/
16-
export function patchElementFocus(element: HTMLElement) {
17-
element.focus = () => dispatchFakeEvent(element, 'focus');
18-
element.blur = () => dispatchFakeEvent(element, 'blur');
19-
}
20-
2111
function triggerFocusChange(element: HTMLElement, event: 'focus' | 'blur') {
2212
let eventFired = false;
2313
const handler = () => eventFired = true;
@@ -29,10 +19,23 @@ function triggerFocusChange(element: HTMLElement, event: 'focus' | 'blur') {
2919
}
3020
}
3121

22+
/**
23+
* Patches an elements focus and blur methods to emit events consistently and predictably.
24+
* This is necessary, because some browsers, like IE11, will call the focus handlers asynchronously,
25+
* while others won't fire them at all if the browser window is not focused.
26+
* @docs-private
27+
*/
28+
export function patchElementFocus(element: HTMLElement) {
29+
element.focus = () => dispatchFakeEvent(element, 'focus');
30+
element.blur = () => dispatchFakeEvent(element, 'blur');
31+
}
32+
33+
/** @docs-private */
3234
export function triggerFocus(element: HTMLElement) {
3335
triggerFocusChange(element, 'focus');
3436
}
3537

38+
/** @docs-private */
3639
export function triggerBlur(element: HTMLElement) {
3740
triggerFocusChange(element, 'blur');
3841
}

src/cdk/testing/event-objects.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
/** Creates a browser MouseEvent with the specified options. */
9+
/**
10+
* Creates a browser MouseEvent with the specified options.
11+
* @docs-private
12+
*/
1013
export function createMouseEvent(type: string, x = 0, y = 0, button = 0) {
1114
const event = document.createEvent('MouseEvent');
1215

@@ -33,7 +36,10 @@ export function createMouseEvent(type: string, x = 0, y = 0, button = 0) {
3336
return event;
3437
}
3538

36-
/** Creates a browser TouchEvent with the specified pointer coordinates. */
39+
/**
40+
* Creates a browser TouchEvent with the specified pointer coordinates.
41+
* @docs-private
42+
*/
3743
export function createTouchEvent(type: string, pageX = 0, pageY = 0) {
3844
// In favor of creating events that work for most of the browsers, the event is created
3945
// as a basic UI Event. The necessary details for the event will be set manually.
@@ -53,7 +59,10 @@ export function createTouchEvent(type: string, pageX = 0, pageY = 0) {
5359
return event;
5460
}
5561

56-
/** Dispatches a keydown event from an element. */
62+
/**
63+
* Dispatches a keydown event from an element.
64+
* @docs-private
65+
*/
5766
export function createKeyboardEvent(type: string, keyCode: number, target?: Element, key?: string) {
5867
let event = document.createEvent('KeyboardEvent') as any;
5968
let originalPreventDefault = event.preventDefault;
@@ -82,7 +91,10 @@ export function createKeyboardEvent(type: string, keyCode: number, target?: Elem
8291
return event;
8392
}
8493

85-
/** Creates a fake event object with any desired event type. */
94+
/**
95+
* Creates a fake event object with any desired event type.
96+
* @docs-private
97+
*/
8698
export function createFakeEvent(type: string, canBubble = false, cancelable = true) {
8799
const event = document.createEvent('Event');
88100
event.initEvent(type, canBubble, cancelable);

src/cdk/testing/public-api.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@
99
export * from './dispatch-events';
1010
export * from './event-objects';
1111
export * from './type-in-element';
12-
export * from './wrapped-error-message';
13-
export * from './mock-ng-zone';
1412
export * from './element-focus';

src/cdk/testing/type-in-element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {dispatchFakeEvent} from './dispatch-events';
1313
* the `input` event, simulating the user typing.
1414
* @param value Value to be set on the input.
1515
* @param element Element onto which to set the value.
16+
* @docs-private
1617
*/
1718
export function typeInElement(value: string, element: HTMLInputElement) {
1819
element.focus();

src/material-experimental/mdc-button/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ ng_e2e_test_library(
115115
name = "e2e_test_sources",
116116
srcs = glob(["**/*.e2e.spec.ts"]),
117117
deps = [
118-
"//src/cdk/testing/e2e",
118+
"//src/cdk/private/testing/e2e",
119119
],
120120
)
121121

122122
e2e_test_suite(
123123
name = "e2e_tests",
124124
deps = [
125125
":e2e_test_sources",
126-
"//src/cdk/testing/e2e",
126+
"//src/cdk/private/testing/e2e",
127127
],
128128
)

src/material-experimental/mdc-card/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ ng_e2e_test_library(
3535
name = "e2e_test_sources",
3636
srcs = glob(["**/*.e2e.spec.ts"]),
3737
deps = [
38-
"//src/cdk/testing/e2e",
38+
"//src/cdk/private/testing/e2e",
3939
],
4040
)
4141

4242
e2e_test_suite(
4343
name = "e2e_tests",
4444
deps = [
4545
":e2e_test_sources",
46-
"//src/cdk/testing/e2e",
46+
"//src/cdk/private/testing/e2e",
4747
],
4848
)

src/material-experimental/mdc-checkbox/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ ng_e2e_test_library(
9494
name = "e2e_test_sources",
9595
srcs = glob(["**/*.e2e.spec.ts"]),
9696
deps = [
97-
"//src/cdk/testing/e2e",
97+
"//src/cdk/private/testing/e2e",
9898
],
9999
)
100100

101101
e2e_test_suite(
102102
name = "e2e_tests",
103103
deps = [
104104
":e2e_test_sources",
105-
"//src/cdk/testing/e2e",
105+
"//src/cdk/private/testing/e2e",
106106
],
107107
)

src/material-experimental/mdc-chips/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ ng_test_library(
5757
"//src/cdk/bidi",
5858
"//src/cdk/keycodes",
5959
"//src/cdk/platform",
60+
"//src/cdk/private/testing",
6061
"//src/cdk/testing",
6162
"//src/material/core",
6263
"//src/material/form-field",

src/material-experimental/mdc-chips/chip-grid.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import {
99
SPACE,
1010
TAB
1111
} from '@angular/cdk/keycodes';
12+
import {MockNgZone} from '@angular/cdk/private/testing';
1213
import {
1314
createFakeEvent,
1415
createKeyboardEvent,
1516
dispatchFakeEvent,
1617
dispatchKeyboardEvent,
1718
dispatchMouseEvent,
18-
MockNgZone,
1919
typeInElement,
2020
} from '@angular/cdk/testing';
2121
import {

src/material-experimental/mdc-chips/chip-listbox.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import {
88
SPACE,
99
TAB,
1010
} from '@angular/cdk/keycodes';
11+
import {MockNgZone} from '@angular/cdk/private/testing';
1112
import {
1213
createKeyboardEvent,
1314
dispatchFakeEvent,
1415
dispatchKeyboardEvent,
15-
MockNgZone,
1616
} from '@angular/cdk/testing';
1717
import {
1818
Component,

0 commit comments

Comments
 (0)