1
0

NotificationsContext.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. *
  4. * @copyright Copyright (c) 2019, Daniel Calviño Sánchez (danxuliu@gmail.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. class NotificationsContext implements Context, ActorAwareInterface {
  24. use ActorAware;
  25. /**
  26. * @return Locator
  27. */
  28. public static function notificationsButton() {
  29. return Locator::forThe()->css("#header #notifications.notifications-button")->
  30. describedAs("Notifications button in the header");
  31. }
  32. /**
  33. * @return Locator
  34. */
  35. public static function notificationsContainer() {
  36. return Locator::forThe()->css("#header #notifications .notification-container")->
  37. describedAs("Notifications container");
  38. }
  39. /**
  40. * @return Locator
  41. */
  42. public static function incomingShareNotificationForFile($fileName) {
  43. return Locator::forThe()->xpath("//li[contains(concat(' ', normalize-space(@class), ' '), ' notification ') and //div[starts-with(normalize-space(), 'You received $fileName as a share by')]]")->
  44. descendantOf(self::notificationsContainer())->
  45. describedAs("Notification of incoming share for file $fileName");
  46. }
  47. /**
  48. * @return Locator
  49. */
  50. public static function actionsInIncomingShareNotificationForFile($fileName) {
  51. return Locator::forThe()->css(".notification-actions")->
  52. descendantOf(self::incomingShareNotificationForFile($fileName))->
  53. describedAs("Actions in notification of incoming share for file $fileName");
  54. }
  55. /**
  56. * @return Locator
  57. */
  58. public static function actionInIncomingShareNotificationForFile($fileName, $action) {
  59. return Locator::forThe()->xpath("//button[normalize-space() = '$action']")->
  60. descendantOf(self::actionsInIncomingShareNotificationForFile($fileName))->
  61. describedAs("$action button in notification of incoming share for file $fileName");
  62. }
  63. /**
  64. * @return Locator
  65. */
  66. public static function acceptButtonInIncomingShareNotificationForFile($fileName) {
  67. return self::actionInIncomingShareNotificationForFile($fileName, 'Accept');
  68. }
  69. /**
  70. * @Given I accept the share for :fileName in the notifications
  71. */
  72. public function iAcceptTheShareForInTheNotifications($fileName) {
  73. $this->actor->find(self::notificationsButton(), 10)->click();
  74. // Notifications are refreshed every 30 seconds, so wait a bit longer.
  75. // As the waiting is long enough already the find timeout multiplier is
  76. // capped at 2 when finding notifications.
  77. $findTimeoutMultiplier = $this->actor->getFindTimeoutMultiplier();
  78. $this->actor->setFindTimeoutMultiplier(min(2, $findTimeoutMultiplier));
  79. $this->actor->find(self::acceptButtonInIncomingShareNotificationForFile($fileName), 35)->click();
  80. $this->actor->setFindTimeoutMultiplier($findTimeoutMultiplier);
  81. // Hide the notifications again
  82. $this->actor->find(self::notificationsButton(), 10)->click();
  83. }
  84. }