Merge pull request #3434 from dpalou/MOBILE-4081
MOBILE-4081 course: Improve behat tests for hidden coursesmain
commit
1dbb00b79a
|
@ -56,13 +56,15 @@ Feature: Test basic usage of courses in app
|
|||
Scenario: Hidden course is only accessible for teachers
|
||||
Given I entered the app as "teacher1"
|
||||
And I press "My courses" in the app
|
||||
Then I should find "Hidden from students" within "Hidden course" "ion-item" in the app
|
||||
|
||||
When I press "Hidden course" in the app
|
||||
Then the header should be "Hidden course" in the app
|
||||
|
||||
Given I entered the app as "student1"
|
||||
And I press "My courses" in the app
|
||||
And I should not find "Hidden course" in the app
|
||||
|
||||
Then I should not find "Hidden course" in the app
|
||||
And I should not find "Hidden from students" in the app
|
||||
|
||||
@lms_from4.0
|
||||
Scenario: See my courses
|
||||
|
|
|
@ -24,18 +24,32 @@ import { TestingBehatElementLocator, TestingBehatFindOptions } from './behat-run
|
|||
@Injectable({ providedIn: 'root' })
|
||||
export class TestingBehatDomUtilsService {
|
||||
|
||||
/**
|
||||
* Check if an element is clickable.
|
||||
*
|
||||
* @param element Element.
|
||||
* @return Whether the element is clickable or not.
|
||||
*/
|
||||
isElementClickable(element: HTMLElement): boolean {
|
||||
return element.getAttribute('aria-disabled') !== 'true' && !element.hasAttribute('disabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an element is visible.
|
||||
*
|
||||
* @param element Element.
|
||||
* @param container Container.
|
||||
* @param container Container. If set, the function will also check parent elements visibility.
|
||||
* @return Whether the element is visible or not.
|
||||
*/
|
||||
isElementVisible(element: HTMLElement, container: HTMLElement): boolean {
|
||||
isElementVisible(element: HTMLElement, container?: HTMLElement): boolean {
|
||||
if (element.getAttribute('aria-hidden') === 'true' || getComputedStyle(element).display === 'none') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!container) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const parentElement = this.getParentElement(element);
|
||||
if (parentElement === container) {
|
||||
return true;
|
||||
|
@ -92,7 +106,10 @@ export class TestingBehatDomUtilsService {
|
|||
`img[alt*="${escapedText}"], [placeholder*="${escapedText}"]`;
|
||||
|
||||
const elements = Array.from(container.querySelectorAll<HTMLElement>(attributesSelector))
|
||||
.filter((element => this.isElementVisible(element, container)))
|
||||
.filter(
|
||||
element => this.isElementVisible(element, container) &&
|
||||
(!options.onlyClickable || this.isElementClickable(element)),
|
||||
)
|
||||
.map((element) => {
|
||||
const exact = this.checkElementLabel(element, text);
|
||||
|
||||
|
@ -116,11 +133,11 @@ export class TestingBehatDomUtilsService {
|
|||
return NodeFilter.FILTER_ACCEPT;
|
||||
}
|
||||
|
||||
if (options.onlyClickable && (node.getAttribute('aria-disabled') === 'true' || node.hasAttribute('disabled'))) {
|
||||
if (options.onlyClickable && !this.isElementClickable(node)) {
|
||||
return NodeFilter.FILTER_REJECT;
|
||||
}
|
||||
|
||||
if (node.getAttribute('aria-hidden') === 'true' || getComputedStyle(node).display === 'none') {
|
||||
if (!this.isElementVisible(node)) {
|
||||
return NodeFilter.FILTER_REJECT;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue