Skip to content

Commit 7b45ff5

Browse files
committed
Merge pull request code-dot-org#861 from code-dot-org/test
DTP
2 parents 4868e44 + 231b6c0 commit 7b45ff5

File tree

8 files changed

+82
-54
lines changed

8 files changed

+82
-54
lines changed

blockly/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,25 @@ grunt test
109109
To run an individual test, use the `--grep` option to target a file or Mocha `describe` identifier:
110110

111111
```
112-
grunt test --grep myTestName # e.g., 2_11, or requiredBlockUtils
112+
grunt mochaTest --grep myTestName # e.g., 2_11, or requiredBlockUtils
113113
```
114114

115115
To debug tests using the node-inspector Chrome-like debugger:
116116

117117
```
118118
npm install -g node-inspector
119119
node-inspector &
120-
# open debugger URL
121-
node --debug-brk $(which grunt) --grep='testname'
120+
# open debugger URL, i.e. http://127.0.0.1:8080/debug?port=5858
121+
node --debug-brk $(which grunt) mochaTest --grep='testname'
122122
# This will breakpoint your inspector at the beginning of that test
123123
```
124+
Not there are two classes of mochaTests we have. The first class run in the same process as grunt, and the above commands will work a expected.
125+
For the second class, we launch a new node process, which your debugger will not have broken on. To debug this second class, we added a --dbg
126+
command that will break the debugger on the node process launch on port 5859.
127+
```
128+
grunt mochaTest --grep='testname' --dbg
129+
# open debugger URL on port 5859, i.e. http://127.0.0.1:8080/debug?port=5859
130+
```
124131

