Skip to content
Snippets Groups Projects
Commit b963ec93 authored by Hernandez-Courbevoie Yohan's avatar Hernandez-Courbevoie Yohan
Browse files

Add tests

parent 172d28ab
No related branches found
No related tags found
No related merge requests found
default:
image: docker:24.0.5
services:
- docker:24.0.5-dind
before_script:
- docker info
variables:
DOCKER_TLS_CERTDIR: "/certs"
stages:
- build
- test
build-job:
stage: build
script:
- apt install ruby
- gem install bundler
- sudo -u nobody -g nogroup bundle install
- apt install git
- git clone https://github.com/touzet/pampa.git
- docker build -t pampa:web .
- docker run -dtp 80:80 pampa:web
test-home:
stage: test
script:
- ruby tests/test_home.rb
test-form:
stage: test
script:
- ruby tests/test_form.rb
test-help:
stage: test
script:
- ruby tests/test_help.rb
test-analysis:
stage: test
script:
- ruby tests/test_analysis.rb
# -- Packages --
require 'rubygems'
# require 'webdrivers'
require 'watir'
require 'test/unit'
require 'open-uri'
require 'email_address'
puts "=========================================================================="
puts " Testing PAMPA Web"
puts "=========================================================================="
$browsers = [
"Watir::Browser.new :chrome, options: {args: ['--no-sandbox']}",
"Watir::Browser.new :firefox, options: {args: ['--no-sandbox']}",
"Watir::Browser.new :edge, options: {args: ['--no-sandbox']}"
]
$form_url = "http://localhost/pampa/form.php"
class PampaWebAnalyseTest < Test::Unit::TestCase
def test_01_result_page
puts "* result - Launch page result (1/4)"
$browsers.each do |br_string|
puts br_string
br = eval(br_string)
br.goto $form_url
# launch analysis
e = br.button(id: 'example_1')
assert(e.present?)
e.click
e = br.button(id: 'run')
assert(e.present?)
e.click
br.wait_until {|b| b.url != $form_url}
# check content
e = br.url
assert(/http:\/\/localhost\/pampa\/result\/[A-Za-z0-9_]+\/results\.php/ =~ e)
e = br.h2
assert(e.present? && (e.text.include? "Results for job"))
es = br.elements(css: '#result_pampa td')
assert(es.size == 80)
assert(es[1].text == "Castor canadensis" && es[14].text == "8.09E-10")
e = br.h3
assert(e.present? && e.text == "Download")
es = br.elements(css: "h3 + ul li")
assert(es.size == 4)
br.close
end
end
def test_02_result_links
puts "* result - Buttons and links result (2/4)"
$browsers.each do |br_string|
puts br_string
br = eval(br_string)
br.goto $form_url
# launch analysis
e = br.button(id: 'example_1')
assert(e.present?)
e.click
e = br.button(id: 'run')
assert(e.present?)
e.click
br.wait_until {|b| b.url != $form_url}
# check links
br.div(id: 'center').as.each do |link|
if link.href.start_with?("http") # web links
status_code = URI.open(link.href).status[0]
assert(status_code=='200')
elsif link.href.start_with?("mailto:")
email = link.href[7..-1]
assert(EmailAddress.valid? email)
else
puts '- "' + link.href + '" not tested'
end
end
br.close
end
end
def test_03_details_simple_page
puts "* result - Launch page details simple (3/4)"
$browsers.each do |br_string|
puts br_string
br = eval(br_string)
br.goto $form_url
# launch analysis
e = br.button(id: 'example_1')
assert(e.present?)
e.click
e = br.button(id: 'run')
assert(e.present?)
e.click
br.wait_until {|b| b.url != $form_url}
# launch details page
e = br.elements(css: '#result_pampa td')[1]
assert(e.present?)
e.click
Watir::Wait.until { br.windows.size == 2 }
handles = br.windows.map(&:handle)
window = br.window(handle: handles[1])
window.use
# check content
e = br.url
assert(/http:\/\/localhost\/pampa\/result\/[A-Za-z0-9_]+\/details_Castor-TOF\.php/ =~ e)
e = br.h2
e.text # ODD Avoid firefox from crashing
assert(e.present? && (/Results for job [A-Za-z0-9_]+( \([A-Za-z0-9_]+\))?\nMass spectrum Castor-TOF\.csv/ =~ e.text))
assert(br.text.include? "Taxonomic group : Castor canadensis (species)")
es = br.tds
assert(es.size == 56 && es[1].text == "1177.59461")
e = br.div(css: '[data-root-id]')
assert(e.present?)
br.close
end
end
def test_04_details_multiple_page
puts "* result - Launch page details multiple (4/4)"
$browsers.each do |br_string|
puts br_string
br = eval(br_string)
br.goto $form_url
# launch analysis
e = br.button(id: 'example_1')
assert(e.present?)
e.click
e = br.button(id: 'run')
assert(e.present?)
e.click
br.wait_until {|b| b.url != $form_url}
# launch details page
e = br.elements(css: '#result_pampa td')[56]
assert(e.present?)
e.click
Watir::Wait.until { br.windows.size == 2 }
handles = br.windows.map(&:handle)
window = br.window(handle: handles[1])
window.use
# check content
e = br.url
assert(/http:\/\/localhost\/pampa\/result\/[A-Za-z0-9_]+\/details_Whale-TOF\.php/ =~ e)
e = br.h2
e.text # Need to call `element.text` before assert to prevent firefox from crashing
assert(e.present? && (/Results for job [A-Za-z0-9_]+( \([A-Za-z0-9_]+\))?\nMass spectrum Whale-TOF\.csv/ =~ e.text))
assert(br.text.include? "Taxonomic group : Globicephala melas (species), with P-value 6.32E-16")
es = br.tds
assert(es.size == 234)
assert(es[176].text == "652")
assert(br.text.include? "GPSGEPGTAGSPGTPGPQGLLGAPGFLGLPGSR")
es = br.divs(css: '[data-root-id]')
assert(es.size == 3)
br.close
end
end
end
# -- Packages --
require 'rubygems'
# require 'webdrivers'
require 'watir'
require 'test/unit'
require 'open-uri'
require 'email_address'
puts "=========================================================================="
puts " Testing PAMPA Web"
puts "=========================================================================="
$browsers = [
"Watir::Browser.new :chrome, options: {args: ['--no-sandbox']}",
"Watir::Browser.new :firefox, options: {args: ['--no-sandbox']}",
"Watir::Browser.new :edge, options: {args: ['--no-sandbox']}"
]
$form_url = "http://localhost/pampa/form.php"
class PampaWebFormTest < Test::Unit::TestCase
def test_01_launch_page
puts "* pampa/form.php - Launch page (1/5)"
$browsers.each do |br_string|
puts br_string
br = eval(br_string)
br.goto $form_url
# check text
e = br.element(id: 'title')
assert(e.present? && (e.text == "Pampa"))
e = br.element(class: 'onglet_left')
assert(e.present? && e.text == "Pampa")
assert(br.text.include? "Mass spectra")
assert(br.table(class: 'pampa_choice').present?)
assert(br.button(id: 'run').present?)
br.close
end
end
def test_02_buttons_links
puts "* pampa/form.php - Buttons and links (2/5)"
$browsers.each do |br_string|
puts br_string
br = eval(br_string)
br.goto $form_url
# check links
br.div(id: 'center').as.each do |link|
if link.href.start_with?("http") # web links
status_code = URI.open(link.href).status[0]
assert(status_code=='200')
elsif link.href.start_with?("mailto:")
email = link.href[7..-1]
assert(EmailAddress.valid? email)
else
puts '- "' + link.href + '" not tested'
end
end
br.close
end
end
def test_03_display
puts "* pampa/form.php - Normal display (3/5)"
$browsers.each do |br_string|
puts br_string
br = eval(br_string)
br.goto $form_url
# check options
e = br.checkbox(name: 'spectra_example_1')
assert(e.exists? && !(e.set?))
e = br.radio(name: 'error_margin_selection', value: 'MALDI_TOF')
assert(e.exists? && e.set?)
e = br.radio(id: 'reference_source_default')
assert(e.exists? && !(e.set?))
e = br.radio(id: 'reference_source_user')
assert(e.exists? && !(e.set?))
e = br.checkbox(name: 'taxonomic_group_selection', value: 'mammals')
assert(e.exists? && e.set?)
e = br.checkbox(name: 'ptm_deamidation', value: 'deamidation')
assert(e.exists? && e.set?)
e = br.radio(name: 'nearoptimal_selection', value: 'optimal')
assert(e.exists? && e.set?)
# check hidden elements
e = br.tr(id: 'spectra_input')
assert(e.present?)
e = br.tr(id: 'spectra_example')
assert(e.exists? && !(e.visible?))
e = br.div(id: 'block_reference_source_default')
assert(e.exists? && !(e.visible?))
e = br.div(id: 'block_reference_source_user')
assert(e.exists? && !(e.visible?))
e = br.div(id: 'block_results')
assert(e.exists? && !(e.visible?))
br.close
end
end
def test_04_interactions
puts "* pampa/form.php - Js interactions (4/5)"
$browsers.each do |br_string|
puts br_string
br = eval(br_string)
br.goto $form_url
# check basic mode
e = br.radio(id: 'reference_source_default')
assert(e.exists?)
e.click
e = br.div(id: 'block_reference_source_default')
assert(e.present?)
e = br.div(id: 'block_reference_source_user')
assert(e.exists? && !(e.visible?))
e = br.div(id: 'block_results')
assert(e.present?)
# check reset button
e = br.button(id: "reset")
assert(e.present?)
e.click
e = br.tr(id: 'spectra_input')
assert(e.present?)
e = br.tr(id: 'spectra_example')
assert(e.exists? && !(e.visible?))
e = br.checkbox(name: 'spectra_example_1')
assert(e.exists? && !(e.set?))
e = br.radio(name: 'error_margin_selection', value: 'MALDI_TOF')
assert(e.present? && e.set?)
e = br.radio(id: 'reference_source_default')
assert(e.present? && !(e.set?))
e = br.radio(id: 'reference_source_user')
assert(e.present? && !(e.set?))
e = br.checkbox(name: 'taxonomic_group_selection', value: 'mammals')
assert(e.exists? && e.set?)
e = br.checkbox(name: 'ptm_deamidation', value: 'deamidation')
assert(e.exists? && e.set?)
e = br.radio(name: 'nearoptimal_selection', value: 'optimal')
assert(e.exists? && e.set?)
e = br.div(id: 'block_reference_source_default')
assert(e.exists? && !(e.visible?))
e = br.div(id: 'block_reference_source_user')
assert(e.exists? && !(e.visible?))
e = br.div(id: 'block_results')
assert(e.exists? && !(e.visible?))
# check advanced mode
e = br.radio(id: 'reference_source_user')
assert(e.exists?)
e.click
e = br.div(id: 'block_reference_source_default')
assert(e.exists? && !(e.visible?))
e = br.div(id: 'block_reference_source_user')
assert(e.present?)
e = br.div(id: 'block_results')
assert(e.present?)
br.close
end
end
def test_05_example
puts "* pampa/form.php - Example (5/5)"
$browsers.each do |br_string|
puts br_string
br = eval(br_string)
br.goto $form_url
# example button effect (form)
e = br.button(id: 'example_1')
assert(e.present?)
e.click
# visibility
e = br.checkbox(name: 'spectra_example_1')
assert(e.exists? && !e.visible? && e.set?)
e = br.button(id: 'back_to_normal')
assert(e.present?)
e = br.tr(id: 'spectra_input')
assert(e.exists? && !(e.visible?))
e = br.radio(name: 'error_margin_selection', value: 'MALDI_TOF')
assert(e.present? && e.set?)
e = br.radio(id: 'reference_source_default')
assert(e.present? && e.set?)
e = br.div(id: 'block_reference_source_default')
assert(e.present?)
e = br.div(id: 'block_reference_source_user')
assert(e.exists? && !(e.visible?))
e = br.div(id: 'block_results')
assert(e.present?)
# parameters
e = br.text_field(name: 'job_name')
assert(e.present? && e.value == "example_1")
e = br.checkbox(name: 'taxonomic_group_selection', value: 'mammals')
assert(e.exists? && e.set?)
es = br.inputs(css: '[list="taxonomic_node_list"]')
assert(es.size == 1)
e = es[0]
assert(e.present? && e.value == "")
e = br.checkbox(name: 'ptm_deamidation', value: 'deamidation')
assert(e.exists? && e.set?)
e = br.radio(name: 'nearoptimal_selection', value: 'optimal')
assert(e.exists? && e.set?)
# custom upload after example
br.button(id: 'back_to_normal').click
e = br.tr(id: 'spectra_input')
assert(e.present?)
e = br.tr(id: 'spectra_example')
assert(e.exists? && !(e.visible?))
e = br.checkbox(name: 'spectra_example_1')
assert(e.exists? && !(e.set?))
e = br.text_field(name: 'job_name')
assert(e.present? && e.value != "example_1")
br.close
end
end
end
# -- Packages --
require 'rubygems'
# require 'webdrivers'
require 'watir'
require 'test/unit'
require 'open-uri'
require 'email_address'
puts "=========================================================================="
puts " Testing PAMPA Web"
puts "=========================================================================="
$browsers = [
"Watir::Browser.new :chrome, options: {args: ['--no-sandbox']}",
"Watir::Browser.new :firefox, options: {args: ['--no-sandbox']}",
"Watir::Browser.new :edge, options: {args: ['--no-sandbox']}"
]
$help_url = "http://localhost/pampa/help.php"
class PampaWebHelpTest < Test::Unit::TestCase
def test_01_launch_page
puts "* pampa/help.php - Launch page (1/2)"
$browsers.each do |br_string|
puts br_string
br = eval(br_string)
br.goto $help_url
# check text
e = br.element(id: 'title')
assert(e.present? && (e.text == "Pampa"))
e = br.element(class: 'onglet_right')
assert(e.present? && e.text == "Help")
assert(br.text.include? "Peptide markers are organized within peptide tables")
assert(br.element(id: 'PTM_description').present?)
br.close
end
end
def test_02_buttons_links
puts "* pampa/help.php - Buttons and links (2/2)"
$browsers.each do |br_string|
puts br_string
br = eval(br_string)
br.goto $help_url
# check links
br.div(id: 'center').as.each do |link|
if link.href.start_with?("http") # web links
status_code = URI.open(link.href).status[0]
assert(status_code=='200')
elsif link.href.start_with?("mailto:")
email = link.href[7..-1]
assert(EmailAddress.valid? email)
else
puts '- "' + link.href + '" not tested'
end
end
br.close
end
end
end
# -- Packages --
require 'rubygems'
# require 'webdrivers'
require 'watir'
require 'test/unit'
require 'open-uri'
require 'email_address'
puts "=========================================================================="
puts " Testing PAMPA Web"
puts "=========================================================================="
$browsers = [
"Watir::Browser.new :chrome, options: {args: ['--no-sandbox']}",
"Watir::Browser.new :firefox, options: {args: ['--no-sandbox']}",
"Watir::Browser.new :edge, options: {args: ['--no-sandbox']}"
]
$home_url = "http://localhost/pampa/"
class PampaWebHomeTest < Test::Unit::TestCase
def test_01_launch_page
puts "* pampa - Launch page (1/2)"
$browsers.each do |br_string|
puts br_string
br = eval(br_string)
br.goto $home_url
# check text
e = br.element(id: 'title')
assert(e.present? && (e.text == "Pampa"))
e = br.element(class: 'onglet_left')
assert(e.present? && e.text == "Pampa")
assert(br.text.include? "PAMPA is available in two versions.")
br.close
end
end
def test_02_buttons_links
puts "* pampa - Buttons and links (2/2)"
$browsers.each do |br_string|
puts br_string
br = eval(br_string)
br.goto $home_url
# check links
br.div(id: 'center').as.each do |link|
assert(link.href != "")
if link.href.start_with?("http") # web links
status_code = URI.open(link.href).status[0]
assert(status_code=='200')
elsif link.href.start_with?("mailto:") # mails
email = link.href[7..-1]
assert(EmailAddress.valid? email)
else
puts '- "' + link.href + '" not tested'
end
end
br.close
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment