Skip to content

Commit a8f1137

Browse files
devversionjelbourn
authored andcommitted
build: better sharing of material test utilities (#13885)
* The slide toggle tests no longer import the test gesture config from `../slider/` * The datepicker month constants from `@angular/material/core` have been moved to `lib/testing`. The old export from `core` will be kept for backwards compatibility until V8
1 parent 2133948 commit a8f1137

24 files changed

+86
-58
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
/src/lib/stepper/** @mmalerba
3434
/src/lib/table/** @andrewseguin
3535
/src/lib/tabs/** @andrewseguin
36+
/src/lib/testing/** @jelbourn
3637
/src/lib/toolbar/** @devversion
3738
/src/lib/tooltip/** @andrewseguin
3839
/src/lib/tree/** @jelbourn @andrewseguin
@@ -52,7 +53,6 @@
5253
/src/lib/core/selection/** @jelbourn
5354
/src/lib/core/selection/pseudo*/** @crisbeto @jelbourn
5455
/src/lib/core/style/** @jelbourn
55-
/src/lib/core/testing/** @jelbourn
5656
/src/lib/core/theming/** @jelbourn
5757
/src/lib/core/typography/** @crisbeto
5858
/src/lib/core/util/** @jelbourn

src/lib/core/BUILD.bazel

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,11 @@ ng_test_library(
102102
deps = [
103103
"@angular//packages/platform-browser",
104104
"@angular//packages/platform-browser/animations",
105+
"//src/cdk/keycodes",
105106
"//src/cdk/platform",
106107
"//src/cdk/testing",
107-
"//src/cdk/keycodes",
108-
"//src/lib/core",
108+
"//src/lib/testing",
109+
":core",
109110
]
110111
)
111112

src/lib/core/datetime/native-date-adapter.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Platform} from '@angular/cdk/platform';
22
import {LOCALE_ID} from '@angular/core';
33
import {async, inject, TestBed} from '@angular/core/testing';
4-
import {DEC, FEB, JAN, MAR} from '../testing/month-constants';
4+
import {DEC, FEB, JAN, MAR} from '@angular/material/testing';
55
import {DateAdapter, MAT_DATE_LOCALE, NativeDateAdapter, NativeDateModule} from './index';
66

77
const SUPPORTS_INTL = typeof Intl != 'undefined';

src/lib/core/month-constants.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
/**
10+
* When constructing a Date, the month is zero-based. This can be confusing, since people are
11+
* used to seeing them one-based. So we create these aliases to make writing the tests easier.
12+
* @docs-private
13+
* @breaking-change 8.0.0 Remove this with V8 since it was only targeted for testing.
14+
*/
15+
export const JAN = 0, FEB = 1, MAR = 2, APR = 3, MAY = 4, JUN = 5, JUL = 6, AUG = 7, SEP = 8,
16+
OCT = 9, NOV = 10, DEC = 11;

src/lib/core/public-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ export * from './label/label-options';
1818
export * from './ripple/index';
1919
export * from './selection/index';
2020

21-
// TODO: don't have this
22-
export * from './testing/month-constants';
21+
// TODO(devversion): remove this with v8
22+
export * from './month-constants';

src/lib/datepicker/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ ng_test_library(
7979
"//src/lib/core",
8080
"//src/lib/form-field",
8181
"//src/lib/input",
82+
"//src/lib/testing",
8283
":datepicker",
8384
]
8485
)

src/lib/datepicker/calendar-header.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {Directionality} from '@angular/cdk/bidi';
22
import {Component} from '@angular/core';
33
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
4-
import {DEC, FEB, JAN, MatNativeDateModule} from '@angular/material/core';
4+
import {MatNativeDateModule} from '@angular/material/core';
5+
import {DEC, FEB, JAN} from '@angular/material/testing';
56
import {By} from '@angular/platform-browser';
67
import {MatCalendar} from './calendar';
78
import {MatDatepickerIntl} from './datepicker-intl';

