ContactsMenuContext.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. *
  4. * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv) (skjnldsv@protonmail.com)
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. use Behat\Behat\Context\Context;
  23. use PHPUnit\Framework\Assert;
  24. class ContactsMenuContext implements Context, ActorAwareInterface {
  25. use ActorAware;
  26. /**
  27. * @return Locator
  28. */
  29. public static function contactsMenuButton() {
  30. return Locator::forThe()->xpath("//*[@id = 'header']//*[@id = 'contactsmenu']//*[@class = 'header-menu__trigger']")->
  31. describedAs("Contacts menu button");
  32. }
  33. /**
  34. * @return Locator
  35. */
  36. public static function contactsMenu() {
  37. return Locator::forThe()->xpath("//*[@id = 'header']//*[@id = 'contactsmenu']//*[@id = 'contactsmenu-menu']")->
  38. describedAs("Contacts menu");
  39. }
  40. /**
  41. * @return Locator
  42. */
  43. public static function contactsMenuSearchInput() {
  44. return Locator::forThe()->id("contactsmenu-search")->
  45. descendantOf(self::contactsMenu())->
  46. describedAs("Contacts menu search input");
  47. }
  48. /**
  49. * @return Locator
  50. */
  51. public static function noResultsMessage() {
  52. return Locator::forThe()->xpath("//*[@class = 'emptycontent' and normalize-space() = 'No contacts found']")->
  53. descendantOf(self::contactsMenu())->
  54. describedAs("No results message in Contacts menu");
  55. }
  56. /**
  57. * @return Locator
  58. */
  59. private static function menuItemFor($contactName) {
  60. return Locator::forThe()->xpath("//*[@class = 'full-name' and normalize-space() = '$contactName']")->
  61. descendantOf(self::contactsMenu())->
  62. describedAs($contactName . " contact in Contacts menu");
  63. }
  64. /**
  65. * @When I open the Contacts menu
  66. */
  67. public function iOpenTheContactsMenu() {
  68. $this->actor->find(self::contactsMenuButton(), 10)->click();
  69. }
  70. /**
  71. * @When I search for the user :user
  72. */
  73. public function iSearchForTheUser($user) {
  74. $this->actor->find(self::contactsMenuSearchInput(), 10)->setValue($user);
  75. }
  76. /**
  77. * @Then I see that the Contacts menu is shown
  78. */
  79. public function iSeeThatTheContactsMenuIsShown() {
  80. Assert::assertTrue(
  81. $this->actor->find(self::contactsMenu(), 10)->isVisible());
  82. }
  83. /**
  84. * @Then I see that the Contacts menu search input is shown
  85. */
  86. public function iSeeThatTheContactsMenuSearchInputIsShown() {
  87. Assert::assertTrue(
  88. $this->actor->find(self::contactsMenuSearchInput(), 10)->isVisible());
  89. }
  90. /**
  91. * @Then I see that the no results message in the Contacts menu is shown
  92. */
  93. public function iSeeThatTheNoResultsMessageInTheContactsMenuIsShown() {
  94. Assert::assertTrue(
  95. $this->actor->find(self::noResultsMessage(), 10)->isVisible());
  96. }
  97. /**
  98. * @Then I see that the contact :contactName in the Contacts menu is shown
  99. */
  100. public function iSeeThatTheContactInTheContactsMenuIsShown($contactName) {
  101. Assert::assertTrue(
  102. $this->actor->find(self::menuItemFor($contactName), 10)->isVisible());
  103. }
  104. /**
  105. * @Then I see that the contact :contactName in the Contacts menu is not shown
  106. */
  107. public function iSeeThatTheContactInTheContactsMenuIsNotShown($contactName) {
  108. $this->iSeeThatThecontactsMenuIsShown();
  109. try {
  110. Assert::assertFalse(
  111. $this->actor->find(self::menuItemFor($contactName))->isVisible());
  112. } catch (NoSuchElementException $exception) {
  113. }
  114. }
  115. /**
  116. * @Then I see that the contact :contactName in the Contacts menu is eventually not shown
  117. */
  118. public function iSeeThatTheContactInTheContactsMenuIsEventuallyNotShown($contactName) {
  119. $this->iSeeThatThecontactsMenuIsShown();
  120. if (!WaitFor::elementToBeEventuallyNotShown(
  121. $this->actor,
  122. self::menuItemFor($contactName),
  123. $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
  124. Assert::fail("The $contactName contact in Contacts menu is still shown after $timeout seconds");
  125. }
  126. }
  127. }