test_browser.rb 11.6 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
66
67
    # check the welcoming popup
    assert ($b.div(:id => 'popup-msg').present?), "Popup message is not present at the opening of Vidjil"
    
Mikaël Salson's avatar
Mikaël Salson committed
68
69
    # close the welcoming popup
    $b.div(:id => 'popup-msg').button(:text => 'ok').click
70
    assert (not $b.div(:id => '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
117
118
    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"
    $b.div(:id => 'data-container').span(:class => 'closeButton').click
    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
152
    return ### TODO

153
    clone_name = $b.clone_info('24')[:name]
Mikaël Salson's avatar
Mikaël Salson committed
154
    clone_name.double_click
155

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

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

Mikaël Salson's avatar
Mikaël Salson committed
163
  def check_when_list_or_scatterplot_focused
Marc Duez's avatar
Marc Duez committed
164
165
    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"
166

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

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

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

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

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

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

Marc Duez's avatar
Marc Duez committed
196
197
198
199
    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"
200

Mikaël Salson's avatar
Mikaël Salson committed
201
202
    stats = $b.statsline
    assert (stats.text.include? '1 clone'), ">> Incorrect stats, should have one clone"
Marc Duez's avatar
Marc Duez committed
203
204
    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
205
  end
206

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

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

Mikaël Salson's avatar
Mikaël Salson committed
214
    $b.unselect
215
    $b.clone_in_scatterplot('24').click  # TODO: to be removed when $b.unselect works
216
    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
217
  end
218

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

Mikaël Salson's avatar
Mikaël Salson committed
223
    check_when_list_or_scatterplot_clicked
224

Mikaël Salson's avatar
Mikaël Salson committed
225
    $b.unselect
226
    $b.clone_in_scatterplot('24').click  # TODO: to be removed when $b.unselect works
227
    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
228
  end
Marc Duez's avatar
Marc Duez committed
229

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

    $b.unselect
Mikaël Salson's avatar
Mikaël Salson committed
243
244
245
246
  end

  def test_10_imgt
    begin
Marc Duez's avatar
Marc Duez committed
247
248
      $b.clone_in_scatterplot('25').wait_until_present
      $b.clone_in_scatterplot('25').click
Mikaël Salson's avatar
Mikaël Salson committed
249
250
251
252
253
254
      
      $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
255
256
        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
257
258
      end
      
Mathieu Giraud's avatar
Mathieu Giraud committed
259
      $b.window(:title => "analysis-example").use
Mikaël Salson's avatar
Mikaël Salson committed
260
261
262
263
264
265
266
      
    end
  end
  
  
  def test_11_igBlast
    begin
Marc Duez's avatar
Marc Duez committed
267
268
      $b.clone_in_scatterplot('25').wait_until_present
      $b.clone_in_scatterplot('25').click
Mikaël Salson's avatar
Mikaël Salson committed
269
270
271
272
273
      
      $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
274
275
276
        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
277
278
      end
      
Mathieu Giraud's avatar
Mathieu Giraud committed
279
      $b.window(:title => "analysis-example").use
280
    end
Mikaël Salson's avatar
Mikaël Salson committed
281
  end
282
283


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

Marc Duez's avatar
Marc Duez committed
292
      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
293
    end
Mikaël Salson's avatar
Mikaël Salson committed
294
295
296
297
298
  end
  

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

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

Mathieu Giraud's avatar
Mathieu Giraud committed
308
309
310
311
312
313
314
      $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
315
316
      edit.wait_until_present
      edit.click
Mathieu Giraud's avatar
Mathieu Giraud committed
317
      $b.tag_selector_edit_name.set 'renamed_return'
Mikaël Salson's avatar
Mikaël Salson committed
318
      $b.send_keys :return
Marc Duez's avatar
Marc Duez committed
319

Mikaël Salson's avatar
Mikaël Salson committed
320
      $b.tag_selector_close.click
Mathieu Giraud's avatar
Mathieu Giraud committed
321
      $b.tag_selector.wait_while_present
Marc Duez's avatar
Marc Duez committed
322

Mathieu Giraud's avatar
Mathieu Giraud committed
323
324
325
326
327
328
329
330
331
332
      ## 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
333
    end
Mikaël Salson's avatar
Mikaël Salson committed
334
  end
Marc Duez's avatar
Marc Duez committed
335
336
  

337

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

Marc Duez's avatar
Marc Duez committed
347
348
end

Marc Duez's avatar
Marc Duez committed
349
350
351
352
353
354
355
356
357
358
359
360
361
=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 
362
=end