dom_glancy 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/Gemfile +4 -0
  4. data/README.md +5 -0
  5. data/app/controllers/dom_glancy_controller.rb +9 -12
  6. data/app/views/dom_glancy/about.html.erb +2 -2
  7. data/app/views/dom_glancy/path_config.html.erb +10 -8
  8. data/app/views/dom_glancy/show.html.erb +3 -18
  9. data/app/views/layouts/dom_glancy.html.erb +10 -19
  10. data/app/views/shared/_dom_glancy_nav.html.erb +1 -1
  11. data/app/views/shared/_dom_set.html.erb +17 -2
  12. data/lib/assets/javascripts/dom_glancy/dom_glancy.js +37 -0
  13. data/{app/assets/stylesheets → lib/assets/stylesheets/dom_glancy}/1236_grid.css +0 -0
  14. data/{app/assets/stylesheets → lib/assets/stylesheets/dom_glancy}/720_grid.css +0 -0
  15. data/{app/assets/stylesheets → lib/assets/stylesheets/dom_glancy}/986_grid.css +0 -0
  16. data/{app/assets/stylesheets → lib/assets/stylesheets/dom_glancy}/dom_glancy.css +35 -4
  17. data/{app/assets/stylesheets → lib/assets/stylesheets/dom_glancy}/normalize.css +0 -0
  18. data/lib/dom_glancy.rb +6 -2
  19. data/lib/dom_glancy/analysis_reporter.rb +39 -0
  20. data/lib/dom_glancy/analyzer.rb +139 -0
  21. data/lib/dom_glancy/change_anlyzer.rb +22 -0
  22. data/lib/dom_glancy/dom_glancy.rb +35 -83
  23. data/lib/dom_glancy/element.rb +63 -12
  24. data/lib/dom_glancy/file_name_builder.rb +21 -0
  25. data/lib/dom_glancy/map_file.rb +14 -0
  26. data/lib/dom_glancy/page_mapper.rb +81 -0
  27. data/lib/dom_glancy/svg.rb +41 -2
  28. data/lib/dom_glancy/version.rb +1 -1
  29. data/test/page_objects/dom_glancy/show_page.rb +6 -0
  30. data/test/selenium/mapping_test.rb +28 -5
  31. data/test/selenium/viewer_test.rb +2 -2
  32. data/test/selenium_test_helper.rb +26 -43
  33. data/test/test_app/app/assets/stylesheets/local_app.css +9 -1
  34. data/test/test_app/app/views/local/index.html.erb +11 -1
  35. data/test/test_helper.rb +7 -5
  36. data/test/test_helpers/artifacts_helpers.rb +54 -0
  37. data/test/test_helpers/location_helpers.rb +5 -3
  38. data/test/test_objects/options_file_1.yaml +2145 -0
  39. data/test/test_objects/options_file_2.yaml +2177 -0
  40. data/test/test_objects/test_objects.rb +57 -6
  41. data/test/unit/analysis_reporter_test.rb +28 -0
  42. data/test/unit/analyzer_test.rb +146 -0
  43. data/test/unit/change_analyzer_test.rb +72 -0
  44. data/test/unit/dom_glancy_test.rb +16 -11
  45. data/test/unit/element_test.rb +56 -0
  46. data/test/unit/file_name_builder_test.rb +28 -0
  47. data/test/unit/map_file_test.rb +47 -0
  48. data/test/unit/page_mapper_test.rb +27 -0
  49. data/test/unit/svg_test.rb +17 -0
  50. metadata +35 -13
  51. data/app/assets/javascripts/application.js +0 -7
  52. data/lib/dom_glancy/analysis.rb +0 -146
  53. data/lib/dom_glancy/locations.rb +0 -16
  54. data/test/unit/analysis_test.rb +0 -110
@@ -595,7 +595,7 @@ module TestObjects
595
595
  YAML::load(data)
596
596
  end
597
597
 
598
- def travis_local_generated_master_2
598
+ def travis_local_generated_master_2
599
599
  data = <<-DATA
600
600
  ---
601
601
  - height: 45
