-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add attributes to improve e2e testing
If you were depending on the existance of date values in the classes of buttons, or other similar changes, your code will break after upgrading. I did not consider those classes part of the public API so I am not listing this as a breaking change.
- Loading branch information
Showing
19 changed files
with
211 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
import { AppPage } from './app.po'; | ||
import {AppPage} from './app.po'; | ||
import pickTime from './dl-date-time-picker-protractor'; | ||
import moment = require('moment'); | ||
|
||
describe('workspace-project App', () => { | ||
let page: AppPage; | ||
|
||
beforeEach(() => { | ||
page = new AppPage(); | ||
return page.navigateTo(); | ||
}); | ||
|
||
it('should display welcome message', () => { | ||
page.navigateTo(); | ||
expect(page.getParagraphText()).toEqual('Welcome to angular-bootstrap-datetimepicker!'); | ||
it('Picking time updates Selected Date:', async () => { | ||
const todayAtMidnight = moment('2003-11-07T21:32:17.800Z'); | ||
const expectedDate = new Date('2003-11-07T21:30:00.000Z').toString(); | ||
|
||
await pickTime(page.getDateTimePicker(), todayAtMidnight.valueOf()); | ||
|
||
const selectedDate = page.getSelectedDate().getText(); | ||
expect(selectedDate).toBe(`Selected Date: ${expectedDate}`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import {by, ElementArrayFinder, ElementFinder} from 'protractor'; | ||
|
||
/** | ||
* This file is an example of how you can implement automated end-to-end tests for the | ||
* date/time picker component. | ||
* | ||
* The overall strategy here is to use the `dl-abdtp-value` attributes, which contain numeric date values, | ||
* to determine which buttons to click on the picker in order to select a target dates. | ||
*/ | ||
|
||
/** | ||
* Clicks the nearest date button with a value less than or equal to the specified time. | ||
* @param dateButtons | ||
* the possible date buttons. | ||
* @param time | ||
* the desired selected time. | ||
*/ | ||
|
||
export function clickNearestDateButton(dateButtons: ElementArrayFinder, time: number) { | ||
return dateButtons | ||
.filter(button => button.getAttribute('dl-abdtp-value').then(buttonValue => Number(buttonValue) <= time)) | ||
.last().click(); | ||
} | ||
|
||
/** | ||
* Have the dateTimePicker select the best possible value that is less than or equal to the specified time. | ||
* based on the current configuration of the dateTimePicker. | ||
* | ||
* This function will `not` select a time value `greater than` the specified time value. | ||
* | ||
* Additionally, this function depends on `ng-reflect-*` attributes which will never exist in a production build. | ||
* | ||
* @param dateTimePicker | ||
* the target dateTimePicker | ||
* | ||
* @param time | ||
* the desired selected time. | ||
*/ | ||
async function pickTime(dateTimePicker: ElementFinder, time: number) { | ||
const dateButtons = dateTimePicker.all(by.className('dl-abdtp-date-button')); | ||
const leftButton = dateTimePicker.element(by.className('dl-abdtp-left-button')); | ||
const rightButton = dateTimePicker.element(by.className('dl-abdtp-right-button')); | ||
const upButton = dateTimePicker.element(by.className('dl-abdtp-up-button')); | ||
const viewAttributeName = 'data-dl-abdtp-view'; | ||
const viewElement = dateTimePicker.element(by.css(`[${viewAttributeName}]`)); | ||
|
||
const maxView = await dateTimePicker.getAttribute('ng-reflect-max-view'); | ||
const minView = await dateTimePicker.getAttribute('ng-reflect-min-view'); | ||
|
||
let currentView = await viewElement.getAttribute(viewAttributeName); | ||
|
||
// Go up to the max view in order to drill down by selecting the nearest button value. | ||
while (maxView !== currentView) { | ||
await upButton.click(); | ||
currentView = await viewElement.getAttribute(viewAttributeName); | ||
} | ||
|
||
let firstButtonValue = await dateButtons.first().getAttribute('dl-abdtp-value'); | ||
|
||
// This left and right navigation to find the target date range assumes that earlier times are to the left. | ||
// This is true for the default implementation but may not be true for all implementations. | ||
|
||
while (Number(firstButtonValue) > time) { | ||
await leftButton.click(); | ||
firstButtonValue = await dateButtons.first().getAttribute('dl-abdtp-value'); | ||
} | ||
|
||
let lastButtonValue = await dateButtons.last().getAttribute('dl-abdtp-value'); | ||
|
||
while (Number(lastButtonValue) <= time) { | ||
await rightButton.click(); | ||
lastButtonValue = await dateButtons.last().getAttribute('dl-abdtp-value'); | ||
} | ||
|
||
while (minView !== currentView) { | ||
await clickNearestDateButton(dateButtons, time); | ||
currentView = await viewElement.getAttribute(viewAttributeName); | ||
} | ||
|
||
return clickNearestDateButton(dateButtons, time); | ||
} | ||
|
||
export default pickTime; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.