您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ContactsMenuContext.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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']")->
  31. describedAs("Contacts menu button");
  32. }
  33. /**
  34. * @return Locator
  35. */
  36. public static function contactsMenu() {
  37. return Locator::forThe()->css(".menu")->
  38. descendantOf(self::contactsMenuButton())->
  39. describedAs("Contacts menu");
  40. }
  41. /**
  42. * @return Locator
  43. */
  44. public static function contactsMenuSearchInput() {
  45. return Locator::forThe()->id("contactsmenu-search")->
  46. descendantOf(self::contactsMenu())->
  47. describedAs("Contacts menu search input");
  48. }
  49. /**
  50. * @return Locator
  51. */
  52. public static function noResultsMessage() {
  53. return Locator::forThe()->xpath("//*[@class = 'emptycontent' and normalize-space() = 'No contacts found']")->
  54. descendantOf(self::contactsMenu())->
  55. describedAs("No results message in Contacts menu");
  56. }
  57. /**
  58. * @return Locator
  59. */
  60. private static function menuItemFor($contactName) {
  61. return Locator::forThe()->xpath("//*[@class = 'full-name' and normalize-space() = '$contactName']")->
  62. descendantOf(self::contactsMenu())->
  63. describedAs($contactName . " contact in Contacts menu");
  64. }
  65. /**
  66. * @When I open the Contacts menu
  67. */
  68. public function iOpenTheContactsMenu() {
  69. $this->actor->find(self::contactsMenuButton(), 10)->click();
  70. }
  71. /**
  72. * @When I search for the user :user
  73. */
  74. public function iSearchForTheUser($user) {
  75. $this->actor->find(self::contactsMenuSearchInput(), 10)->setValue($user);
  76. }
  77. /**
  78. * @Then I see that the Contacts menu is shown
  79. */
  80. public function iSeeThatTheContactsMenuIsShown() {
  81. Assert::assertTrue(
  82. $this->actor->find(self::contactsMenu(), 10)->isVisible());
  83. }
  84. /**
  85. * @Then I see that the Contacts menu search input is shown
  86. */
  87. public function iSeeThatTheContactsMenuSearchInputIsShown() {
  88. Assert::assertTrue(
  89. $this->actor->find(self::contactsMenuSearchInput(), 10)->isVisible());
  90. }
  91. /**
  92. * @Then I see that the no results message in the Contacts menu is shown
  93. */
  94. public function iSeeThatTheNoResultsMessageInTheContactsMenuIsShown() {
  95. Assert::assertTrue(
  96. $this->actor->find(self::noResultsMessage(), 10)->isVisible());
  97. }
  98. /**
  99. * @Then I see that the contact :contactName in the Contacts menu is shown
  100. */
  101. public function iSeeThatTheContactInTheContactsMenuIsShown($contactName) {
  102. Assert::assertTrue(
  103. $this->actor->find(self::menuItemFor($contactName), 10)->isVisible());
  104. }
  105. /**
  106. * @Then I see that the contact :contactName in the Contacts menu is not shown
  107. */
  108. public function iSeeThatTheContactInTheContactsMenuIsNotShown($contactName) {
  109. $this->iSeeThatThecontactsMenuIsShown();
  110. try {
  111. Assert::assertFalse(
  112. $this->actor->find(self::menuItemFor($contactName))->isVisible());
  113. } catch (NoSuchElementException $exception) {
  114. }
  115. }
  116. /**
  117. * @Then I see that the contact :contactName in the Contacts menu is eventually not shown
  118. */
  119. public function iSeeThatTheContactInTheContactsMenuIsEventuallyNotShown($contactName) {
  120. $this->iSeeThatThecontactsMenuIsShown();
  121. if (!WaitFor::elementToBeEventuallyNotShown(
  122. $this->actor,
  123. self::menuItemFor($contactName),
  124. $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
  125. Assert::fail("The $contactName contact in Contacts menu is still shown after $timeout seconds");
  126. }
  127. }
  128. }