File obs-server-2.9-0016-webui-Wait-for-flash-message-to-appear-in-webui-test.patch of Package obs-server
From 954927ba92b1923cdbe37736f7c1face4dd08dfc Mon Sep 17 00:00:00 2001
From: Oleg Girko <ol@infoserver.lv>
Date: Tue, 5 Jul 2016 00:34:28 +0100
Subject: [PATCH] [webui] Wait for flash message to appear in webui tests.
This change makes flash_message and flash_message_type methods
wait for flash message to appear on the page.
Also, these methods now raise error when flash message doesn't appear
or multiple flash messages appear.
Raising error instead of returning nil if there is no flash message
does not affect webui tests and even makes them more correct:
there is no place in webui tests where return of these methods
is checked for nil, and there are many placse that assume that it's non-nil.
Methods flash_messages and flash_message_appeared? have been removed.
They are not used in webui tests anyway.
Signed-off-by: Oleg Girko <ol@infoserver.lv>
---
src/api/test/test_helper.rb | 34 ++++------------------------------
1 file changed, 4 insertions(+), 30 deletions(-)
diff --git a/src/api/test/test_helper.rb b/src/api/test/test_helper.rb
index eaf8544fa6..7411292270 100644
--- a/src/api/test/test_helper.rb
+++ b/src/api/test/test_helper.rb
@@ -319,48 +319,22 @@ module Webui
ret
end
- # ============================================================================
- # Checks if a flash message is displayed on screen
- #
- def flash_message_appeared?
- flash_message_type != nil
- end
-
# ============================================================================
# Returns the text of the flash message currenlty on screen
- # @note Doesn't fail if no message is on screen. Returns empty string instead.
+ # @note Raises error if no message or multiple messages are on screen.
# @return [String]
#
def flash_message
- results = all(:css, 'div#flash-messages p')
- return 'none' if results.empty?
- if results.count > 1
- texts = results.map(&:text)
- raise "One flash expected, but we had #{texts.inspect}"
- end
- results.first.text
- end
-
- # ============================================================================
- # Returns the text of the flash messages currenlty on screen
- # @note Doesn't fail if no message is on screen. Returns empty list instead.
- # @return [array]
- #
- def flash_messages
- results = all(:css, 'div#flash-messages p')
- ret = []
- results.each { |r| ret << r.text }
- ret
+ find(:css, 'div#flash-messages p').text
end
# ============================================================================
# Returns the type of the flash message currenlty on screen
- # @note Does not fail if no message is on screen! Returns nil instead!
+ # @note Raises error if no message or multiple messages are on screen.
# @return [:info, :alert]
#
def flash_message_type
- result = first(:css, 'div#flash-messages span')
- return unless result
+ result = find(:css, 'div#flash-messages span')
return :info if result['class'].include? 'info'
return :alert if result['class'].include? 'alert'
end
--
2.20.1