125132
- You can add new test files as /test/*Tests.js, see `/test/feedbackTests.js` as an example of adding a mock Blockly instance
126133
- Blockly tests typically target built files in the `build/js` folder

dashboard/app/helpers/levels_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def select_and_remember_callouts(always_show = false)
8383
end
8484
end
8585
else
86-
available_callouts = @script_level.available_callouts if @script_level
86+
available_callouts = @script_level.callouts if @script_level
8787
end
8888
@callouts_to_show = available_callouts
8989
.reject { |c| !always_show && session[:callouts_seen].include?(c.localization_key) }

dashboard/app/models/callout.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Callout < ActiveRecord::Base
22
include Seeded
3-
belongs_to :script_level
3+
belongs_to :script_level, inverse_of: :callouts
44

55
CSV_HEADERS =
66
{

dashboard/app/models/hint.rb

Lines changed: 0 additions & 3 deletions
This file was deleted.

dashboard/app/models/script.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class Script < ActiveRecord::Base
3030
FLAPPY_NAME = 'flappy'
3131
TWENTY_HOUR_NAME = '20-hour'
3232

33+
COURSE1_NAME = 'course1'
34+
COURSE2_NAME = 'course2'
35+
COURSE3_NAME = 'course3'
36+
COURSE4_NAME = 'course4'
37+
3338
def Script.twenty_hour_script
3439
Script.get_from_cache(Script::TWENTY_HOUR_ID)
3540
end
@@ -66,9 +71,11 @@ def self.script_cache_to_redis
6671

6772
def self.script_cache_from_db
6873
{}.tap do |cache|
69-
[FLAPPY_ID, TWENTY_HOUR_ID, PLAYLAB_NAME, HOC_NAME, FROZEN_NAME].each do |id|
74+
[TWENTY_HOUR_ID,
75+
FLAPPY_ID, PLAYLAB_NAME, HOC_NAME, FROZEN_NAME,
76+
COURSE1_NAME, COURSE2_NAME, COURSE3_NAME, COURSE3_NAME].each do |id|
7077
find_by = (id.to_i.to_s == id.to_s) ? :id : :name
71-
script = Script.includes([{script_levels: [{level: [:game, :concepts] }, :stage]}, :stages]).
78+
script = Script.includes([{script_levels: [{level: [:game, :concepts] }, :stage, :callouts]}, :stages]).
7279
find_by(find_by => id)
7380
cache[script.name] = script
7481
cache[script.id.to_s] = script

dashboard/app/models/script_level.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class ScriptLevel < ActiveRecord::Base
55
belongs_to :script, inverse_of: :script_levels
66
belongs_to :stage, inverse_of: :script_levels
77
acts_as_list scope: :stage
8+
has_many :callouts, inverse_of: :script_level
89

910
NEXT = 'next'
1011

@@ -115,15 +116,4 @@ def self.cache_find(id)
115116
@@script_level_map ||= ScriptLevel.includes([{level: [:game, :concepts]}, :script]).index_by(&:id)
116117
@@script_level_map[id]
117118
end
118-
119-
def available_callouts
120-
@@available_callouts ||= {}
121-
@@available_callouts[self.id] ||=
122-
Callout.where(script_level_id: self.id).select(:id, :element_id, :qtip_config, :localization_key)
123-
return @@available_callouts[self.id]
124-
end
125-
126-
def self.clear_available_callouts_cache
127-
@@available_callouts = {}
128-
end
129119
end

dashboard/test/controllers/script_levels_controller_test.rb

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ class ScriptLevelsControllerTest < ActionController::TestCase
1010
@admin = create(:admin)
1111
sign_in(@admin)
1212

13-
ScriptLevel.clear_available_callouts_cache
14-
1513
@script = Script.find(Script::TWENTY_HOUR_ID)
1614
@script_level = @script.script_levels.fifth
1715

@@ -275,24 +273,22 @@ class ScriptLevelsControllerTest < ActionController::TestCase
275273

276274
sign_out(@admin)
277275

278-
stage = create :stage, script: Script.find_by_name('course1')
279-
level = create :unplugged, name: 'NewUnplugged', type: 'Unplugged'
280-
@script_level = create(:script_level, stage: stage, script: stage.script, level: level)
276+
script_level = Script.find_by_name('course1').script_levels.first
281277

282-
get :show, script_id: @script_level.script, stage_id: stage.position, id: @script_level.position
278+
get :show, script_id: script_level.script, stage_id: script_level.stage.position, id: script_level.position
283279

284280
assert_response :success
285281

286-
assert_select 'div.unplugged > h2', 'Test title'
287-
assert_select 'div.unplugged > p', 'Test description'
282+
assert_select 'div.unplugged > h2', 'Happy Maps'
283+
assert_select 'div.unplugged > p', 'Students create simple algorithms (sets of instructions) to move a character through a maze using a single command.'
288284
assert_select '.pdf-button', 2
289285

290-
unplugged_curriculum_path_start = "curriculum/#{stage.script.name}/#{stage.position}"
286+
unplugged_curriculum_path_start = "curriculum/#{script_level.script.name}/#{script_level.stage.position}"
291287
assert_select '.pdf-button' do
292288
assert_select "[href=?]", /.*#{unplugged_curriculum_path_start}.*/
293289
end
294290

295-
assert_equal @script_level, assigns(:script_level)
291+
assert_equal script_level, assigns(:script_level)
296292
end
297293

298294
test "show redirects to canonical url for custom scripts" do
@@ -343,11 +339,16 @@ class ScriptLevelsControllerTest < ActionController::TestCase
343339
test "should select only callouts for current script level" do
344340
@controller.expects :slog
345341

346-
callout1 = create(:callout, script_level: @script_level)
347-
callout2 = create(:callout, script_level: @script_level)
342+
script = create(:script)
343+
level = create(:level, :blockly, user_id: nil)
344+
stage = create(:stage, script: script)
345+
script_level = create(:script_level, script: script, level: level, stage: stage)
346+
347+
callout1 = create(:callout, script_level: script_level)
348+
callout2 = create(:callout, script_level: script_level)
348349
irrelevant_callout = create(:callout)
349350

350-
get :show, script_id: @script.id, id: @script_level.id
351+
get :show, script_id: script.name, stage_id: stage.position, id: script_level.position
351352