src/lib/datepicker/calendar.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
} from '@angular/cdk/testing';
99
import {Component, NgZone} from '@angular/core';
1010
import {async, ComponentFixture, inject, TestBed} from '@angular/core/testing';
11-
import {DateAdapter, DEC, FEB, JAN, JUL, MatNativeDateModule, NOV} from '@angular/material/core';
11+
import {DateAdapter, MatNativeDateModule} from '@angular/material/core';
12+
import {DEC, FEB, JAN, JUL, NOV} from '@angular/material/testing';
1213
import {By} from '@angular/platform-browser';
1314
import {MatCalendar} from './calendar';
1415
import {MatDatepickerIntl} from './datepicker-intl';

src/lib/datepicker/datepicker.spec.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {ENTER, ESCAPE, RIGHT_ARROW, UP_ARROW, DOWN_ARROW} from '@angular/cdk/keycodes';
1+
import {Directionality} from '@angular/cdk/bidi';
2+
import {DOWN_ARROW, ENTER, ESCAPE, RIGHT_ARROW, UP_ARROW} from '@angular/cdk/keycodes';
23
import {Overlay, OverlayContainer} from '@angular/cdk/overlay';
34
import {ScrollDispatcher} from '@angular/cdk/scrolling';
45
import {
@@ -11,27 +12,18 @@ import {
1112
import {Component, FactoryProvider, Type, ValueProvider, ViewChild} from '@angular/core';
1213
import {ComponentFixture, fakeAsync, flush, inject, TestBed, tick} from '@angular/core/testing';
1314
import {FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms';
14-
import {
15-
DEC,
16-
JAN,
17-
JUL,
18-
JUN,
19-
MAT_DATE_LOCALE,
20-
MatNativeDateModule,
21-
NativeDateModule,
22-
SEP,
23-
} from '@angular/material/core';
15+
import {MAT_DATE_LOCALE, MatNativeDateModule, NativeDateModule} from '@angular/material/core';
2416
import {MatFormField, MatFormFieldModule} from '@angular/material/form-field';
17+
import {DEC, JAN, JUL, JUN, SEP} from '@angular/material/testing';
2518
import {By} from '@angular/platform-browser';
19+
import {BrowserDynamicTestingModule} from '@angular/platform-browser-dynamic/testing';
2620
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
2721
import {Subject} from 'rxjs';
2822
import {MatInputModule} from '../input/index';
2923
import {MatDatepicker} from './datepicker';
3024
import {MatDatepickerInput} from './datepicker-input';
3125
import {MatDatepickerToggle} from './datepicker-toggle';
3226
import {MAT_DATEPICKER_SCROLL_STRATEGY, MatDatepickerIntl, MatDatepickerModule} from './index';
33-
import {Directionality} from '@angular/cdk/bidi';
34-
import {BrowserDynamicTestingModule} from '@angular/platform-browser-dynamic/testing';
3527

3628
describe('MatDatepicker', () => {
3729
const SUPPORTS_INTL = typeof Intl != 'undefined';

src/lib/datepicker/month-view.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ import {
88
PAGE_DOWN,
99
PAGE_UP,
1010
RIGHT_ARROW,
11-
UP_ARROW,
1211
SPACE,
12+
UP_ARROW,
1313
} from '@angular/cdk/keycodes';
1414
import {dispatchFakeEvent, dispatchKeyboardEvent} from '@angular/cdk/testing';
1515
import {Component} from '@angular/core';
1616
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
17-
import {DEC, FEB, JAN, MAR, MatNativeDateModule, NOV} from '@angular/material/core';
17+
import {MatNativeDateModule} from '@angular/material/core';
18+
import {DEC, FEB, JAN, MAR, NOV} from '@angular/material/testing';
1819
import {By} from '@angular/platform-browser';
1920
import {MatCalendarBody} from './calendar-body';
2021
import {MatMonthView} from './month-view';
2122

22-
2323
describe('MatMonthView', () => {
2424
let dir: {value: Direction};
2525

0 commit comments

Comments
 (0)