@@ -1160,11 +1160,10 @@ module TestObjects
1160
1160
  visible: false
1161
1161
  DATA
1162
1162
 
1163
- YAML::load(data)
1164
- end
1165
-
1166
-
1167
- def travis_generated_current
1163
+ YAML::load(data)
1164
+ end
1165
+
1166
+ def travis_generated_current
1168
1167
  data = <<-DATA
1169
1168
  ---
1170
1169
  - height: 45
@@ -2026,4 +2025,56 @@ module TestObjects
2026
2025
  DATA
2027
2026
  YAML::load(data)
2028
2027
  end
2028
+
2029
+ def mapping_json
2030
+ "--- - id: '12' height: 238 visible: true tag: DIV width: 720 class: grid left: 43 top: 14 - id: '14' height: 0 visible: true tag: SPAN width: 0 class: mm--title_text_sub left: 71 top: 86 "
2031
+ end
2032
+
2033
+ def set_1_h1_changes
2034
+ data = <<-DATA
2035
+ ---
2036
+ - height: 38
2037
+ width: 944
2038
+ id: ''
2039
+ tag: H1
2040
+ class: ''
2041
+ top: 21
2042
+ left: 8
2043
+ visible: true
2044
+ - height: 38
2045
+ width: 944
2046
+ id: ''
2047
+ tag: H1
2048
+ class: ''
2049
+ top: 291
2050
+ left: 8
2051
+ visible: true
2052
+
2053
+ DATA
2054
+ YAML::load(data)
2055
+ end
2056
+
2057
+ def set_2_h1_changes
2058
+ data = <<-DATA
2059
+ ---
2060
+ - height: 38
2061
+ width: 1044
2062
+ id: ''
2063
+ tag: H1
2064
+ class: ''
2065
+ top: 21
2066
+ left: 8
2067
+ visible: true
2068
+ - height: 38
2069
+ width: 1044
2070
+ id: ''
2071
+ tag: H1
2072
+ class: ''
2073
+ top: 291
2074
+ left: 8
2075
+ visible: true
2076
+
2077
+ DATA
2078
+ YAML::load(data)
2079
+ end
2029
2080
  end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class AnalysisReporterTest < DomGlancyTestCase
4
+
5
+ def test_analysis_reporter
6
+ prep_locations_for_test
7
+
8
+ test_root = 'kolo_torre'
9
+ master_data = array_of_elements
10
+ current_data = array_of_elements
11
+ current_data << single_element_hash
12
+ analyzer = DomGlancy::Analyzer.new(master_data, current_data, test_root)
13
+ analyzer.send(:clear_results)
14
+
15
+ reporter = DomGlancy::AnalysisReporter.new(test_root, analyzer.set_current_not_master, analyzer.set_master_not_current, analyzer.set_changed_master, analyzer.changed_element_pairs)
16
+
17
+ reporter.create_diff_file
18
+
19
+ files = Dir[File.join(DomGlancy.configuration.diff_file_location, '*')]
20
+
21
+ assert_equal 5, files.length
22
+ assert_includes files, File.join(DomGlancy.configuration.diff_file_location, "#{test_root}__changed_master__diff.yaml")
23
+ assert_includes files, File.join(DomGlancy.configuration.diff_file_location, "#{test_root}__current_not_master__diff.yaml")
24
+ assert_includes files, File.join(DomGlancy.configuration.diff_file_location, "#{test_root}__master_not_current__diff.yaml")
25
+ assert_includes files, File.join(DomGlancy.configuration.diff_file_location, "#{test_root}__changed_pairs__diff.yaml")
26
+ assert_includes files, File.join(DomGlancy.configuration.diff_file_location, "#{test_root}_diff.html")
27
+ end
28
+ end
@@ -0,0 +1,146 @@
1
+ require 'test_helper'
2
+
3
+ class AnalyzerTest < DomGlancyTestCase
4
+
5
+ def test_same_elements
6
+ master_data = array_of_elements
7
+ current_data = array_of_elements
8
+
9
+ analysis = DomGlancy::Analyzer.new(master_data, current_data).analyze
10
+
11
+ assert_equal 0, analysis[:not_in_master].count, 'results of data analysis: not_in_master'
12
+ assert_equal 0, analysis[:not_in_current].count, 'results of data analysis: not_in_current'
13
+ assert analysis[:same], 'results of data analysis.same'
14
+ end
15
+
16
+ def test_one_id_different
17
+ master_data = array_of_elements_small
18
+ current_data = array_of_elements_small
19
+ current_data.first['id'] = 'some-new-id'
20
+
21
+ analysis = DomGlancy::Analyzer.new(master_data, current_data).analyze
22
+
23
+ assert_equal 1, analysis[:not_in_master].count, 'results of data analysis: not_in_master'
24
+ assert_equal 1, analysis[:not_in_current].count, 'results of data analysis: not_in_current'
25
+ refute analysis[:same], 'results of data analysis.same'
26
+ end
27
+
28
+ def test_one_new_element
29
+ master_data = array_of_elements
30
+ current_data = array_of_elements
31
+ current_data << single_element_hash
32
+
33
+ analysis = DomGlancy::Analyzer.new(master_data, current_data).analyze
34
+
35
+ assert_equal 1, analysis[:not_in_master].count, 'results of data analysis: not_in_master'
36
+ assert_equal 0, analysis[:not_in_current].count, 'results of data analysis: not_in_current'
37
+ refute analysis[:same], 'results of data analysis.same'
38
+ end
39
+
40
+ def test_two_changed
41
+ master_data = array_of_elements
42
+ current_data = array_of_elements
43
+ current_data[0]['height'] = current_data[0]['height'] + 16
44
+ current_data[1]['width'] = current_data[1]['width'] + 25
45
+
46
+ analysis = DomGlancy::Analyzer.new(master_data, current_data).analyze
47
+
48
+ assert_equal 0, analysis[:not_in_master].count, 'results of data analysis: not_in_master'
49
+ assert_equal 0, analysis[:not_in_current].count, 'results of data analysis: not_in_current'
50
+ assert_equal 2, analysis[:changed_element_pairs].count, 'changed element pairs'
51
+ assert_equal 2, analysis[:changed_master].count, 'changed master elements'
52
+ refute analysis[:same], 'results of data analysis.same'
53
+ end
54
+
55
+ def test_one_changed_less_than_similarity_factor
56
+ master_data = array_of_elements
57
+ current_data = array_of_elements
58
+
59
+ current_data[1]['height'] = current_data[1]['height'] + 3
60
+
61
+ analysis = DomGlancy::Analyzer.new(master_data, current_data).analyze
62
+
63
+ assert_equal 0, analysis[:not_in_master].count, 'results of data analysis: not_in_master'
64
+ assert_equal 0, analysis[:not_in_current].count, 'results of data analysis: not_in_current'
65
+ assert_equal 0, analysis[:changed_element_pairs].count, 'changed element pairs'
66
+ assert analysis[:same], 'results of data analysis.same'
67
+ end
68
+
69
+ def test_one_changed_one_missing_one_added
70
+ master_data = array_of_elements
71
+ current_data = array_of_elements
72
+
73
+ current_data[0]['height'] = current_data[0]['height'] + 23 ## the one changed (by more than similarity factor)
74
+ current_data[1]['height'] = current_data[1]['height'] + 3 ## the one changed (by less than similarity factor and therefor not counted)
75
+ current_data.delete_at(5) ## the one missing
76
+ current_data << single_element_hash ## the one added
77
+
78
+ analysis = DomGlancy::Analyzer.new(master_data, current_data).analyze
79
+
80
+ assert_equal 1, analysis[:not_in_master].count, 'results of data analysis: not_in_master'
81
+ assert_equal 1, analysis[:not_in_current].count, 'results of data analysis: not_in_current'
82
+ assert_equal 1, analysis[:changed_element_pairs].count, 'changed element pairs'
83
+ refute analysis[:same], 'results of data analysis.same'
84
+ end
85
+
86
+ def test_huge_list_of_similarly_named_elements
87
+ master_data = travis_local_generated_master
88
+ current_data = travis_generated_current
89
+
90
+ analysis = DomGlancy::Analyzer.new(master_data, current_data).analyze
91
+ assert_equal 0, analysis[:not_in_master].count, 'results of data analysis: not_in_master'
92
+ assert_equal 0, analysis[:not_in_current].count, 'results of data analysis: not_in_current'
93
+ assert_equal 0, analysis[:changed_element_pairs].count, 'changed element pairs'
94
+ assert analysis[:same], 'results of data analysis.same'
95
+ end
96
+
97
+ def test_huge_another_list_of_similarly_named_elements
98
+ master_data = travis_local_generated_master_2
99
+ current_data = travis_generated_current_2
100
+
101
+ analysis = DomGlancy::Analyzer.new(master_data, current_data).analyze
102
+
103
+ ## real difference that was found on travis with the INPUT tags being different styles/sizes if not css-styled
104
+ assert_equal 0, analysis[:not_in_master].count, 'results of data analysis: not_in_master'
105
+ assert_equal 0, analysis[:not_in_current].count, 'results of data analysis: not_in_current'
106
+ assert_equal 1, analysis[:changed_element_pairs].count, 'changed element pairs'
107
+ refute analysis[:same], 'results of data analysis.same'
108
+ end
109
+
110
+ def test_large_change_set
111
+ test_root = 'suso'
112
+ file_1 = File.expand_path('../../test_objects/options_file_1.yaml', __FILE__)
113
+ file_2 = File.expand_path('../../test_objects/options_file_2.yaml', __FILE__)
114
+
115
+ result, msg, current_data = DomGlancy::MapFile.new.read(file_1)
116
+ result, msg, master_data = DomGlancy::MapFile.new.read(file_2)
117
+
118
+ analyzer = ::DomGlancy::Analyzer.new(master_data, current_data, test_root)
119
+
120
+ analysis_data = analyzer.analyze
121
+
122
+ # ap analysis_data
123
+
124
+ refute analysis_data[:same]
125
+ assert_equal 0, analysis_data[:not_in_master].count, 'not master count'
126
+ assert_equal 39, analysis_data[:not_in_current].count, 'not current count'
127
+ assert_equal 47, analysis_data[:changed_element_pairs].count, 'changed element pairs count'
128
+ assert_equal 47, analysis_data[:changed_master].count, 'changed master count'
129
+ end
130
+
131
+ def test_from_changed_h1_sets
132
+ test_root = 'jordan_henderson'
133
+ master_data = set_1_h1_changes
134
+ current_data = set_2_h1_changes
135
+
136
+ analyzer = ::DomGlancy::Analyzer.new(master_data, current_data, test_root)
137
+ analysis_data = analyzer.analyze
138
+
139
+ refute analysis_data[:same]
140
+ assert_equal 0, analysis_data[:not_in_master].count, 'not master count'
141
+ assert_equal 0, analysis_data[:not_in_current].count, 'not current count'
142
+ assert_equal 2, analysis_data[:changed_element_pairs].count, 'changed element pairs count'
143
+ assert_equal 2, analysis_data[:changed_master].count, 'changed master count'
144
+ end
145
+
146
+ end
@@ -0,0 +1,72 @@
1
+ require 'test_helper'
2
+
3
+ class ChangeAnalyzerTest < DomGlancyTestCase
4
+
5
+ def test_change_calculator__initialization
6
+ change_analyzer = DomGlancy::ChangeAnalyzer.new
7
+ assert_equal 0, change_analyzer.change_factors[0]
8
+ assert_equal 1, change_analyzer.change_factors[1]
9
+ assert_equal 1.2, change_analyzer.change_factors[2]
10
+ assert_equal 2, change_analyzer.change_factors[3]
11
+ assert_equal 5, change_analyzer.change_factors[4]
12
+
13
+ change_analyzer = DomGlancy::ChangeAnalyzer.new([50, 60])
14
+ assert_equal 50, change_analyzer.change_factors[0]
15
+ assert_equal 60, change_analyzer.change_factors[1]
16
+ assert_equal 1.2, change_analyzer.change_factors[2]
17
+ assert_equal 2, change_analyzer.change_factors[3]
18
+ assert_equal 5, change_analyzer.change_factors[4]
19
+
20
+ change_analyzer = DomGlancy::ChangeAnalyzer.new([55, 66, 7, 8, 9, 10, 12345, -10])
21
+ assert_equal 55, change_analyzer.change_factors[0]
22
+ assert_equal 66, change_analyzer.change_factors[1]
23
+ assert_equal 7, change_analyzer.change_factors[2]
24
+ assert_equal 8, change_analyzer.change_factors[3]
25
+ assert_equal 9, change_analyzer.change_factors[4]
26
+ assert_nil change_analyzer.change_factors[5]
27
+
28
+ change_analyzer.change_factors[3] = 23
29
+ assert_equal 55, change_analyzer.change_factors[0]
30
+ assert_equal 66, change_analyzer.change_factors[1]
31
+ assert_equal 7, change_analyzer.change_factors[2]
32
+ assert_equal 23, change_analyzer.change_factors[3]
33
+ assert_equal 9, change_analyzer.change_factors[4]
34
+ assert_nil change_analyzer.change_factors[5]
35
+ end
36
+
37
+ def test_change_calculator__calc
38
+ change_analyzer = DomGlancy::ChangeAnalyzer.new
39
+
40
+ element1 = DomGlancy::DOMElement.new(single_element_hash)
41
+
42
+ element2 = element1.dup
43
+ element2.top += 100
44
+
45
+ element3 = element1.dup
46
+ element3.width += 25
47
+ element3.height += 25
48
+
49
+ element4 = element1.dup
50
+ element4.width += 10
51
+ element4.height += 10
52
+ element4.top += 10
53
+
54
+ element5 = element1.dup
55
+ element5.width += 3
56
+ element5.height += 3
57
+ element5.top += 3
58
+ element5.left += 3
59
+
60
+ change_value = change_analyzer.compare(element1, element2)
61
+ assert_equal 100, change_value
62
+
63
+ change_value = change_analyzer.compare(element1, element3)
64
+ assert_equal 85.0, change_value
65
+
66
+ change_value = change_analyzer.compare(element1, element4)
67
+ assert_equal 70.0, change_value
68
+
69
+ change_value = change_analyzer.compare(element1, element5)
70
+ assert_equal 63, change_value
71
+ end
72
+ end
@@ -7,6 +7,7 @@ class DomGlancyTest < DomGlancyTestCase
7
7
  @test_root = 'elbow'
8
8
  prep_locations_for_test
9
9
  make_master_test_file(@test_root, array_of_elements_small)
10
+ @dom_glancy = DomGlancy::DomGlancy.new
10
11
  end
11
12
 
12
13
  def teardown
@@ -15,9 +16,10 @@ class DomGlancyTest < DomGlancyTestCase
15
16
 
16
17
  def test_dom_glancy__missing_master
17
18
  this_test_root = 'not_elbow'
18
- blessing_copy_string = "cp #{DomGlancy::DomGlancy.current_filename(this_test_root)} #{DomGlancy::DomGlancy.master_filename(this_test_root)}"
19
+ fnb = DomGlancy::FileNameBuilder.new(this_test_root)
20
+ blessing_copy_string = "cp #{fnb.current} #{fnb.master}"
19
21
 
20
- @dom_glancy.stubs(:perform_mapping_operation).returns(array_of_elements_small)
22
+ ::DomGlancy::PageMapper.any_instance.stubs(:map_page).returns(array_of_elements_small)
21
23
  mapping_results = @dom_glancy.page_map_same?(this_test_root)
22
24
 
23
25
  refute mapping_results[0], 'test should fail because no master'
@@ -25,24 +27,27 @@ class DomGlancyTest < DomGlancyTestCase
25
27
  assert_match blessing_copy_string, mapping_results[1], 'blessing copy string should be in the error message'
26
28
 
27
29
  `#{blessing_copy_string}`
28
- @dom_glancy.stubs(:perform_mapping_operation).returns(array_of_elements_small)
30
+ ::DomGlancy::PageMapper.any_instance.stubs(:map_page).returns(array_of_elements_small)
29
31
 
30
32
  mapping_results = @dom_glancy.page_map_same?(this_test_root)
31
33
  assert mapping_results[0], 'test should now pass with copied master'
32
34
  end
33
35
 
34
36
  def test_dom_glancy__pass
35
- @dom_glancy.stubs(:perform_mapping_operation).returns(array_of_elements_small)
37
+ ::DomGlancy::PageMapper.any_instance.stubs(:map_page).returns(array_of_elements_small)
38
+
36
39
  mapping_results = @dom_glancy.page_map_same?(@test_root)
37
40
 
38
41
  assert mapping_results[0], mapping_results[1]
39
42
  end
40
43
 
41
44
  def test_dom_glancy__fail_one_new_element
42
- blessing_copy_string = "cp #{DomGlancy::DomGlancy.current_filename(@test_root)} #{DomGlancy::DomGlancy.master_filename(@test_root)}"
45
+ fnb = DomGlancy::FileNameBuilder.new(@test_root)
46
+
47
+ blessing_copy_string = "cp #{fnb.current} #{fnb.master}"
43
48
 
44
49
  current_data = array_of_elements_small << single_element_hash
45
- @dom_glancy.stubs(:perform_mapping_operation).returns(current_data)
50
+ ::DomGlancy::PageMapper.any_instance.stubs(:map_page).returns(current_data)
46
51
  mapping_results = @dom_glancy.page_map_same?(@test_root)
47
52
 
48
53
  refute mapping_results[0], 'page same results should be false'
@@ -51,14 +56,14 @@ class DomGlancyTest < DomGlancyTestCase
51
56
  assert_match 'Elements not in current: 0', mapping_results[1], 'error message contents'
52
57
  assert_match 'Changed elements: 0', mapping_results[1], 'error message contents'
53
58
 
54
- assert_match "current: #{DomGlancy::DomGlancy.current_filename(@test_root)}", mapping_results[1], 'error message contents'
55
- assert_match "master: #{DomGlancy::DomGlancy.master_filename(@test_root)}", mapping_results[1], 'error message contents'
56
- assert_match "difference: #{DomGlancy::DomGlancy.diff_filename(@test_root)}", mapping_results[1], 'error message contents'
59
+ assert_match "current: #{fnb.current}", mapping_results[1], 'error message contents'
60
+ assert_match "master: #{fnb.master}", mapping_results[1], 'error message contents'
61
+ assert_match "difference: #{fnb.diff}", mapping_results[1], 'error message contents'
57
62
 
58
63
  assert_match blessing_copy_string, mapping_results[1], 'blessing copy string should be in the error message'
59
64
 
60
65
  files_in_diff_location = Dir[File.join(DomGlancy.configuration.diff_file_location, '*')]
61
- assert_equal 4, files_in_diff_location.count, 'the number of files in the diff location after a failure.'
66
+ assert_equal 5, files_in_diff_location.count, 'the number of files in the diff location after a failure.'
62
67
 
63
68
  `#{blessing_copy_string}`
64
69
 
@@ -70,7 +75,7 @@ class DomGlancyTest < DomGlancyTestCase
70
75
  end
71
76
 
72
77
  def make_master_test_file(test_root, data)
73
- filename = DomGlancy::DomGlancy.master_filename(test_root)
78
+ filename = DomGlancy::FileNameBuilder.new(test_root).master
74
79
  yaml_data = data.to_yaml
75
80
  File.open(filename, 'w') { |file| file.write(yaml_data) }
76
81
  end
@@ -21,6 +21,27 @@ class ElementTest < DomGlancyTestCase
21
21
  refute element1.same_element?(element2)
22
22
  end
23
23
 
24
+ def test_sameness_and_similarity__no_id
25
+ element_1 = DomGlancy::DOMElement.new({"id"=>"", "height"=>10, "visible"=>true, "tag"=>"SPAN", "width"=>50, "class"=>"", "left"=>71, "top"=>86, 'similarity' => DomGlancy.configuration.similarity})
26
+ element_2 = DomGlancy::DOMElement.new({"id"=>"", "height"=>12, "visible"=>true, "tag"=>"SPAN", "width"=>52, "class"=>"", "left"=>72, "top"=>82, 'similarity' => DomGlancy.configuration.similarity})
27
+ element_3 = DomGlancy::DOMElement.new({"id"=>"", "height"=>13, "visible"=>true, "tag"=>"SPAN", "width"=>54, "class"=>"", "left"=>72, "top"=>82, 'similarity' => DomGlancy.configuration.similarity})
28
+ element_4 = DomGlancy::DOMElement.new({"id"=>"", "height"=>14, "visible"=>true, "tag"=>"SPAN", "width"=>56, "class"=>"", "left"=>72, "top"=>82, 'similarity' => DomGlancy.configuration.similarity})
29
+ element_5 = DomGlancy::DOMElement.new({"id"=>"", "height"=>115, "visible"=>true, "tag"=>"SPAN", "width"=>58, "class"=>"", "left"=>72, "top"=>82, 'similarity' => DomGlancy.configuration.similarity})
30
+ element_6 = DomGlancy::DOMElement.new({"id"=>"", "height"=>16, "visible"=>true, "tag"=>"SPAN", "width"=>142, "class"=>"", "left"=>72, "top"=>82, 'similarity' => DomGlancy.configuration.similarity})
31
+
32
+ assert element_1.same_element?(element_2)
33
+ assert element_1.same_element?(element_3)
34
+ assert element_1.same_element?(element_4)
35
+ assert element_1.same_element?(element_5)
36
+ assert element_1.same_element?(element_6)
37
+
38
+ assert element_1.close_enough?(element_2)
39
+ assert element_1.close_enough?(element_3)
40
+ assert element_1.close_enough?(element_4)
41
+ refute element_1.close_enough?(element_5)
42
+ refute element_1.close_enough?(element_6)
43
+ end
44
+
24
45
  def test_similarity
25
46
  element1 = DomGlancy::DOMElement.new(single_element_hash.merge({'similarity' => 2}))
26
47
  element2 = DomGlancy::DOMElement.new(single_element_hash.merge({'left' => 72}))
@@ -39,6 +60,41 @@ class ElementTest < DomGlancyTestCase
39
60
  assert element1.close_enough?(element3), 'should not be close enough'
40
61
  end
41
62
 
63
+ def test_similarity_level
64
+ element1 = DomGlancy::DOMElement.new(single_element_hash.merge({'similarity' => 2}))
65
+ element2 = element1.dup
66
+
67
+ element2.left = element2.left.to_i + 1
68
+
69
+ assert_equal 1, element1.similarity_level(element2), 'similarity level of 1'
70
+
71
+ element2.top += 1
72
+ assert_equal 1, element1.similarity_level(element2), 'similarity level of 1, still'
73
+
74
+ element2.width += 1
75
+ assert_equal 2, element1.similarity_level(element2), 'similarity level of 2'
76
+ end
77
+
78
+ def test_change_level
79
+ element1 = DomGlancy::DOMElement.new(single_element_hash.merge({'similarity' => 2}))
80
+ element2 = element1.dup
81
+
82
+ element2.top = element2.top.to_i + 1
83
+ refute element1.all_same?(element2), 'not exactly the same'
84
+ assert element1.close_enough?(element2), 'should be within similarity'
85
+
86
+ element2.top += 2
87
+ refute element1.close_enough?(element2)
88
+
89
+ assert_equal 1, element1.change_level(element2), 'change level with one change'
90
+
91
+ element2.width += 1
92
+ assert_equal 1, element1.change_level(element2), 'change level with one change and one similar'
93
+
94
+ element2.width += 10
95
+ assert_equal 2, element1.change_level(element2), 'change level with one change and one similar'
96
+ end
97
+
42
98
  def test_changed_element__width
43
99
  element1 = DomGlancy::DOMElement.new(array_of_elements.last)
44
100
  element2 = DomGlancy::DOMElement.new(array_of_elements.last.merge("width" => 20))