352353
assert(assigns(:callouts_to_show).include?(callout1))
353354
assert(assigns(:callouts_to_show).include?(callout2))
@@ -357,8 +358,15 @@ class ScriptLevelsControllerTest < ActionController::TestCase
357358
test "should localize callouts" do
358359
@controller.expects :slog
359360

360-
create(:callout, script_level: @script_level, localization_key: 'run')
361-
get :show, script_id: @script_level.script_id, id: @script_level.id
361+
script = create(:script)
362+
level = create(:level, :blockly, user_id: nil)
363+
stage = create(:stage, script: script)
364+
script_level = create(:script_level, script: script, level: level, stage: stage)
365+
366+
create(:callout, script_level: script_level, localization_key: 'run')
367+
368+
get :show, script_id: script.name, stage_id: stage.position, id: script_level.position
369+
362370
assert assigns(:callouts).find{|c| c['localized_text'] == 'Hit "Run" to try your program'}
363371
end
364372

@@ -370,7 +378,7 @@ class ScriptLevelsControllerTest < ActionController::TestCase
370378
stage = create(:stage, script: script)
371379
script_level = create(:script_level, script: script, level: level, stage: stage)
372380

373-
get :show, script_id: script.name, stage_id: stage, id: script_level.position
381+
get :show, script_id: script.name, stage_id: stage.position, id: script_level.position
374382

375383
assert_equal script_level, assigns(:script_level)
376384

@@ -380,8 +388,15 @@ class ScriptLevelsControllerTest < ActionController::TestCase
380388
test "with callout defined should define callout JS" do
381389
@controller.expects :slog
382390

383-
create(:callout, script_level: @script_level)
384-
get :show, script_id: @script.id, id: @script_level.id
391+
script = create(:script)
392+
level = create(:level, :blockly, user_id: nil)
393+
stage = create(:stage, script: script)
394+
script_level = create(:script_level, script: script, level: level, stage: stage)
395+
396+
create(:callout, script_level: script_level)
397+
398+
get :show, script_id: script.name, stage_id: stage.position, id: script_level.position
399+
385400
assert(@response.body.include?('Drag a \"move\" block and snap it below the other block'))
386401
end
387402

dashboard/test/integration/caching_test.rb

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,38 @@ def no_database
9494

9595

9696
# course1 is not caching yet
97-
# test "should get show of course1 level 1 and then level 10" do
98-
# get '/s/course1/stage/1/puzzle/1'
99-
# assert_response :success
97+
test "should get show of course1 level 1 twice" do
98+
get '/s/course1/stage/3/puzzle/1'
99+
assert_response :success
100100

101-
# no_database
101+
no_database
102102

103-
# get '/s/course1/stage/1/puzzle/10'
104-
# assert_response :success
105-
# end
103+
get '/s/course1/stage/3/puzzle/1'
104+
assert_response :success
105+
end
106106

107-
# test "post milestone to course1" do
108-
# sl = Script.find_by_name('course1').script_levels[2]
107+
# course1 caching across levels is not working yet
108+
# test "should get show of course1 level 1 and then level 10" do
109+
# get '/s/course1/stage/3/puzzle/1'
110+
# assert_response :success
109111

110-
# post "milestone/0/#{sl.id}"
111-
# assert_response 200
112+
# no_database
112113

113-
# no_database
114+
# get '/s/course1/stage/3/puzzle/10'
115+
# assert_response :success
116+
# end
114117

115-
# post "milestone/0/#{sl.id}"
116-
# assert_response 200
117-
# end
118+
test "post milestone to course1 passing" do
119+
sl = Script.find_by_name('course1').script_levels[2]
120+
params = {program: 'fake program', testResult: 100, result: 'true'}
121+
122+
post "milestone/0/#{sl.id}", params
123+
assert_response 200
124+
125+
no_database
126+
127+
post "milestone/0/#{sl.id}", params
128+
assert_response 200
129+
end
118130

119131
end

0 commit comments

Comments
 (0)