
     +h-6                     P   d Z ddlmZ ddlZddlmZ ddlZ G d de          Z G d de          Z	 G d	 d
e	          Z
 G d de	          Z G d de          Z G d de	          Z G d de          Z G d dee          Z G d dee	          Z G d dee
          ZdS )z8User stories, functional tests for AutocompleteTestCase.    )unicode_literalsN)StaleElementReferenceExceptionc                      e Zd ZdZ	 	 	 	 	 	 	 	 	 ddZ ej         ej        d                    d             Zd Z	d Z
d	 Zd
 Z ej         ej        d                    d             Zd Z ej         ej        d                    d             Zd Zd Z ej         ej        d                    d             Zd Zd Zd Zd Zd Zd Zd ZdS )	BaseStoryzBase UserStory class.Nc                    || _         |p| j         j        | _        |p| j         j        | _        |p| j         j        | _        |p| j         j        | _        |p| j         j        | _        |p| j         j        | _        |p| j         j        | _        |	p| j         j        | _        |
p| j         j	        | _	        d| j        z  | _
        d| j        z  | _        | j
        d| j        | _        d| _        dS )z2If any kwarg is None, get it from case attributes.zfieldset.aligned .field-%sz#id_%s FN)caseclear_selectordropdown_selector
field_nameinput_selectorlabel_selectorlabels_selectormodeloption_selectorwidget_selectorfield_container_selectorfield_selectorfield_clear_selectorin_popup)selfr	   r
   r   r   r   r   r   r   r   r   s              T/var/www/html/e360mart/e360mart_env/lib/python3.11/site-packages/dal/test/stories.py__init__zBaseStory.__init__   s     	,H	0H"3 #A%)Y%@ 	$<	(<,H	0H,H	0H.K$)2K-dio
.K$)2K.K$)2K)E)-*9%&8)))%
!        )stopc                     | j         j                            | j                  }|D ]}||j        v r|c S t          d|z            )z(Incremental sleep until option appeared.zOption %s not found)r	   browserfind_by_cssr   text	Exception)r   r    optionsoptions       r   find_optionzBaseStory.find_option1   s_     )#//0DEE 	 	Fv{"" # -4555r   c                 $    | j         d| j        S z+Return CSS selector for field option label.r   )r   r   r   s    r   get_field_label_selectorz"BaseStory.get_field_label_selector<   s    7779L9LMMr   c                 n    | j         j                            d|                                 z             dS )5Clean child nodes before checking (ie. clear option).z
            document.querySelectorAll("%s *").forEach(function(node) {
                node.parentNode.removeChild(node);
            });
            N)r	   r   execute_scriptr(   r'   s    r   clean_label_from_remove_butonz'BaseStory.clean_label_from_remove_buton@   sD    	(( //11	2	
 	
 	
 	
 	
r   c                     | j         j                            |                                           }|                                  |                     |j                  S )!Return autocomplete widget label.)r	   r   r   r(   r,   clean_labelr    r   labels     r   	get_labelzBaseStory.get_labelJ   sU    	!--))++
 
 	**,,,
