Created
June 27, 2017 20:35
-
-
Save DanRibbens/4d1d439fdbc4894aa5cecb43b32bf641 to your computer and use it in GitHub Desktop.
example protractor test class for the Promact/md2 md2-select mutiple (multiselect)
This file contains hidden or 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
import {Md2MultiSelect} from "./components/md2/md2-multi-select"; | |
describe('example test usage of md2-select multiple test class', () => { | |
it("md2-select: should be able to check all options", () => { | |
const md2Select = new Md2MultiSelect('[name=anotherSelect]'); | |
md2Select.checkAll(); | |
md2Select.open(); | |
expect(element.all(by.css('.md2-select-content .md2-option')).count()).toEqual(element.all(by.css('.md2-selected')).count()); | |
}); | |
it("md2-select: should be able to select multiple items from the options", () => { | |
const list = ['A', 'B', 'C', '1', '2', '3']; | |
const md2select = new Md2MultiSelect('[name=selectedCaseStatuses]'); | |
md2select.uncheckAll().click(list); | |
expect(md2select.getStringValue()).toContain('A, B, C, 1, 2, 3'); | |
}); | |
}); |
This file contains hidden or 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
import {by, ElementFinder, $, $$} from "protractor"; | |
import {promise} from "selenium-webdriver"; | |
export class Md2MultiSelect { | |
component: ElementFinder; | |
constructor(selector: string) { | |
this.component = $(selector); | |
} | |
uncheckAll(): Md2MultiSelectPage { | |
this.open(); | |
this.selectedOptions().then((selector) => { | |
$$(selector).each((elem) => elem.click()); | |
this.close(); | |
}); | |
this.close(); | |
return this; | |
} | |
checkAll(): any { | |
this.open(); | |
this.notSelectedOptions().then((selector) => { | |
$$(selector).each((elem) => elem.click()); | |
this.close(); | |
}); | |
return this; | |
} | |
click(array: string[]): Md2MultiSelectPage { | |
this.open(); | |
this.allOptions().then((selector) => { | |
$$(selector).each((elem) => { | |
elem.getAttribute("innerText").then((text) => { | |
if (array.indexOf(text) >= 0) { | |
elem.click(); | |
} | |
}); | |
}); | |
}); | |
this.close(); | |
return this; | |
} | |
getStringValue(): any { | |
return this.component.element(by.className('md2-select-value-text')).getAttribute("innerText"); | |
} | |
private selectedOptions(): promise.Promise<string> { | |
return this.filterOptionIds().then((ids) => { | |
return ids.split(' ').map((id) => { | |
return "#" + id + '.md2-selected'; | |
}).toString(); | |
}); | |
} | |
private notSelectedOptions(): promise.Promise<string> { | |
return this.filterOptionIds().then((ids) => { | |
return ids.split(' ').map((id) => { | |
return "#" + id + ":not(md2-selected)"; | |
}).toString(); | |
}); | |
} | |
private allOptions(): promise.Promise<string> { | |
return this.filterOptionIds().then((ids) => { | |
return ids.split(' ').map((id) => { | |
return "#" + id; | |
}).toString(); | |
}); | |
} | |
private filterOptionIds(): promise.Promise<string> { | |
return this.component.getAttribute('aria-owns').then((promise) => { | |
return promise | |
}); | |
} | |
open() { | |
this.close(); | |
this.component.click(); | |
return this; | |
} | |
close() { | |
$('body').click(); | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment