|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @copyright Copyright (C) Ibexa AS. All rights reserved. |
| 5 | + * @license For full copyright and license information view LICENSE file distributed with this source code. |
| 6 | + */ |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace EzSystems\Behat\Test\Browser\Element\Condition; |
| 10 | + |
| 11 | +use EzSystems\Behat\Test\Browser\Element\BaseTestCase; |
| 12 | +use Ibexa\Behat\Browser\Element\Condition\ElementTransitionHasEndedCondition; |
| 13 | +use Ibexa\Behat\Browser\Element\ElementInterface; |
| 14 | +use Ibexa\Behat\Browser\Locator\CSSLocator; |
| 15 | +use PHPUnit\Framework\Assert; |
| 16 | + |
| 17 | +class ElementTransitionHasEndedConditionTest extends BaseTestCase |
| 18 | +{ |
| 19 | + public function testElementTransitionHasEnded(): void |
| 20 | + { |
| 21 | + $searchedElementLocator = new CSSLocator('searched-id', 'searched-test'); |
| 22 | + |
| 23 | + $condition = new ElementTransitionHasEndedCondition( |
| 24 | + $this->createElementWithChildElement('root', $searchedElementLocator, $this->createChildElement(false, true)), |
| 25 | + $searchedElementLocator |
| 26 | + ); |
| 27 | + |
| 28 | + Assert::assertTrue($condition->isMet()); |
| 29 | + } |
| 30 | + |
| 31 | + public function testElementTransitionHasNotEndedInTime(): void |
| 32 | + { |
| 33 | + $searchedElementLocator = new CSSLocator('searched-id', 'searched-test'); |
| 34 | + $baseElement = $this->createElementWithChildElement('root', $searchedElementLocator, $this->createElement('ChildText')); |
| 35 | + |
| 36 | + $condition = new ElementTransitionHasEndedCondition( |
| 37 | + $this->createElementWithChildElement('root', $searchedElementLocator, $this->createChildElement(true, false)), |
| 38 | + $searchedElementLocator |
| 39 | + ); |
| 40 | + |
| 41 | + Assert::assertFalse($condition->isMet()); |
| 42 | + Assert::assertEquals( |
| 43 | + "Transition has not ended for element with CSS locator 'searched-id': 'searched-test'. Timeout value: 1 seconds.", |
| 44 | + $condition->getErrorMessage($baseElement) |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + public function testElementTransitionHasNotStarted(): void |
| 49 | + { |
| 50 | + $searchedElementLocator = new CSSLocator('searched-id', 'searched-test'); |
| 51 | + $baseElement = $this->createElementWithChildElement('root', $searchedElementLocator, $this->createElement('ChildText')); |
| 52 | + |
| 53 | + $condition = new ElementTransitionHasEndedCondition( |
| 54 | + $this->createElementWithChildElement('root', $searchedElementLocator, $this->createChildElement(false, false)), |
| 55 | + $searchedElementLocator |
| 56 | + ); |
| 57 | + |
| 58 | + Assert::assertFalse($condition->isMet()); |
| 59 | + Assert::assertEquals( |
| 60 | + "Transition has not started at all for element with CSS locator 'searched-id': 'searched-test'. Please make sure the condition is used on the correct element. Timeout value: 1 seconds.", |
| 61 | + $condition->getErrorMessage($baseElement) |
| 62 | + ); |
| 63 | + } |
| 64 | + |
| 65 | + private function createChildElement(bool $hasStartedTransition, bool $hasEndedTransition): ElementInterface |
| 66 | + { |
| 67 | + $childElement = $this->createStub(ElementInterface::class); |
| 68 | + $childElement->method('getText')->willReturn('ChildText'); |
| 69 | + $childElement->method('hasClass')->will($this->returnValueMap( |
| 70 | + [ |
| 71 | + ['ibexa-selenium-transition-started', $hasStartedTransition], |
| 72 | + ['ibexa-selenium-transition-ended', $hasEndedTransition], |
| 73 | + ] |
| 74 | + )); |
| 75 | + |
| 76 | + return $childElement; |
| 77 | + } |
| 78 | +} |
0 commit comments