+++r   c                     |S )z.Given an option text, return the actual label. r0   s     r   r/   zBaseStory.clean_labelS   s    r   c                 :    ||                                  k    sJ dS )z0Assert that the autocomplete label matches text.N)r2   )r   r    s     r   assert_labelzBaseStory.assert_labelW   s%     t~~''''''''r   c                 Z    | j         j                            | j                  }|d         S )$Return the autocomplete field value.value)r	   r   r   r   )r   fields     r   	get_valuezBaseStory.get_value\   s.    	!--! ! W~r   c                 T    |                                  t          |          k    sJ dS )z1Assart that the actual field value matches value.N)r;   str)r   r9   s     r   assert_valuezBaseStory.assert_valuec   s+     ~~3u::------r   c                 Z    |                      |           |                     |           dS )z1Assert value is selected and has the given label.N)r6   r>   r   r9   r1   s      r   assert_selectionzBaseStory.assert_selectionh   s0    %   %     r   c                     |                      ||           |                                  |                     |           |                     |           dS )z9Assert value and lebel, submit the form and assert again.N)rA   submitr6   r>   r@   s      r   assert_selection_persistsz#BaseStory.assert_selection_persistsm   sS    eU+++%   %     r   c                 n    t          |          t          |                                           k    sJ dS )z7Retrying assert that suggestions match expected labels.N)sortedget_suggestions_labels)r   expecteds     r   assert_suggestion_labels_arez&BaseStory.assert_suggestion_labels_aret   s7     h6$*E*E*G*G#H#HHHHHHHr   c                     d}|r>t          | j        j        j                  dk    rnt	          j        d           |dz  }|>| j        j        j        d         | j        j        j        _        d| _        dS )z$Wait for and switch to popup window.
      皙?   TN)lenr	   r   windowstimesleepcurrentr   )r   triess     r   switch_to_popupzBaseStory.switch_to_popupy   sw     	49$,--22JsOOOQJE	  	 -1I,=,Ea,H	!)r   c                 j    | j         j        j        d         | j         j        j        _        d| _        dS )zSwitch back to main window.r   FN)r	   r   rP   rS   r   r'   s    r   switch_to_mainzBaseStory.switch_to_main   s*    ,0I,=,Ea,H	!)r   c                    d}| j         s|dz  }| j        j                            |          j        }|                                 d}|rUt          | j        j        j                  dk    r| j         rn+	 |j         n#  Y nxY w|dz  }t          j
        d           |U| j         s| j                                         dS dS )zSubmit the form.zinput[type=submit]z[name=_continue]d   rN   g?N)r   r	   r   r   firstclickrO   rP   visiblerQ   rR   wait_script)r   selelrT   s       r   rC   zBaseStory.submit   s    "} 	&%%CY**3//5



  	49$,--22t}2


QJEJsOOO  	 } 	$I!!#####	$ 	$s   6A> >Bc                 X    | j                             | j        d| j                   dS )zOpen the autocomplete dropdown.r   N)r	   r[   r   r   r'   s    r   toggle_autocompletezBaseStory.toggle_autocomplete   s>    	)))  
 	 	 	 	 	r   c                     |                                   | j        j                            | j                   |                                   dS )zRe-open the autocomplete box.N)ra   r	   r   is_element_not_present_by_cssr   r'   s    r   refresh_autocompletezBaseStory.refresh_autocomplete   sH      """	778LMMM  """""r   c                       fd}d } |            } ||          du r+t          j        d            |            } ||          du +d |D             S )z7Return the list of suggestions in the autocomplete box.c                  L     j         j                             j                  S N)r	   r   r   r   r'   s   r   get_optionsz.BaseStory.get_suggestions.<locals>.get_options   s    9$001EFFFr   c                 \    	 d| d         j         v S # t          $ r Y dS t          $ r Y dS w xY w)N	Searchingr   T)r    r   
