test_browser.rb 11.4 KB
Newer Older
Marc Duez's avatar
Marc Duez committed
1
require 'rubygems'
marc duez's avatar
marc duez committed
2
gem "minitest"
Marc Duez's avatar
Marc Duez committed
3
require 'watir-webdriver'
Marc Duez's avatar
Marc Duez committed
4
5
require 'test/unit'
require "minitest/autorun"
6
require 'minitest/ci'
7
8
9
if ENV['HEADLESS']
  require 'headless'
end
10
load 'vidjil_browser.rb'
Marc Duez's avatar
Marc Duez committed
11

Marc Duez's avatar
Marc Duez committed
12
include Test::Unit::Assertions
13
MiniTest.autorun
Marc Duez's avatar
Marc Duez committed
14

15
16
17
18
19
20
21
22
#browser test suite
class Browser < MiniTest::Test

  def self.test_order
    :alpha
  end

  def setup
Mikaël Salson's avatar
Mikaël Salson committed
23
24
25
26
27
28
29
30
31
    if ENV['HEADLESS'] and not defined? $headless
      $headless = Headless.new
      $headless.start
      print "debut\n"
    end

    if not defined? $b
      set_browser
    end
32
33
34
  end

  def set_browser
Mikaël Salson's avatar
Mikaël Salson committed
35
    folder_path = Dir.pwd
36
37
    folder_path.sub! '/browser/test', ''
    index_path = 'file://' + folder_path + '/browser/index.html'
Marc Duez's avatar
Marc Duez committed
38
    data_path = folder_path + '/doc/analysis-example.vidjil'
39
    analysis_path = folder_path + '/browser/test/test.analysis'
Mikaël Salson's avatar
Mikaël Salson committed
40

41
42
43
44
45
46
    if ENV['LIVE_SERVER']
      index_path = ENV['LIVE_SERVER'] + '/?data='
    end
      
    print "Testing Vidjil browser at " + index_path + "\n"

Mikaël Salson's avatar
Mikaël Salson committed
47
    $b = VidjilBrowser.new :firefox
48
    #$b = VidjilBrowser.new :chrome
49
    $b.window.resize_to(1500, 800)
Mikaël Salson's avatar
Mikaël Salson committed
50
51
    $b.goto index_path

52
53
54
55
56
57
    # check that the browser loaded correctly
    if not $b.div(:id => 'logo').present?
      print "Loading of Vidjil browser failed. Do not execute remaining tests."
      exit
    end

58
    print "Vidjil browser loaded, launching tests.\n"
59
    
60
61
62
63
64
    # A live server can be configured with a database.
    # The welcome popup should not be tested.
    
    if not ENV['LIVE_SERVER']

65
    # check the welcoming popup
Marc Duez's avatar
Marc Duez committed
66
    assert ($b.div(:class => 'popup_msg').present?), "Popup message is not present at the opening of Vidjil"
67
    
Mikaël Salson's avatar
Mikaël Salson committed
68
    # close the welcoming popup
Marc Duez's avatar
Marc Duez committed
69
70
    $b.div(:class => 'popup_msg').button(:text => 'ok').click
    assert (not $b.div(:class => 'popup_msg').present?), "Popup message still present after trying to close it"
Mikaël Salson's avatar
Mikaël Salson committed
71

72
73
    end
    
Mikaël Salson's avatar
Mikaël Salson committed
74
75
76
77
78
79
    $b.div(:id => 'demo_file_menu').click 
    $b.div(:id => 'demo_file_menu').a(:id => 'import_data_anchor').click
    
    # select data file
    $b.div(:id => 'file_menu').file_field(:name,"json").set(data_path)
    $b.div(:id => 'file_menu').button(:text => 'start').click 
80
81
  end

82
  def after_tests
83
  end
Mikaël Salson's avatar
Mikaël Salson committed
84
  
85
  def test_00_info_segmentation
Marc Duez's avatar
Marc Duez committed
86
    assert ($b.div(:id => 'info_segmented').text.include?  '742 377 reads (94.35%)'), ' Incorrect number of segmented reads'
87
  end
Marc Duez's avatar
Marc Duez committed
88

Marc Duez's avatar
Marc Duez committed
89

90
  def test_00_info_reads
