From 266c8b73b06c52c9d98a28ca70c2c6b6f295ddea Mon Sep 17 00:00:00 2001 From: Huong Nguyen Date: Wed, 17 Jul 2024 18:21:49 +0700 Subject: [PATCH] MDL-82505 calendar: more precise matching of calendar day partial The partial name selector points to the parent element, but the Javascript code monitors the child element. We need to make it consistent --- .../tests/behat/block_calendar_month.feature | 2 +- calendar/tests/behat/behat_calendar.php | 32 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/blocks/calendar_month/tests/behat/block_calendar_month.feature b/blocks/calendar_month/tests/behat/block_calendar_month.feature index 691f5b95afd..6239d9da25c 100644 --- a/blocks/calendar_month/tests/behat/block_calendar_month.feature +++ b/blocks/calendar_month/tests/behat/block_calendar_month.feature @@ -106,6 +106,6 @@ Feature: Enable the calendar block in a course and test it's functionality And I press "Save changes" When I am on "Course 1" course homepage And I follow "Course calendar" - And I click on today in the mini-calendar block + And I click on today in the mini-calendar block to view the detail Then I should see "Site Event" in the "Calendar" "block" And ".popover" "css_element" should not exist diff --git a/calendar/tests/behat/behat_calendar.php b/calendar/tests/behat/behat_calendar.php index 75c81ea333a..291398e742f 100644 --- a/calendar/tests/behat/behat_calendar.php +++ b/calendar/tests/behat/behat_calendar.php @@ -48,10 +48,19 @@ class behat_calendar extends behat_base { new behat_component_named_selector('mini calendar block', [".//*[@data-block='calendar_month']"]), new behat_component_named_selector('full calendar page', [".//*[@id='page-calendar-view']"]), new behat_component_named_selector('calendar day', [".//*[@data-region='day'][@data-day=%locator%]"]), + new behat_component_named_selector( + 'calendar day detail', + [".//*[@data-region='day'][@data-day=%locator%]//a[@data-action='view-day-link']"] + ), new behat_component_named_selector( 'responsive calendar day', [".//*[@data-region='day'][@data-day=%locator%]/div[contains(@class, 'hidden-desktop')]"] ), + new behat_component_named_selector( + 'responsive calendar day detail', + [".//*[@data-region='day'][@data-day=%locator%]" . + "/div[contains(@class, 'hidden-desktop')]//a[@data-action='view-day-link']"] + ), ]; } @@ -139,13 +148,26 @@ class behat_calendar extends behat_base { * * @param int $day The day of the current month. * @param string $responsive If not null, find the responsive version of the link. + * @param string $detail If not null, find the detail version of the link. */ - public function i_click_on_day_of_this_month_in_mini_calendar_block(int $day, string $responsive = ''): void { + public function i_click_on_day_of_this_month_in_mini_calendar_block( + int $day, + string $responsive = '', + string $detail = '', + ): void { + $selectortype = 'core_calendar >'; + if (!empty($responsive)) { + $selectortype .= ' responsive'; + } + $selectortype .= ' calendar day'; + if (!empty($detail)) { + $selectortype .= ' detail'; + } $this->execute( contextapi: "behat_general::i_click_on_in_the", params: [ $day, - empty($responsive) ? 'core_calendar > calendar day' : 'core_calendar > responsive calendar day', + $selectortype, '', 'core_calendar > mini calendar block', ], @@ -167,14 +189,16 @@ class behat_calendar extends behat_base { /** * Click on today in the mini-calendar. * - * @Given /^I click on today in the mini-calendar block( responsive view|)$/ + * @Given /^I click on today in the mini-calendar block( responsive view|)( to view the detail|)$/ * * @param string $responsive If not empty, use the responsive calendar link. + * @param string $detail If not empty, use the detail view calendar link. */ - public function i_click_on_today_in_mini_calendar_block(string $responsive = ''): void { + public function i_click_on_today_in_mini_calendar_block(string $responsive = '', string $detail = ''): void { $this->i_click_on_day_of_this_month_in_mini_calendar_block( day: date('j'), responsive: $responsive, + detail: $detail, ); }