20850: Fix test selector
[arvados.git] / apps / workbench / test / controllers / work_units_controller_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class WorkUnitsControllerTest < ActionController::TestCase
8   # These tests don't do state-changing API calls.
9   # Save some time by skipping the database reset.
10   reset_api_fixtures :after_each_test, false
11   reset_api_fixtures :after_suite, true
12
13   [
14     ['foo', 10, 25,
15       ['/pipeline_instances/zzzzz-d1hrv-1xfj6xkicf2muk2',
16        '/pipeline_instances/zzzzz-d1hrv-1yfj61234abcdk4',
17        '/jobs/zzzzz-8i9sb-grx15v5mjnsyxk7'],
18       ['/pipeline_instances/zzzzz-d1hrv-1yfj61234abcdk3',
19        '/jobs/zzzzz-8i9sb-n7omg50bvt0m1nf',
20        '/container_requests/zzzzz-xvhdp-cr4completedcr2']],
21     ['pipeline_with_tagged_collection_input', 1, 1,
22       ['/pipeline_instances/zzzzz-d1hrv-1yfj61234abcdk3'],
23       ['/pipeline_instances/zzzzz-d1hrv-1yfj61234abcdk4',
24        '/jobs/zzzzz-8i9sb-pshmckwoma9plh7',
25        '/jobs/zzzzz-8i9sb-n7omg50bvt0m1nf',
26        '/container_requests/zzzzz-xvhdp-cr4completedcr2']],
27     ['no_such_match', 0, 0,
28       [],
29       ['/pipeline_instances/zzzzz-d1hrv-1yfj61234abcdk4',
30        '/jobs/zzzzz-8i9sb-pshmckwoma9plh7',
31        '/jobs/zzzzz-8i9sb-n7omg50bvt0m1nf',
32        '/container_requests/zzzzz-xvhdp-cr4completedcr2']],
33   ].each do |search_filter, expected_min, expected_max, expected, not_expected|
34     test "all_processes page for search filter '#{search_filter}'" do
35       work_units_index(filters: [['any','ilike', "%#{search_filter}%"]], show_children: true)
36       assert_response :success
37
38       # Verify that expected number of processes are found
39       found_count = json_response['content'].scan('<tr').count
40       if expected_min == expected_max
41         assert_equal(true, found_count == expected_min,
42           "Not found expected number of items. Expected #{expected_min} and found #{found_count}")
43       else
44         assert_equal(true, found_count>=expected_min,
45           "Found too few items. Expected at least #{expected_min} and found #{found_count}")
46         assert_equal(true, found_count<=expected_max,
47           "Found too many items. Expected at most #{expected_max} and found #{found_count}")
48       end
49
50       # verify that all expected uuid links are found
51       expected.each do |link|
52         assert_match /href="#{link}"/, json_response['content']
53       end
54
55       # verify that none of the not_expected uuid links are found
56       not_expected.each do |link|
57         assert_no_match /href="#{link}"/, json_response['content']
58       end
59     end
60   end
61
62   def work_units_index params
63     params = {
64       partial: :all_processes_rows,
65       format: :json,
66     }.merge(params)
67     encoded_params = Hash[params.map { |k,v|
68                             [k, (v.is_a?(Array) || v.is_a?(Hash)) ? v.to_json : v]
69                           }]
70     get :index, params: encoded_params, session: session_for(:active)
71   end
72 end