Marc Duez's avatar
Marc Duez committed
91
    assert ($b.div(:id => 'info_total').text.include? '786 861 reads'), 'Incorrect number of reads'
92
93
94
  end

  def test_00_default_point_name
Marc Duez's avatar
Marc Duez committed
95
    assert ($b.div(:id => 'info_point').text.include? 'helloworld'), 'Incorrect point name in info box'
96
97
98
  end

  def test_00_germline
Marc Duez's avatar
Marc Duez committed
99
    assert ($b.div(:id => 'info').span(:class => 'systemBoxNameMenu').text.include? 'TRA'), 'missing system TRA'
100
101
102
  end

  def test_00_legend_scatterplot
Marc Duez's avatar
Marc Duez committed
103
104
105
106
    assert ($b.scatterplot_x_legend(0).text == 'TRBV1'), "Bad legend for scatterplot"
    assert ($b.scatterplot_x_legend(4).text == '?'), "Bad legend for scatterplot"
    assert ($b.scatterplot_y_legend(0).text == 'TRBJ1-1'), "Bad legend for scatterplot"
    assert ($b.scatterplot_y_legend(9).text == '?'), "Bad legend for scatterplot"
107
  end
Marc Duez's avatar
Marc Duez committed
108

109
  def test_00_info_point
110
    assert (not $b.div(:id => 'info_timepoint').present?), "Info timepoint should not be present"
111
112
113
114
    $b.div(:id => 'info_point').span(:text => 'Info').click
    assert ($b.div(:id => 'info_timepoint').visible?), "After clicking info timepoint should be visible"

    table = $b.div(:id => 'info_timepoint').table
Marc Duez's avatar
Marc Duez committed
115
116
    assert (table[1][1].text == '786861'), "Incorrect  number of reads in infopoint"
    assert (table[2][1].text.include? '742377'), "Incorrect  number of reads in infopoint"
117
    $b.div(:class => 'data-container').span(:class => 'closeButton').click
Marc Duez's avatar
Marc Duez committed
118
    assert (not $b.div(:id => 'info_timepoint').present?), "Info timepoint should not be present"
119
  end
Marc Duez's avatar
Marc Duez committed
120

Mikaël Salson's avatar
Mikaël Salson committed
121
  def test_01_init
Marc Duez's avatar
Marc Duez committed
122
123
124
125
126
127

      assert ( $b.clone_in_list('25').exists?), ">>fail init : clone 0 missing in list"
      assert ( $b.clone_in_scatterplot('25').exists?), ">>fail init : clone 0 missing in scatterplot"
      #assert ( $b.clone_in_graph('25').exists?), ">>fail init : clone 0 missing in graph"
      assert ( $b.clone_in_list('25').text.include? '0.130%' ) , ">>fail init : wrong clone size "

Mikaël Salson's avatar
Mikaël Salson committed
128
  end
129

Mikaël Salson's avatar
Mikaël Salson committed
130
131
132
133
134
135
136
  def test_02_fold_left_menu
    assert ($b.div(:id => "left-container").present?), ">> fail : left menu should be visible"
    $b.div(:id => "vertical-separator").click
    assert (not $b.div(:id => "left-container").present?), ">> fail : left menu is still visible"
    $b.div(:id => "vertical-separator").click
    assert ($b.div(:id => "left-container").present?), ">> fail : left menu did not reappear"
  end
137

Mikaël Salson's avatar
Mikaël Salson committed
138
  def test_03_rename_clone_by_clicking
Marc Duez's avatar
Marc Duez committed
139
140
    clone_name = $b.clone_info('25')[:name]
    assert (clone_name.text == 'TRBV29*01 -1/0/-0 TRBD1*01 -2/0/-5 TRBJ2-5*01'), " >> clone name is not corect"
Mikaël Salson's avatar
Mikaël Salson committed
141
    clone_name.double_click
142

143
    $b.clone_name_editor.set 'renamed_click'
Mikaël Salson's avatar
Mikaël Salson committed
144
    $b.clone_name_saver.click
145
    assert (clone_name.text == 'renamed_click'), " >> clone name (click) has not changed"
146
147

    $b.unselect
Mikaël Salson's avatar
Mikaël Salson committed
148
  end
149

Mikaël Salson's avatar
Mikaël Salson committed
150
  def test_04_rename_clone_by_enter