IndexError)r"   s    r   is_searchingz/BaseStory.get_suggestions.<locals>.is_searching   sS    "gajo551   tt   tts    
+	++TrM   c                 ,    g | ]}|d          |j         fS )r9   )r    .0os     r   
<listcomp>z-BaseStory.get_suggestions.<locals>.<listcomp>   s#    6667QV$666r   )rQ   rR   )r   rh   rl   r"   s   `   r   get_suggestionszBaseStory.get_suggestions   s    	G 	G 	G 	G 	G	 	 	 +--l7##t++JsOOO!kmmG l7##t++ 76g6666r   c                 >    d |                                  D             S )z6Return labels for suggestions in the autocomplete box.c                     g | ]
}|d          S )rN   r4   rn   s     r   rq   z4BaseStory.get_suggestions_labels.<locals>.<listcomp>   s    555!555r   )rr   r'   s    r   rG   z BaseStory.get_suggestions_labels   s"    55d22445555r   )	NNNNNNNNN)__name__
__module____qualname____doc__r   tenacityretrystop_after_delayr$   r(   r,   r2   r/   r6   r;   r>   rA   rD   rI   rU   rW   rC   ra   rd   rr   rG   r4   r   r   r   r      s        !%#'  $ $!%!%!%   B X^221556666 6 766N N N
 
 
, , ,   X^22155666( ( 76(   X^22155666. . 76.! ! !
! ! ! X^22155666I I 76I
 
 
  
$ $ $:  # # #7 7 7&6 6 6 6 6r   r   c                       e Zd ZdZd Zd ZdS )SelectOptionzUser selects an option.c                 n   | j         j                            | j                  }t	          |          r|j        s|                                  | j                             | j                   | j                             | j	        |           | 
                    |                                           dS )z7Assert that selecting option "text" sets input's value.N)r	   r   r   r   rO   r\   ra   assert_visible
enter_textr   r$   r[   )r   r    dropdowns      r   select_optionzSelectOption.select_option   s    9$001GHH8}} 	'H$4 	'$$&&&	  !7888	T0$777$$&&&&&r   c                 D    | j                             | j                   dS )zClear current option.N)r	   r[   r   r'   s    r   clear_optionzSelectOption.clear_option   s    	122222r   N)ru   rv   rw   rx   r   r   r4   r   r   r}   r}      s8        !!' ' '3 3 3 3 3r   r}   c                   $     e Zd ZdZd fd	Z xZS )InlineSelectOptionz/Same as UserCanSelectOption, in a given inline.Nc                    || _         |p|j        | _         t          t          |           j        |fi | d| j        d| j         d| j        | _        d| j        d| j         d| j        | _        | j        j	        j
                            d          j        }t          | j        j	                            d| j        z                      }|| j         dz   k     r|                                 	 | j        j	                            | j                            t#          | j                   t#          |                              j         n#  Y xY w|dz  }|| j         dz   k     dS dS )	z
        Do the same as UserCanSelectOption, in inline inline_number.

        Where inline_related_name should be the related_name option for the
        foreign key used for the InlineModelAdmin.
        #-z .field-z#id_zAdd anotherz.dynamic-%srN   N)inline_numberinline_related_namesuperr   r   r   r   r   r	   r   linksfind_by_partial_textrZ   rO   r   r[   replacer=   )r   r	   r   r   kwargsaddnum	__class__s          r   r   zInlineSelectOption.__init__   s    +$7 %@'+'? 	  	1 $''0@@@@@@ $$$d&8&8&8$//)K%% $$$OO
 i%::=IIOI)) 88 
 

 D&***IIKKK	!--'//D.//C  
 %%1HC D&*******s   6AE Erg   ru   rv   rw   rx   r   __classcell__r   s   @r   r   r      sC        99, , , , , , , , , ,r   r   c                       e Zd ZdZd ZdS )RenameOptionz/User story to rename an option in django admin.c                 x   | j                             d| j        z             |                                  | j         j                            d          }| j                             |d         |           | j                             d|           |                                  | 	                                 dS )z0Click the change button and rename in the popup.z#change_id_%sid_namer9   #id_nameN)
r	   r[   r   rU   r   
find_by_idassertEqualr   rC   rW   )r   current_nameadd_keys
name_inputs       r   rename_optionzRenameOption.rename_option  s    	$/9:::Y&11)<<
	w	
 	
 	

 		Z222r   N)ru   rv   rw   rx   r   r4   r   r   r   r     s)        99    r   r   c                       e Zd ZdZd ZdS )AddAnotherOptionzAdd-another user story.c                 &   | j         j                            d| j        z                                             |                                  | j                             d|           |                                  |                                  dS )z9Click the add button and add another option in the popup.z	add_id_%sr   N)	r	   r   r   r   r[   rU   r   rC   rW   r   names     r   add_anotherzAddAnotherOption.add_another'  s}    	$$[4?%BCCIIKKK	Z...r   N)ru   rv   rw   rx   r   r4   r   r   r   r   $  s)        !!    r   r   c                       e Zd ZdZd ZdS )CreateOptionzCreate an option on the fly.c                 (   |                                   | j                            | j        |           | j        j                            |           | j                            | j                   | j        j                            d           dS )zf
        Select the only option after typing name and submit.

        name should be unique.
        z.select2-results__optionsN)	ra   r	   r   r   r   is_element_present_by_textr[   r   rc   r   s     r   create_optionzCreateOption.create_option4  s     	  """	T0$777	44T:::	,---	77'	
 	
 	
 	
 	
r   N)ru   rv   rw   rx   r   r4   r   r   r   r   1  s)        &&
 
 
 
 
r   r   c                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )MultipleMixinz,Enable multiple choice support with stories.c                 $    | j         d| j        S r&   )r   r   r'   s    r   get_field_labels_selectorz'MultipleMixin.get_field_labels_selectorG  s    7779M9MNNr   c                 n    | j         j                            d|                                 z             dS )r*   z
            document.querySelectorAll("%s span").forEach(function(node) {
                node.parentNode.removeChild(node);
            });
            N)r	   r   r+   r   r'   s    r   r,   z+MultipleMixin.clean_label_from_remove_butonK  sD    	(( 0022	3	
 	
 	
 	
 	
r   c                                                          j        j                                                                       } fd|D             S )r.   c                 D    g | ]}                     |j                  S r4   )r/   r    )ro   r1   r   s     r   rq   z,MultipleMixin.get_labels.<locals>.<listcomp>]  s9     
 
 
 UZ((
 
 
r   )r,   r	   r   r   r   )r   labelss   ` r   
get_labelszMultipleMixin.get_labelsU  si    **,,,"..**,,
 

 
 
 

 
 
 	
r   c                     d| j         z  }| j        j                            |           | j        j                            d          S )r8   z
        window.GET_VALUES = [];
        document.querySelectorAll("%s option:checked").forEach(function(opt) {
            GET_VALUES.push(opt.value);
        });
        zwindow.GET_VALUES)r   r	   r   r+   evaluate_script)r   scripts     r   
get_valueszMultipleMixin.get_valuesb  sK    
 !" 		((000y 001DEEEr   c                     |                                  }|D ]}| j                            ||           | j                            t	          |          t	          |                     dS )z#Assert that all labels match texts.N)r   r	   assertInr   rO   )r   textsr   r    s       r   assert_labelszMultipleMixin.assert_labelsm  se    "" 	- 	-DItV,,,,	c%jj#f++66666r   c                     d |D             }|                                  }|D ]}| j                            ||           | j                            t	          |          t	          |                     dS )z3Assert that the actual field values matches values.c                 ,    g | ]}t          |          S r4   )r=   )ro   vs     r   rq   z/MultipleMixin.assert_values.<locals>.<listcomp>x  s    ...!s1vv...r   N)r   r	   r   r   rO   )r   valuestext_valuesactual_valuesactual_values        r   assert_valueszMultipleMixin.assert_valuesv  s    ..v...))) 	 	LI   
 		c&kk3}+=+=>>>>>r   c                 Z    |                      |           |                     |           dS )z)Assert selections have values and labels.N)r   r   r   r   r   s      r   rA   zMultipleMixin.assert_selection  s0    6"""6"""""r   c                     |                      ||           |                                  |                     |           |                     |           dS )z@Do the same as above, but also submits the form and check again.N)rA   rC   r   r   r   s      r   rD   z'MultipleMixin.assert_selection_persists  sS    ff---6"""6"""""r   N)ru   rv   rw   rx   r   r,   r   r   r   r   rA   rD   r4   r   r   r   r   D  s        66O O O
 
 

 
 
	F 	F 	F7 7 7? ? ?# # #
# # # # #r   r   c                       e Zd ZdZdS )CreateOptionMultiple"Multiple version of CreateOptions.Nru   rv   rw   rx   r4   r   r   r   r             ,,,,r   r   c                       e Zd ZdZdS )SelectOptionMultipler   Nr   r4   r   r   r   r     r   r   r   c                   $     e Zd ZdZd fd	Z xZS )InlineSelectOptionMultiplez(Multiple options for InlineSelectOption.Nc                 |     t          t          |           j        ||fd|i| | j        d| j        | _        dS )z1Set input_selector with field_container_selector.r   r   N)r   r   r   r   r   )r   r	   r   r   r   r   s        r   r   z#InlineSelectOptionMultiple.__init__  sm     	9($//8	
 	
 !4	
 		
 	
 	
 )))
r   rg   r   r   s   @r   r   r     sC        22
 
 
 
 
 
 
 
 
 
r   r   )rx   
__future__r   rQ   selenium.common.exceptionsr   ry   objectr   r}   r   r   r   r   r   r   r   r   r4   r   r   <module>r      s   > > ' ' ' ' ' '       |6 |6 |6 |6 |6 |6 |6 |6~3 3 3 3 39 3 3 3$/ / / / / / / /d    <   (
 
 
 
 
y 
 
 

 
 
 
 
< 
 
 
&I# I# I# I# I#F I# I# I#X- - - - -=, - - -- - - - -=, - - -
 
 
 
 
0B 
 
 
 
 
r   