Javascript mission editor test and css test hacks

James Peret %!s(int64=10) %!d(string=hace) años
padre
commit
b82c4602f3

+ 1 - 0
Gemfile

@@ -85,6 +85,7 @@ group :test do
85 85
   gem 'database_cleaner'
86 86
   gem "factory_girl_rails", "~> 4.0", :require => false
87 87
   gem 'email_spec'
88
+  gem 'selenium-webdriver'
88 89
 end
89 90
 
90 91
 # Use ActiveModel has_secure_password

+ 11 - 0
Gemfile.lock

@@ -48,6 +48,8 @@ GEM
48 48
       mime-types (>= 1.16)
49 49
     carrierwave_backgrounder (0.4.1)
50 50
       carrierwave (~> 0.5)
51
+    childprocess (0.5.5)
52
+      ffi (~> 1.0, >= 1.0.11)
51 53
     coffee-rails (4.0.1)
52 54
       coffee-script (>= 2.2.0)
53 55
       railties (>= 4.0.0, < 5.0)
@@ -91,6 +93,7 @@ GEM
91 93
     factory_girl_rails (4.5.0)
92 94
       factory_girl (~> 4.5.0)
93 95
       railties (>= 3.0.0)
96
+    ffi (1.9.8)
94 97
     figaro (1.0.0)
95 98
       thor (~> 0.14)
96 99
     flatstrap-rails (0.3.0.2)
@@ -250,6 +253,7 @@ GEM
250 253
       rspec-mocks (~> 3.1.0)
251 254
       rspec-support (~> 3.1.0)
252 255
     rspec-support (3.1.2)
256
+    rubyzip (1.1.7)
253 257
     sass (3.2.19)
254 258
     sass-rails (4.0.3)
255 259
       railties (>= 4.0.0, < 5.0)
@@ -259,6 +263,11 @@ GEM
259 263
     sdoc (0.4.1)
260 264
       json (~> 1.7, >= 1.7.7)
261 265
       rdoc (~> 4.0)
266
+    selenium-webdriver (2.45.0)
267
+      childprocess (~> 0.5)
268
+      multi_json (~> 1.0)
269
+      rubyzip (~> 1.0)
270
+      websocket (~> 1.0)
262 271
     simple_form (3.0.2)
263 272
       actionpack (~> 4.0)
264 273
       activemodel (~> 4.0)
@@ -311,6 +320,7 @@ GEM
311 320
       rack (>= 1.0.0)
312 321
     warden (1.2.3)
313 322
       rack (>= 1.0)
323
+    websocket (1.2.1)
314 324
     wirble (0.1.3)
315 325
     xpath (2.0.0)
316 326
       nokogiri (~> 1.3)
@@ -363,6 +373,7 @@ DEPENDENCIES
363 373
   rspec-rails
364 374
   sass-rails
365 375
   sdoc
376
+  selenium-webdriver
366 377
   simple_form
367 378
   sprockets-helpers
368 379
   sprockets-rails

+ 0 - 1
app/assets/javascripts/application.js

@@ -20,5 +20,4 @@
20 20
 //= require summernote
21 21
 //= require turbolinks
22 22
 //= require google_analytics
23
-//= require jquery_nested_form
24 23
 //= require_tree .

+ 5 - 5
app/assets/javascripts/mission_editor.js

@@ -9,11 +9,11 @@ function attachHandler(jQuery) {
9 9
 	  var panel_body = field.find('.panel-body');
10 10
 	  field.find(".panel").removeClass("hidden");
11 11
   
12
-	  var timestamp = new Date().getUTCMilliseconds();
13
-	  var new_id = "collapse_step_" + timestamp;
14
-	  acordion_toggle.attr("href", "#" + new_id);
15
-	  panel_body.attr("id", new_id);
16
-	  //alert(panel_body.id)
12
+	  // var timestamp = new Date().getUTCMilliseconds();
13
+	  // var new_id = "collapse_step_" + timestamp;
14
+	  // acordion_toggle.attr("href", "#" + new_id);
15
+	  // panel_body.attr("id", new_id);
16
+	  // //alert(panel_body.id)
17 17
 	})
18 18
 	
19 19
 	$('.dropdown-toggle').dropdown();

+ 12 - 2
public/javascripts/nested_form.js

@@ -11,7 +11,6 @@
11 11
       var assoc     = $(link).data('association');                // Name of child
12 12
       var blueprint = $('#' + $(link).data('blueprint-id'));
13 13
       var content   = blueprint.data('blueprint');                // Fields template
14
-
15 14
       // Make the context correct by replacing <parents> with the generated ID
16 15
       // of each of the parent objects
17 16
       var context = ($(link).closest('.fields').closestChild('input, textarea, select').eq(0).attr('name') || '').replace(new RegExp('\[[a-z_]+\]$'), '');
@@ -41,8 +40,19 @@
41 40
       var regexp  = new RegExp('new_' + assoc, 'g');
42 41
       var new_id  = this.newId();
43 42
       content     = $.trim(content.replace(regexp, new_id));
44
-
45 43
       var field = this.insertFields(content, assoc, link);
44
+	 
45
+	 // Set up ids
46
+	 $(field).attr("id","new_agent_step_" + new_id);
47
+	 
48
+	  var acordion_toggle = field.find('.accordion-toggle');
49
+ 	  var panel_body = field.find('.panel-body');
50
+	  var new_collapse_id = "collapse_step_" + new_id;
51
+	  acordion_toggle.attr("href", "#" + new_collapse_id);
52
+	  panel_body.attr("id", new_collapse_id);
53
+	  field.find('#btn-add-validation').attr('data-target', '#validations-container-' + new_id)
54
+	  field.find('.validations-container').attr('id', 'validations-container-' + new_id)
55
+	 
46 56
       // bubble up event upto document (through form)
47 57
       field
48 58
         .trigger({ type: 'nested:fieldAdded', field: field })

+ 7 - 0
app/assets/stylesheets/test.css

@@ -0,0 +1,7 @@
1
+* { text-transform: none  !important }
2
+
3
+input[type="file"] {
4
+  width: 1px;
5
+  height: 1px;
6
+  float: left;
7
+}

+ 3 - 0
app/views/layouts/application.html.erb

@@ -35,6 +35,9 @@
35 35
     <%= favicon_link_tag 'favicon.ico', :rel => 'shortcut icon' %>
36 36
 
37 37
     <%= javascript_include_tag "application" %>
38
+    
39
+    <%= stylesheet_link_tag "test" if Rails.env.test? %>
40
+    
38 41
   </head>
39 42
   <body>
40 43
     <div class="wrapper">

+ 3 - 3
app/views/mission_editor/agents/_form_step.html.erb

@@ -2,7 +2,7 @@
2 2
 	<% step_number = 0 %>
3 3
 	<%= f.fields_for :agent_steps, :wrapper => false, show_empty: false do |ff| %>
4 4
 		<% step_number = step_number + 1%>
5
-		<%= content_tag(:div, id: "agent_step_#{ff.object.id}" ,class: "fields panel panel-white step  #{'hidden' if ff.object == nil}") do %>
5
+		<%= content_tag(:div, id: "new_agent_step_#{ff.object.id != nil ? ff.object.id : '1'}" , class: "new_agent_step_ fields panel panel-white step_form  #{'hidden' if ff.object == nil}") do %>
6 6
 			<%= content_tag(:div, class: 'panel-heading handle') do %>
7 7
 				<%= content_tag(:h3, class: 'panel-title') do %>
8 8
 					<%= content_tag(:span, (ff.object.step.to_s != '' ? ff.object.step.to_s : '#'), class: 'task-number') %>
@@ -19,7 +19,7 @@
19 19
 			<%= content_tag(:div, class: 'panel-body collapse', id: ('collapse_step_' + step_number.to_s)) do %>
20 20
 				<%= content_tag(:div, class: "panel-content") do %>
21 21
 					<%= content_tag(:div, class: "panel-text") do %>
22
-						<%= ff.text_field :title, label: (t 'mission_editor.agents.step_title'), class: 'input-block-level' %>
22
+						<%= ff.text_field :title, class: 'input-step-title', label: (t 'mission_editor.agents.step_title'), class: 'input-block-level' %>
23 23
 						<%= ff.text_area :description, label: (t 'mission_editor.agents.description'), class: 'input-block-level', rows: 10 %>
24 24
 					<% end %>
25 25
 				<% end %>
@@ -30,5 +30,5 @@
30 30
 	 <% end %>	 
31 31
 <% end %>
32 32
  <%= content_tag(:div, class: 'panel panel-dashed centered') do %>
33
- 	<%= f.link_to_add "Add a step", :agent_steps, class: 'btn', :data => { :target => "#steps_container" } %>
33
+ 	<%= f.link_to_add "Add a step", :agent_steps, class: 'btn', id: 'btn-add-step', :data => { :target => "#steps_container" } %>
34 34
 <% end %>

+ 3 - 3
app/views/mission_editor/agents/_form_step_validation.html.erb

@@ -10,7 +10,7 @@
10 10
 		       </a>
11 11
 		       <ul class="dropdown-menu dropdown-menu-right" role="menu">