151
    sleep 1
152
    clone_name = $b.clone_info('24')[:name]
Mikaël Salson's avatar
Mikaël Salson committed
153
    clone_name.double_click
154

155
    $b.clone_name_editor.set 'renamed_return'
Mikaël Salson's avatar
Mikaël Salson committed
156
    $b.send_keys :return
157
    assert (clone_name.text == 'renamed_return'), " >> clone name (return) has not changed"
158

Mikaël Salson's avatar
Mikaël Salson committed
159
160
    $b.unselect
  end
161

Mikaël Salson's avatar
Mikaël Salson committed
162
  def check_when_list_or_scatterplot_focused
Marc Duez's avatar
Marc Duez committed
163
164
    assert ( $b.clone_in_scatterplot('25', :class => 'circle_focus').exists?), ">> fail to focus correct plot after hovering a clone in the list"
    assert ( $b.clone_in_graph('25', :class => "graph_focus").exists?), ">> fail to focus correct graphLine after hovering a clone in the list"
165

Marc Duez's avatar
Marc Duez committed
166
    clone_name = $b.clone_info('25')[:name]
Mikaël Salson's avatar
Mikaël Salson committed
167
168
    assert ( $b.infoline.text == clone_name.text), ">> Clone name is not correct in focus div"
  end
Marc Duez's avatar
Marc Duez committed
169

Mikaël Salson's avatar
Mikaël Salson committed
170
171
172
173
  def test_05_focus_in_list
    begin
      $b.unselect
      #test hover a clone in the list
Marc Duez's avatar
Marc Duez committed
174
175
      $b.clone_in_scatterplot('25').wait_until_present
      $b.clone_in_list('25').hover
Mikaël Salson's avatar
Mikaël Salson committed
176
177

      check_when_list_or_scatterplot_focused
Marc Duez's avatar
Marc Duez committed
178
    end
Mikaël Salson's avatar
Mikaël Salson committed
179
  end
180

Mikaël Salson's avatar
Mikaël Salson committed
181
182
183
  def test_05_focus_in_scatterplot
    begin
      $b.unselect
Marc Duez's avatar
Marc Duez committed
184
185
      $b.clone_in_scatterplot('25').wait_until_present
      $b.clone_in_scatterplot('25').hover
186

Mikaël Salson's avatar
Mikaël Salson committed
187
      check_when_list_or_scatterplot_focused
188
    end
Mikaël Salson's avatar
Mikaël Salson committed
189
  end
190

Mikaël Salson's avatar
Mikaël Salson committed
191
  def check_when_list_or_scatterplot_clicked
Marc Duez's avatar
Marc Duez committed
192
    clone_name = $b.clone_info('25')[:name]
Mikaël Salson's avatar
Mikaël Salson committed
193
    assert ( $b.infoline.text == clone_name.text), ">> Clone name is not correct in focus div"
194

Marc Duez's avatar
Marc Duez committed
195
196
197
198
    assert ( $b.clone_in_list('25').class_name == "list list_select" )
    assert ( $b.clone_in_scatterplot('25', :class => "circle_select").exists?)
    assert ( $b.clone_in_graph('25', :class=> "graph_select").exists?)
    assert ( $b.clone_in_segmenter('25').exists? ), ">> fail to add clone to segmenter by clicking on the list or scatterplot"
199

Mikaël Salson's avatar
Mikaël Salson committed
200
201
    stats = $b.statsline
    assert (stats.text.include? '1 clone'), ">> Incorrect stats, should have one clone"
Marc Duez's avatar
Marc Duez committed
202
203
    assert (stats.text.include? '962 reads'), ">> Incorrect stats, should have 962 reads"
    assert (stats.text.include? '0.130%'), ">> Incorrect stats, should be at 0.130%"
Mikaël Salson's avatar
Mikaël Salson committed
204
  end
205

Mikaël Salson's avatar
Mikaël Salson committed
206
207
  def test_08_click_in_list
    #test select a clone in the list
Marc Duez's avatar
Marc Duez committed
208
209
    $b.clone_in_scatterplot('25').wait_until_present
    $b.clone_info('25')[:name].click()
210

Mikaël Salson's avatar
Mikaël Salson committed
211
    check_when_list_or_scatterplot_clicked
212

Mikaël Salson's avatar
Mikaël Salson committed
213
    $b.unselect
214
    assert ($b.clone_in_list('25').class_name == "list"), ">> Incorrect class name, clone is not unselected'"
Mikaël Salson's avatar
Mikaël Salson committed
215
  end
216

Mikaël Salson's avatar
Mikaël Salson committed
217
  def test_08_click_in_scatterplot
Marc Duez's avatar
Marc Duez committed
218
219
    $b.clone_in_scatterplot('25').wait_until_present
    $b.clone_in_scatterplot('25').click
220

Mikaël Salson's avatar
Mikaël Salson committed
221
    check_when_list_or_scatterplot_clicked
222

Mikaël Salson's avatar
Mikaël Salson committed
223
    $b.unselect
224
    assert ($b.clone_in_list('25').class_name == "list"), ">> Incorrect class name, clone is not unselected'"
Mikaël Salson's avatar
Mikaël Salson committed
225
  end
Marc Duez's avatar
Marc Duez committed
226

Mikaël Salson's avatar
Mikaël Salson committed
227
  def test_09_normalize
Marc Duez's avatar
Marc Duez committed
228
    $b.clone_info('25')[:star].click
Mikaël Salson's avatar
Mikaël Salson committed
229
230
231
    $b.tag_selector_edit_normalisation.wait_until_present
    $b.tag_selector_edit_normalisation.set('0.01')
    $b.tag_selector_normalisation_validator.click 
232
    
Marc Duez's avatar
Marc Duez committed
233
    assert ( $b.clone_info('25')[:size].text == '1.000%' ) , ">> fail normalize on : wrong clone size "
234
    
Mikaël Salson's avatar
Mikaël Salson committed
235
236
    $b.menu_settings.click 
    $b.radio(:id => 'reset_norm').click
Marc Duez's avatar
Marc Duez committed
237
    assert ( $b.clone_info('25')[:size].text == '0.130%' ) , ">> fail normalize off : wrong clone size "
238
239

    $b.unselect
Mikaël Salson's avatar
Mikaël Salson committed
240
241
242
243
  end

  def test_10_imgt
    begin
Marc Duez's avatar
Marc Duez committed
244
245
      $b.clone_in_scatterplot('25').wait_until_present
      $b.clone_in_scatterplot('25').click
Mikaël Salson's avatar
Mikaël Salson committed
246
247
248
249
250
251
      
      $b.span(:id => "toIMGT" ).click
      
      assert ( $b.window(:title => "IMGT/V-QUEST").exists? ) , ">> fail opening IMGT "
      $b.window(:title => "IMGT/V-QUEST").use do
        assert ($b.text.include? "Number of analysed sequences: 1"), ">> fail IMGT analysis"
Marc Duez's avatar
Marc Duez committed
252
253
        assert ($b.text.include? "Homsap TRBV28*01"), ">> IMGT expected V not found"
        assert ($b.text.include? "Homsap TRBJ2-5*01"), ">> IMGT expected J not found"
Mikaël Salson's avatar
Mikaël Salson committed
254
255
      end
      
Mathieu Giraud's avatar
Mathieu Giraud committed
256
      $b.window(:title => "analysis-example").use
Mikaël Salson's avatar
Mikaël Salson committed
257
258
259
260
261
262
263
      
    end
  end
  
  
  def test_11_igBlast
    begin
Marc Duez's avatar
Marc Duez committed
264
265
      $b.clone_in_scatterplot('25').wait_until_present
      $b.clone_in_scatterplot('25').click
Mikaël Salson's avatar
Mikaël Salson committed
266
267
268
269
270
      
      $b.span(:id => "toIgBlast" ).click
      
      assert ( $b.window(:title => "IgBLAST Search Results").exists? ) , ">> fail opening igblast "
      $b.window(:title => "IgBLAST Search Results").use do
Marc Duez's avatar
Marc Duez committed
271
272
273
        assert ($b.text.include? "Length=180"), ">> igblast: was not launched on the correct sequence"
        assert ($b.text.include? "TRBV28*01"), ">> igblast: expected V not found"
        assert ($b.text.include? "TRBJ2-5*01"), ">> igblast: expected Js not found"
Mikaël Salson's avatar
Mikaël Salson committed
274
275
      end
      
Mathieu Giraud's avatar
Mathieu Giraud committed
276
      $b.window(:title => "analysis-example").use
277
    end
Mikaël Salson's avatar
Mikaël Salson committed
278
  end
279
280


Mikaël Salson's avatar
Mikaël Salson committed
281
282
  def test_12_tag
    begin
Marc Duez's avatar
Marc Duez committed
283
      $b.clone_info('25')[:star].click
284
285
286
287
      name = $b.tag_item('0')[:name]
      name.wait_until_present
      name.click
      name.wait_while_present
288

Marc Duez's avatar
Marc Duez committed
289
      assert ($b.clone_info('25')[:name].style('color') ==  'rgba(220, 50, 47, 1)' ) , ">> fail tag : clone color hasn't changed"
Marc Duez's avatar
Marc Duez committed
290
    end
Mikaël Salson's avatar
Mikaël Salson committed
291
292
293
294
295
  end
  

  def test_14_edit_tag
    begin
Mathieu Giraud's avatar
Mathieu Giraud committed
296
      ## rename Tag 0
Marc Duez's avatar
Marc Duez committed
297
      $b.clone_info('25')[:star].click
Mathieu Giraud's avatar
Mathieu Giraud committed
298

Mikaël Salson's avatar
Mikaël Salson committed
299
300
301
      edit = $b.tag_item('0')[:edit]
      edit.wait_until_present
      edit.click
Mathieu Giraud's avatar
Mathieu Giraud committed
302
      $b.tag_selector_edit_name.set 'renamed_click'
Mikaël Salson's avatar
Mikaël Salson committed
303
304
      $b.tag_selector_name_validator.click

Mathieu Giraud's avatar
Mathieu Giraud committed
305
306
307
308
309
310
311
      $b.tag_selector_close.click
      $b.tag_selector.wait_while_present

      ## rename Tag 1 (on another clone)
      $b.clone_info('24')[:star].click

      edit = $b.tag_item('1')[:edit]
Marc Duez's avatar
Marc Duez committed
312
313
      edit.wait_until_present
      edit.click
Mathieu Giraud's avatar
Mathieu Giraud committed
314
      $b.tag_selector_edit_name.set 'renamed_return'
Mikaël Salson's avatar
Mikaël Salson committed
315
      $b.send_keys :return
Marc Duez's avatar
Marc Duez committed
316

Mikaël Salson's avatar
Mikaël Salson committed
317
      $b.tag_selector_close.click
Mathieu Giraud's avatar
Mathieu Giraud committed
318
      $b.tag_selector.wait_while_present
Marc Duez's avatar
Marc Duez committed
319

Mathieu Giraud's avatar
Mathieu Giraud committed
320
321
322
323
324
325
326
327
328
329
      ## check renames (on again another clone)
      $b.clone_info('23')[:star].click
      edit = $b.tag_item('1')[:edit]
      edit.wait_until_present

      assert ($b.tag_selector.text.include? 'renamed_click'),  "fail edit tag with mouse : tag name in tag selector hasn't changed"
      assert ($b.tag_selector.text.include? 'renamed_return'), "fail edit tag with keyboard : tag name in tag selector hasn't changed"

      $b.tag_selector_close.click
      $b.tag_selector.wait_while_present
330
    end
Mikaël Salson's avatar
Mikaël Salson committed
331
  end
Marc Duez's avatar
Marc Duez committed
332
333
  

334

Mikaël Salson's avatar
Mikaël Salson committed
335
336
  # Not really a test, used to close server at the end
  def test_zz_close_everything
337
    print "\nTests finished, closing browser.\n"
Mikaël Salson's avatar
Mikaël Salson committed
338
339
340
    $b.close
    if ENV['HEADLESS']
      $headless.destroy
341
    end
Mikaël Salson's avatar
Mikaël Salson committed
342
  end
343

Marc Duez's avatar
Marc Duez committed
344
345
end

Marc Duez's avatar
Marc Duez committed
346
347
348
349
350
351
352
353
354
355
356
357
358
=begin
    TODO
    save_analysis
    clipboard
    edit tag
    change axis scatterplot
    edit name
    change color method
    change color palette
    change scatterplot/graph size
    
    check x/y clone position on scatterplot
    check clone path 
359
=end