Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit a3786ce

Browse files
committed
fix(calendar): fix broken unit tests for component rename and focus
changes.
1 parent 733431b commit a3786ce

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

src/components/calendar/calendar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515

1616
// PRE RELEASE
17-
// TODO(jelbourn): read-only state.
1817
// TODO(jelbourn): Date "isComplete" logic
1918
// TODO(jelbourn): Fix NVDA stealing key presses (IE) ???
2019

@@ -26,6 +25,7 @@
2625
// TODO(jelbourn): Previous month opacity is lowered when partially scrolled out of view.
2726
// TODO(jelbourn): Support md-calendar standalone on a page (as a tabstop w/ aria-live
2827
// announcement and key handling).
28+
// Read-only calendar (not just date-picker).
2929

3030
// COULD GO EITHER WAY
3131
// TODO(jelbourn): Clicking on the month label opens the month-picker.

src/components/calendar/calendar.spec.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ describe('md-calendar', function() {
8787
});
8888
}
8989

90+
function getFocusedDateElement() {
91+
return element.querySelector('.md-focus');
92+
}
93+
9094
beforeEach(module('material.components.calendar', 'ngAnimateMock'));
9195

9296
beforeEach(inject(function($injector) {
@@ -221,48 +225,48 @@ describe('md-calendar', function() {
221225
selectedDate.focus();
222226

223227
dispatchKeyEvent(keyCodes.LEFT_ARROW);
224-
expect(document.activeElement.textContent).toBe('10');
225-
expect(getMonthLabelForDateCell(document.activeElement)).toBe('Feb 2014');
228+
expect(getFocusedDateElement().textContent).toBe('10');
229+
expect(getMonthLabelForDateCell(getFocusedDateElement())).toBe('Feb 2014');
226230

227231
dispatchKeyEvent(keyCodes.UP_ARROW);
228-
expect(document.activeElement.textContent).toBe('3');
229-
expect(getMonthLabelForDateCell(document.activeElement)).toBe('Feb 2014');
232+
expect(getFocusedDateElement().textContent).toBe('3');
233+
expect(getMonthLabelForDateCell(getFocusedDateElement())).toBe('Feb 2014');
230234

231235
dispatchKeyEvent(keyCodes.RIGHT_ARROW);
232-
expect(document.activeElement.textContent).toBe('4');
233-
expect(getMonthLabelForDateCell(document.activeElement)).toBe('Feb 2014');
236+
expect(getFocusedDateElement().textContent).toBe('4');
237+
expect(getMonthLabelForDateCell(getFocusedDateElement())).toBe('Feb 2014');
234238

235239
dispatchKeyEvent(keyCodes.DOWN_ARROW);
236-
expect(document.activeElement.textContent).toBe('11');
237-
expect(getMonthLabelForDateCell(document.activeElement)).toBe('Feb 2014');
240+
expect(getFocusedDateElement().textContent).toBe('11');
241+
expect(getMonthLabelForDateCell(getFocusedDateElement())).toBe('Feb 2014');
238242

239243
dispatchKeyEvent(keyCodes.HOME);
240-
expect(document.activeElement.textContent).toBe('1');
241-
expect(getMonthLabelForDateCell(document.activeElement)).toBe('Feb 2014');
244+
expect(getFocusedDateElement().textContent).toBe('1');
245+
expect(getMonthLabelForDateCell(getFocusedDateElement())).toBe('Feb 2014');
242246

243247
dispatchKeyEvent(keyCodes.END);
244-
expect(document.activeElement.textContent).toBe('28');
245-
expect(getMonthLabelForDateCell(document.activeElement)).toBe('Feb 2014');
248+
expect(getFocusedDateElement().textContent).toBe('28');
249+
expect(getMonthLabelForDateCell(getFocusedDateElement())).toBe('Feb 2014');
246250

247251
dispatchKeyEvent(keyCodes.RIGHT_ARROW);
248-
expect(document.activeElement.textContent).toBe('1');
249-
expect(getMonthLabelForDateCell(document.activeElement)).toBe('Mar 2014');
252+
expect(getFocusedDateElement().textContent).toBe('1');
253+
expect(getMonthLabelForDateCell(getFocusedDateElement())).toBe('Mar 2014');
250254

251255
dispatchKeyEvent(keyCodes.PAGE_UP);
252-
expect(document.activeElement.textContent).toBe('1');
253-
expect(getMonthLabelForDateCell(document.activeElement)).toBe('Feb 2014');
256+
expect(getFocusedDateElement().textContent).toBe('1');
257+
expect(getMonthLabelForDateCell(getFocusedDateElement())).toBe('Feb 2014');
254258

255259
dispatchKeyEvent(keyCodes.PAGE_DOWN);
256-
expect(document.activeElement.textContent).toBe('1');
257-
expect(getMonthLabelForDateCell(document.activeElement)).toBe('Mar 2014');
260+
expect(getFocusedDateElement().textContent).toBe('1');
261+
expect(getMonthLabelForDateCell(getFocusedDateElement())).toBe('Mar 2014');
258262

259263
dispatchKeyEvent(keyCodes.UP_ARROW, {meta: true});
260-
expect(document.activeElement.textContent).toBe('1');
261-
expect(getMonthLabelForDateCell(document.activeElement)).toBe('Feb 2014');
264+
expect(getFocusedDateElement().textContent).toBe('1');
265+
expect(getMonthLabelForDateCell(getFocusedDateElement())).toBe('Feb 2014');
262266

263267
dispatchKeyEvent(keyCodes.DOWN_ARROW, {meta: true});
264-
expect(document.activeElement.textContent).toBe('1');
265-
expect(getMonthLabelForDateCell(document.activeElement)).toBe('Mar 2014');
268+
expect(getFocusedDateElement().textContent).toBe('1');
269+
expect(getMonthLabelForDateCell(getFocusedDateElement())).toBe('Mar 2014');
266270

267271
dispatchKeyEvent(keyCodes.ENTER);
268272
applyDateChange();

src/components/calendar/datePicker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
// PRE RELEASE
55
// TODO(jelbourn): Documentation
66
// TODO(jelbourn): Demo that uses moment.js
7+
78
// TODO(jelbourn): aria attributes tying together date input and floating calendar.
89
// TODO(jelbourn): make sure this plays well with validation and ngMessages.
9-
// TODO(jelbourn): forward more attributes to the internal input (required, autofocus, etc.)
1010
// TODO(jelbourn): auto-grow input to accomodate longer dates
1111

1212
// POST RELEASE
13+
// TODO(jelbourn): forward more attributes to the internal input (required, autofocus, etc.)
1314
// TODO(jelbourn): error state
1415
// TODO(jelbourn): something better for mobile (calendar panel takes up entire screen?)
1516
// TODO(jelbourn): input behavior (masking? auto-complete?)

src/components/calendar/datePicker.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ describe('md-date-picker', function() {
2424
pageScope.myDate = initialDate;
2525
pageScope.isDisabled = false;
2626

27-
var template = '<md-date-picker ng-model="myDate" ng-disabled="isDisabled"></md-date-picker>';
27+
var template = '<md-datepicker ng-model="myDate" ng-disabled="isDisabled"></md-datepicker>';
2828
ngElement = $compile(template)(pageScope);
2929
$rootScope.$apply();
3030

3131
scope = ngElement.scope();
32-
controller = ngElement.controller('mdDatePicker');
32+
controller = ngElement.controller('mdDatepicker');
3333
element = ngElement[0];
3434
}));
3535

0 commit comments

Comments
 (0)