12 12
 		         <li>
13
-		           <%= ff.link_to_add "Text Validation", :step_validations, :data => { :target => "#validations-container-#{ff.object.id.to_s}" } %>
13
+		           <%= ff.link_to_add "Text Validation", :step_validations, id: 'btn-add-validation', :data => { :target => "#validations-container-#{ff.object.id.to_s}" } %>
14 14
 		         </li>
15 15
 		       </ul>
16 16
 		     </li>
@@ -19,9 +19,9 @@
19 19
 <% end %>
20 20
 
21 21
 <% # Text Validation Form %>
22
-<%= content_tag(:div, id: "validations-container-#{ff.object.id.to_s}") do %>
22
+<%= content_tag(:div, class: 'validations-container', id: "validations-container-#{ff.object.id.to_s}") do %>
23 23
 	<%= ff.fields_for :step_validations, show_empty: false do |f_validation| %>
24
-		<%= content_tag(:div, class: "panel-content panel-divider-top steps-validation") do %>
24
+		<%= content_tag(:div, class: "panel-content panel-divider-top step-validation") do %>
25 25
 			<%= content_tag(:div, class: 'panel-heading') do %>
26 26
 				<%= content_tag(:h3, class: 'panel-title text-validation-form') do %>
27 27
 					<%= content_tag(:span, ('<i class="icon-chat"></i>'.html_safe), class: 'task-number') %>

+ 1 - 1
app/views/mission_editor/rewards/_form.html.erb

@@ -19,7 +19,7 @@
19 19
 								<%= content_tag(:span, '', class: 'fileinput-new') %>
20 20
 								<%= content_tag(:span, '', class: 'fileinput-exists') %>
21 21
 
22
-								<%= f.file_field :img, class: 'hidden ', layout: :inline,  label: (t 'mission_editor.mission_details.select_image') %>
22
+								<%= f.file_field :img, layout: :inline,  label: (t 'mission_editor.mission_details.select_image') %>
23 23
 							<% end %>
24 24
 						<% end %>
25 25
 					<% end %>

+ 1 - 1
app/views/missions/_mission_image_uploader.html.erb

@@ -8,7 +8,7 @@
8 8
 			<%= content_tag(:span, '', class: 'fileinput-new') %>
9 9
 			<%= content_tag(:span, '', class: 'fileinput-exists') %>
10 10
 
11
-			<%= f.file_field :cover_img, class: 'hidden ', layout: :inline,  label: (t 'mission_editor.mission_details.select_image') %>
11
+			<%= f.file_field :cover_img,  layout: :inline,  label: (t 'mission_editor.mission_details.select_image') %>
12 12
 		<% end %>
13 13
 	<% end %>
14 14
 <% end %>

+ 2 - 0
config/locales/mission.en.yml

@@ -52,6 +52,8 @@ en:
52 52
       agent_details_help_title: 'Agent Details'
53 53
       agent_details_help: 'Some tips about agents... coming soon'
54 54
       text_validation_description: 'Validation description'
55
+      step_title: 'Step Title'
56
+      add_validation: 'Add Validation'
55 57
     launch:
56 58
       before_launch: 'Before Launch Tips'
57 59
       before_launch_help: '<p>Check out this tips for some things to do before launching your mission.</p><ul><li>Review Your mission in the public view</li><li>Make sure you can deliver the rewards you promisse</li><li>Review agents and make sure everyone has steps with at least one validation</li></ul>'

+ 2 - 0
config/locales/mission.pt-BR.yml

@@ -52,6 +52,8 @@ pt-BR:
52 52
       agent_details_help_title: 'Detalhes do agente'
53 53
       agent_details_help: 'Algumas dicas sobre como criar agentes em breve...'
54 54
       text_validation_description: 'Descreva a validação'
55
+      step_title: 'Titulo do passo'
56
+      add_validation: 'Adicionar Validação'
55 57
     launch:
56 58
       before_launch: 'Before Launch Tips'
57 59
       before_launch_help: '<p>Check out this tips for some things to do before launching your mission.</p><ul><li>Review Your mission in the public view</li><li>Make sure you can deliver the rewards you promisse</li><li>Review agents and make sure everyone has steps with at least one validation</li></ul>'

+ 21 - 2
features/mission_editor.feature

@@ -8,6 +8,7 @@ Feature: Mission Editor
8 8
 	Given the website is configured
9 9
 	And I am logged in as user
10 10
 	
11
+	@javascript
11 12
 	Scenario: Create Mission 
12 13
 		Given I go to the missions page
13 14
 		And I click in the link "New Mission"
@@ -36,8 +37,26 @@ Feature: Mission Editor
36 37
 		And I fill in "Agent Role" with "Treasure Hunter"
37 38
 		And I fill in "Objective" with "Follow the step to find the treasure."
38 39
 		And I fill in "Briefing" with "Follow each step carefully to get to the secret location where the treasure is hidden."
39
-		And I fill in "Step Title" with "Start in front of Copan"
40
-		And I fill in "Description" with "The initial position is in front of the building"
40
+		Then within the ".step_form" number "1" I click in the link "Step"
41
+		Then within the ".step_form" number "1" I fill in "Step Title" with "Go to the train station"
42
+		And  within the ".step_form" number "1" I fill in "Description" with "Start of by going to the train station."
43
+		And  within the ".step_form" number "1" I click in the link "Add Validation"
44
+		And  within the ".step_form" number "1" I click in the link "Text Validation"
45
+		And  within the ".step-validation" number "1" I fill in "Validation description" with "What is the name of the station?"
46
+		And  within the ".step_form" number "1" I click in the link "Add Validation"
47
+		And  within the ".step_form" number "1" I click in the link "Add Validation"
48
+		And  within the ".step_form" number "1" I click in the link "Text Validation"
49
+		And  within the ".step-validation" number "2" I fill in "Validation description" with "What time did you arrive?"
50
+		And I click in the link "Add a step"
51
+		Then within the ".step_form" number "2" I click in the link "Step"
52
+		And within the ".step_form" number "2" I fill in "Step Title" with "Get the first train"
53
+		And within the ".step_form" number "2" I fill in "Description" with "Take the first train towards the countryside"
54
+		And within the ".step_form" number "2" I click in the link "Add Validation"
55
+		And within the ".step_form" number "2" I click in the link "Text Validation"
56
+		And within the ".step-validation" number "3" I fill in "Validation description" with "What is the final destination?"
57
+		And  within the ".step_form" number "1" I click in the link "Add Validation"
58
+		And  within the ".step_form" number "1" I click in the link "Text Validation"
59
+		And within the ".step-validation" number "4" I fill in "Validation description" with "What is your ETA?"
41 60
 		And I click in the button "Save Agent"
42 61
 		Then within "h1" I should see "Agents"
43 62
 		And I should see "Treasure Hunter"

+ 13 - 0
features/step_definitions/form_steps.rb

@@ -4,4 +4,17 @@ end
4 4
 
5 5
 Then(/^I uncheck the checkbox called "(.*?)"$/) do |arg1|
6 6
   uncheck(arg1)
7
+end
8
+
9
+Then(/^within "(.*?)" I fill in "(.*?)" with "(.*?)"$/) do |arg1, arg2, arg3|
10
+  within(arg1) do
11
+     fill_in arg2, :with => arg3
12
+  end
13
+end
14
+
15
+Then(/^within the "(.*?)" number "(\d+)" I fill in "(.*?)" with "(.*?)"$/) do |arg1, arg2, arg3, arg4|
16
+  items = page.all(arg1)
17
+  within(items[arg2.to_i - 1]) do
18
+     fill_in arg3, :with => arg4
19
+  end
7 20
 end

+ 1 - 1
features/step_definitions/helper_steps.rb

@@ -45,7 +45,7 @@ end
45 45
 
46 46
 Then(/^I upload the file "(.*?)" to the field "(.*?)"$/) do |arg1, arg2|
47 47
   @test_file_path = File.expand_path(('../../spec/fixtures/' + arg1), File.dirname(__FILE__))
48
-  attach_file arg2, @test_file_path 
48
+  attach_file arg2, @test_file_path, visible: false
49 49
 end
50 50
 
51 51
 # Check for image

+ 7 - 1
features/step_definitions/link_steps.rb

@@ -6,7 +6,6 @@ When(/^I click in the link with class "(.*?)"$/) do |arg1|
6 6
   first(arg1).click
7 7
 end
8 8
 
9
-
10 9
 When(/^I click in the link "(.*?)"$/) do |arg1|
11 10
   click_link arg1
12 11
 end
@@ -19,4 +18,11 @@ Then(/^within "(.*?)" I click in the link "(.*?)"$/) do |arg1, arg2|
19 18
   within(arg1) do
20 19
      click_link(arg2)
21 20
   end
21
+end
22
+
23
+Then(/^within the "(.*?)" number "(\d+)" I click in the link "(.*?)"$/) do |arg1, arg2, arg3|
24
+  items = page.all(arg1)
25
+  within(items[arg2.to_i - 1]) do
26
+     click_link(arg3)
27
+  end
22 28
 end