Skip to content

Commit

Permalink
Merge pull request #661 from tadast/tt/fix-tests
Browse files Browse the repository at this point in the history
Fix flaky capybara tests
  • Loading branch information
yannickwurm committed Jul 10, 2023
2 parents ccbca7f + cbb8483 commit 0237c7c
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 121 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ doc
# jeweler generated
pkg

# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
#
# * Create a file at ~/.gitignore
# * Include files you want ignored
Expand Down Expand Up @@ -54,3 +54,6 @@ pkg
.gems/*
Gemfile.lock
node_modules

spec/dotdir/*
spec/downloads/*
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Metrics/AbcSize:
Exclude:
# TODO
- 'lib/sequenceserver.rb'
- 'spec/**'
Metrics/MethodLength:
# Because 15 lines in a method is just about as good as 10 (default). And we
# have a couple that can't be helped.
Expand All @@ -30,6 +31,7 @@ Metrics/BlockLength:
Exclude:
- 'bin/sequenceserver'
- 'sequenceserver.gemspec'
- 'spec/**'

Style/UnlessElse:
# TODO:
Expand Down
24 changes: 12 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GEM
addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
capybara (3.39.0)
capybara (3.39.2)
addressable
matrix
mini_mime (>= 0.1.3)
Expand All @@ -23,7 +23,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
capybara-screenshot (1.0.24)
capybara-screenshot (1.0.26)
capybara (>= 1.0, < 4)
launchy
childprocess (3.0.0)
Expand All @@ -32,16 +32,16 @@ GEM
docile (1.3.2)
json (2.3.0)
json_pure (2.6.3)
launchy (2.4.3)
addressable (~> 2.3)
launchy (2.5.2)
addressable (~> 2.8)
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.2)
mini_portile2 (2.8.1)
mini_portile2 (2.8.2)
mustermann (2.0.2)
ruby2_keywords (~> 0.0.1)
nokogiri (1.14.3)
mini_portile2 (~> 2.8.0)
nokogiri (1.15.3)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
ox (2.14.16)
parallel (1.23.0)
Expand All @@ -51,8 +51,8 @@ GEM
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.1)
racc (1.6.2)
rack (2.2.6.4)
racc (1.7.1)
rack (2.2.7)
rack-protection (2.2.4)
rack
rack-test (1.1.0)
Expand All @@ -64,15 +64,15 @@ GEM
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.1)
rspec-support (~> 3.9.1)
rspec-core (3.9.3)
rspec-support (~> 3.9.3)
rspec-expectations (3.9.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.2)
rspec-support (3.9.4)
rubocop (1.50.2)
json (~> 2.3)
parallel (~> 1.10)
Expand Down
6 changes: 3 additions & 3 deletions public/js/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ class Report extends Component {
// remove attributes from link if sequence_ids array is empty
$('.download-alignment-of-selected').attr('href', '#').removeAttr('download');
return;

}
if(this.state.alignment_blob_url){
// always revoke existing url if any because this method will always create a new url
Expand All @@ -503,7 +503,7 @@ class Report extends Component {
}
});
}, this));
const filename = 'alignment-' + sequence_ids.length + '_hits';
const filename = 'alignment-' + sequence_ids.length + '_hits.txt';
const blob_url = aln_exporter.prepare_alignments_for_export(hsps_arr, filename);
// set required download attributes for link
$('.download-alignment-of-selected').attr('href', blob_url).attr('download', filename);
Expand All @@ -528,7 +528,7 @@ class Report extends Component {
);

var aln_exporter = new AlignmentExporter();
var file_name = `alignment-${num_hits}_hits`;
var file_name = `alignment-${num_hits}_hits.txt`;
const blob_url = aln_exporter.prepare_alignments_for_export(hsps_arr, file_name);
$('.download-alignment-of-all')
.attr('href', blob_url)
Expand Down
2 changes: 1 addition & 1 deletion public/sequenceserver-report.min.js

Large diffs are not rendered by default.

150 changes: 80 additions & 70 deletions spec/capybara_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,70 @@
visit '/'
fill_in('sequence', with: nucleotide_query)

prot = page.evaluate_script("$('.protein .database').text().trim()")
prot.should eq("2020-11 Swiss-Prot insecta 2020-11-Swiss-Prot insecta (subset taxid 102803) Sinvicta 2-2-3 prot subset without_parse_seqids.fa")

nucl = page.evaluate_script("$('.nucleotide .database').text().trim()")
nucl.should eq("Sinvicta 2-2-3 cdna subset Solenopsis invicta gnG subset funky ids (v5)")
expect(page).to have_selector('.protein .database', text: /\A2020-11 Swiss-Prot insecta\z/)
expect(page).to have_selector('.protein .database', text: '2020-11-Swiss-Prot insecta (subset taxid 102803)')
expect(page).to have_selector('.protein .database', text: 'Sinvicta 2-2-3 prot subset')
expect(page).to have_selector('.protein .database', text: 'without_parse_seqids.fa')

expect(page).to have_selector('.nucleotide .database', text: 'Sinvicta 2-2-3 cdna subset')
expect(page).to have_selector('.nucleotide .database', text: 'Solenopsis invicta gnG subset')
expect(page).to have_selector('.nucleotide .database', text: 'funky ids (v5)')
end

it 'properly controls blast button' do
it 'keeps the CTA disabled until a sequence is provided and database selected' do
visit '/'

fill_in('sequence', with: nucleotide_query)
page.evaluate_script("$('#method').is(':disabled')").should eq(true)
expect(page).to have_selector('#method:disabled')

check(nucleotide_databases.first)
page.evaluate_script("$('#method').is(':disabled')").should eq(false)
expect(page).to have_selector('#method:enabled')
end

it 'properly controls interaction with database listing' do
it 'disables protein DB selection if a nucleotide DB is already selected' do
visit '/'
fill_in('sequence', with: nucleotide_query)
check(nucleotide_databases.first)
page.evaluate_script("$('.protein .database').first().hasClass('disabled')")
.should eq(true)

expect(page).to have_no_selector('.protein .database:enabled')
end

it 'shows a dropdown menu when other blast methods are available' do
visit '/'
fill_in('sequence', with: nucleotide_query)
check(nucleotide_databases.first)
page.has_css?('#methods button.dropdown-toggle').should eq(true)
expect(page).to have_selector('#methods button.dropdown-toggle')
end

it 'can run a simple blastn search' do
perform_search query: nucleotide_query,
databases: nucleotide_databases
page.should have_content('BLASTN')
expect(page).to have_content('BLASTN')
end

it 'can run a simple blastp search' do
perform_search query: protein_query,
databases: protein_databases
page.should have_content('BLASTP')
expect(page).to have_content('BLASTP')
end

it 'can run a simple blastx search' do
perform_search query: nucleotide_query,
databases: protein_databases
page.should have_content('BLASTX')
expect(page).to have_content('BLASTX')
end

it 'can run a simple tblastx search' do
perform_search query: nucleotide_query,
databases: nucleotide_databases,
method: 'tblastx'
page.should have_content('TBLASTX')
expect(page).to have_content('TBLASTX')
end

it 'can run a simple tblastn search' do
perform_search query: protein_query,
databases: nucleotide_databases
page.should have_content('TBLASTN')
expect(page).to have_content('TBLASTN')
end

### Test aspects of the generated report.
Expand All @@ -80,7 +83,7 @@

# Click on the first FASTA download button on the page and wait for the
# download to finish.
page.execute_script("$('.download-fa:eq(0)').click()")
page.first('.download-fa').click
wait_for_download

# Test name and content of the downloaded file.
Expand Down Expand Up @@ -141,7 +144,7 @@

# Click on the first Alignment download button on the page and wait for the
# download to finish.
page.execute_script("$('.download-aln:eq(0)').click()")
page.first('.download-aln').click
wait_for_download

# Test name and content of the downloaded file.
Expand Down Expand Up @@ -222,7 +225,7 @@
href = page.find('#sendEmail')['href']
expect(href).to include('mailto:?subject=SequenceServer%20BLASTP%20analysis')
expect(href).to include(page.current_url)
expect(href).to include(protein_databases.values_at(0).join() && '%20')
expect(href).to include(protein_databases.values_at(0).join && '%20')
end

it 'can show hit sequences in a modal' do
Expand All @@ -232,7 +235,7 @@
databases: protein_databases.values_at(0))

# Click on the first sequence viewer link in the report.
page.execute_script("$('.view-sequence:eq(0)').click()")
page.first('.view-sequence').click

within('.sequence-viewer') do
page.should have_content('SI2.2.0_06267')
Expand All @@ -245,11 +248,12 @@
SEQ
end

# Dismiss the first modal.
page.execute_script("$('.sequence-viewer').modal('hide')")
# Dismiss the modal.
page.find('.sequence-viewer').send_keys(:escape)
expect(page).to have_no_css('.sequence-viewer')

# Click on the second sequence viewer link in the report.
page.execute_script("$('.view-sequence:eq(1)').click()")
page.find_all('.view-sequence')[1].click

within('.sequence-viewer') do
page.should have_content('SI2.2.0_13722')
Expand All @@ -272,7 +276,7 @@
databases: nucleotide_databases.values_at(0))

# Check that the sequence viewer links are disabled.
page.evaluate_script("$('.view-sequence').is(':disabled')").should eq(true)
expect(page).to have_selector('.view-sequence:disabled')
end

it 'can download visualisations in svg and png format' do
Expand All @@ -282,60 +286,66 @@
databases: protein_databases.values_at(0))

## Check that there is a circos vis and unfold it.
page.should have_content('Queries and their top hits: chord diagram')
page.execute_script("$('.circos > .grapher-header > h4').click()")
sleep 1
page.find('.circos > .grapher-header > h4', text: 'Queries and their top hits: chord diagram').click

page.execute_script("$('.export-to-svg:eq(0)').click()")
wait_for_download
expect(File.basename(downloaded_file)).to eq('Circos-visualisation.svg')
clear_downloads
within('.circos.grapher') do
page.click_on('SVG')
wait_for_download
expect(File.basename(downloaded_file)).to eq('Circos-visualisation.svg')
clear_downloads

page.execute_script("$('.export-to-png:eq(0)').click()")
wait_for_download
expect(File.basename(downloaded_file)).to eq('Circos-visualisation.png')
page.click_on('PNG')
wait_for_download
expect(File.basename(downloaded_file)).to eq('Circos-visualisation.png')
end
clear_downloads

## Check that there is a graphical overview of hits.
page.should have_content('Graphical overview of hits')

page.execute_script("$('.export-to-svg:eq(1)').click()")
wait_for_download
expect(File.basename(downloaded_file)).to eq('Alignment-Overview-Query_1.svg')
clear_downloads

page.execute_script("$('.export-to-png:eq(1)').click()")
wait_for_download
expect(File.basename(downloaded_file)).to eq('Alignment-Overview-Query_1.png')
clear_downloads
expect(page).to have_content('Graphical overview of hits')

within('#Query_1 .alignment-overview.grapher') do
page.click_on('SVG')
wait_for_download
expect(File.basename(downloaded_file)).to eq('Alignment-Overview-Query_1.svg')
clear_downloads

page.click_on('PNG')
wait_for_download
expect(File.basename(downloaded_file)).to eq('Alignment-Overview-Query_1.png')
clear_downloads
end

## Check that there is a length distribution of matching sequences.
page.should have_content('Length distribution of matching sequences')
page.execute_script("$('.length-distribution > .grapher-header > h4').click()")
sleep 1

page.execute_script("$('.export-to-svg:eq(2)').click()")
wait_for_download
expect(File.basename(downloaded_file)).to eq('length-distribution-Query_1.svg')
clear_downloads

page.execute_script("$('.export-to-png:eq(2)').click()")
wait_for_download
expect(File.basename(downloaded_file)).to eq('length-distribution-Query_1.png')
clear_downloads
expect(page).to have_content('Length distribution of matching sequences')
page.find('#Query_1 .length-distribution > .grapher-header > h4',
text: 'Length distribution of matching sequences').click

within('#Query_1 .length-distribution.grapher') do
page.click_on('SVG')
wait_for_download
expect(File.basename(downloaded_file)).to eq('length-distribution-Query_1.svg')
clear_downloads

page.click_on('PNG')
wait_for_download
expect(File.basename(downloaded_file)).to eq('length-distribution-Query_1.png')
clear_downloads
end

## Check that there is a kablammo vis of query vs hit.
page.should have_content('Graphical overview of aligning region(s)')

page.execute_script("$('.export-to-svg:eq(3)').click()")
wait_for_download
expect(File.basename(downloaded_file)).to eq('Kablammo-Query_1-SI2_2_0_06267.svg')
clear_downloads

page.execute_script("$('.export-to-png:eq(3)').click()")
wait_for_download
expect(File.basename(downloaded_file)).to eq('Kablammo-Query_1-SI2_2_0_06267.png')
clear_downloads
expect(page).to have_content('Graphical overview of aligning region(s)')

within('#Query_1_hit_1 .kablammo.grapher') do
page.click_on('SVG')
wait_for_download
expect(File.basename(downloaded_file)).to eq('Kablammo-Query_1-SI2_2_0_06267.svg')
clear_downloads

page.click_on('PNG')
wait_for_download
expect(File.basename(downloaded_file)).to eq('Kablammo-Query_1-SI2_2_0_06267.png')
clear_downloads
end
end

## Helpers ##
Expand Down
Loading

0 comments on commit 0237c7c

Please sign in to comment.