expect = chai.expect
fractalpanel = require('fractalpanel')
FractalPanel = fractalpanel.FractalPanel
orientation = fractalpanel.orientation
pause_msec = 100
timeout_msec = 0
ask = false
int = (s) ->
expect = chai.expect
fractalpanel = require('fractalpanel')
FractalPanel = fractalpanel.FractalPanel
orientation = fractalpanel.orientation
pause_msec = 100
timeout_msec = 0
ask = false
int = (s) ->
console.log(“int(#{s})”)
if s
return Math.round(s.replace("px",''))
beep() # from lib/lib_test.js
throw "int(#{s}) expects a value"
split_pane = (panel_id, edge_id) ->
$("##{panel_id} .fractalpanel_knob_#{edge_id}").first().click()
close_pane = (panel_id) ->
selector = "##{panel_id} .fractalpanel_knob_tr"
knob = $(selector).first()
expect(knob.length, "#{selector} NOT FOUND so can't close").to.equal(1)
knob.click()
get_CSS_of_FIRST = (css_key, selector) ->
the_first = $(selector).first()
retval = the_first.css(css_key)
console.log “get_CSS_of_FIRST(#{css_key},’#{selector}’) return: #{retval} first.id:”,the_first.attr(“id”)
return retval
expect_kids_to_fit = (panel_id) ->
sel = "##{panel_id}"
console.log “sel:”,sel
clazz = $(sel).attr("class") or ""
if clazz.indexOf("vertical") > -1
the_orientation = "vertical"
the_direction = 'width'
if clazz.indexOf("horizontal") > -1
the_orientation = "horizontal"
the_direction = 'height'
if the_direction
This fails during “basic splitting” tests.
one = orientation[the_orientation][0]
two = orientation[the_orientation][1]
console.log “panel_id:”,panel_id,”the_direction:”,the_direction,”one:”,one, “two:”,two
sum = [
int(get_CSS_of_FIRST(the_direction, "##{panel_id} > .fractalpanel_#{one}"))
int(get_CSS_of_FIRST(the_direction, "##{panel_id} > .split-pane-divider"))
int(get_CSS_of_FIRST(the_direction, "##{panel_id} > .fractalpanel_#{two}"))
].join(" + ")
parent_extent = int($("##{panel_id}").first().css(the_direction))
tolerance = 2
difference = Math.abs(parent_extent - eval(sum))
expect(difference, sum).to.be.below(tolerance)
else
beep()
throw "cannot determine the direction of #{panel_id}: class='#{clazz}'"
expect_north_south = (panel_id) ->
sel = "##{panel_id}"
pane = $(sel)
expect(pane.hasClass("split-pane"))
kids = pane.children()
expect(kids.length).to.equal(4)
expect($(kids[0]).hasClass("split-pane-component")).to.be.true
expect($(kids[1]).hasClass("horizontal-divider")).to.be.true
expect($(kids[1]).hasClass("vertical-divider")).to.be.false
expect($(kids[2]).hasClass("split-pane-component")).to.be.true
expect($(kids[3]).hasClass("split-pane-resize-shim")).to.be.true
expect_east_west = (panel_id) ->
sel = "##{panel_id}"
pane = $(sel)
expect(pane.hasClass("split-pane"))
kids = pane.children()
expect(kids.length).to.equal(4)
expect($(kids[0]).hasClass("split-pane-component")).to.be.true
expect($(kids[1]).hasClass("vertical-divider")).to.be.true
expect($(kids[1]).hasClass("horizontal-divider")).to.be.false
expect($(kids[2]).hasClass("split-pane-component")) .to.be.true
expect($(kids[3]).hasClass("split-pane-resize-shim")).to.be.true
expect_inside = (panel_id) ->
panel_id should be a split-pane with one split-pane-component
sel = "##{panel_id}"
pane = $(sel)
expect(pane.attr(“class”), “fractalpanel_outer split-pane”)
msg = "expect_inside('#{panel_id}')"
expect(pane.hasClass("split-pane"))
kids = pane.children()
console.log("kids", kids)
expect(kids.length, msg).to.equal(2)
console.log("expect_inside(#{panel_id}) ==>", kids.length)
expect($(kids[0],msg).hasClass("split-pane-component"))
expect($(kids[1],msg).hasClass("split-pane-resize-shim"))
split_and_expect_kids_to_fit = (panel_id, edge_id) ->
console.log “split_and_expect_kids_to_fit(#{panel_id}, #{edge_id})”
split_pane(panel_id, edge_id)
expect_kids_to_fit(panel_id)
get_parent = (id) ->
return $("##{id}").parent()
scripted_expectations = (test, short_circuits, done) ->
Treat the title of the test as a script of space delimited commands
short_circuits ?= {}
script = test.title
actions = script.split(" ")
so_far = ""
for action in actions
[id, side] = action.split('.')
id = "fp_#{id}"
split_pane(id, side)
so_far += " " + action
parent = get_parent(id)
parent_id = parent.attr('id')
if side is 'close'
sibs_count = parent.children().length
close_pane(id)
make_check_closed = (test, id, parent_id) ->
return () ->
close_worked = $("#"+id).length is 0
console.log "id: #{id} close_worked:", close_worked
if short_circuits[action]?
desc = short_circuits[action]
if not desc? and test.pause_every_close
desc = "#{id} should be closed"
if desc?
q = "action: '#{action}' #{close_worked}:\n " + desc + "\nContinue?"
if confirm q
done()
return
else
test.pause = "sorry that didn't work out"
done()
expect(close_worked, "closing #{id} failed").to.be.true
if parent.attr(‘id’) is ‘fp_5’ test.pause = so_far + “: about to fail expect_inside(‘#{parent_id}’)” return not true in a general way
if sibs_count is '4'
expect_inside(parent_id)
else the parents parent
done()
setTimeout(make_check_closed(test, id, parent_id), 3000)
else
if parent_id
console.log " expect_#{side}(#{parent_id})"
if side in ['north','south']
expect_north_south(parent_id)
else
expect_east_west(parent_id)
done()
halt = () ->
expect(undefined, "").to.be.ok()
describe "FractalPanel tests", () ->
@timeout(timeout_msec)
@bail(true)
before () ->
after () =>
beforeEach () ->
test_title = this.currentTest.title
console.groupCollapsed(test_title);
@fp = new FractalPanel "body", "TEST: " + test_title,
make_frame: true
propagate:
always_show_NEWS_buttons: true
color_panels_uniquely: true
inject_tree_path: true
suppress_corner_buttons: false
suppress_content_area: false
show_NEWS_handle:
E: true
S: true
N: true
W: true
afterEach (done) ->
if @currentTest.state is 'failed'
beep()
console.log “CURRENT:”,@currentTest
if ask or @currentTest.pause
msg = @currentTest.pause + "\n\nContinue?"
if not confirm(msg)
@halt_and_catch_fire = true
if @halt_and_catch_fire
@intentionally.halt_and_catch_fire
else
setTimeout(() =>
delete @fp
FractalPanel.color_idx = 0
FractalPanel.last_ids = {}
$(".split-pane-frame").remove()
done()
console.groupEnd()
, pause_msec)
describe "basic splitting", () ->
it "east horizontally should work", () ->
edge_id = @test.title.split(" ")[0]
split_and_expect_kids_to_fit('fp_1', edge_id)
it "west horizontally should work", () ->
edge_id = @test.title.split(" ")[0]
split_and_expect_kids_to_fit('fp_1', edge_id)
it "north vertically should work", () ->
edge_id = @test.title.split(" ")[0]
split_and_expect_kids_to_fit('fp_1', edge_id)
it "south vertically should work", () ->
edge_id = @test.title.split(" ")[0]
split_and_expect_kids_to_fit('fp_1', edge_id)
describe "deeply nested splitting", () ->
it "crazily complex split should still not overlap", () ->
expect_inside('fp_1')
split_pane('fp_1', 'east')
expect_east_west('fp_1')
split_pane('fp_3', 'north')
expect_north_south('fp_5')
expect_kids_to_fit('fp_5')
split_pane('fp_6', 'east')
expect_kids_to_fit('fp_5')
split_pane('fp_9', 'north')
expect_kids_to_fit('fp_8')
split_pane('fp_12', 'east')
split_pane('fp_2', 'south')
expect_kids_to_fit('fp_17')
split_pane('fp_18', 'west')
expect_east_west('fp_20')
expect_kids_to_fit('fp_20')
describe "closing panes: NSEW x 2,3", () ->
it "1.east 3.close", () ->
expect_inside('fp_1')
split_pane('fp_1', 'east')
expect_east_west('fp_1')
close_pane('fp_3')
expect_inside('fp_1')
it "1.west 3.close", () ->
expect_inside('fp_1')
split_pane('fp_1', 'west')
expect_east_west('fp_1')
close_pane('fp_3')
expect_inside('fp_1')
it "1.north 3.close", () ->
expect_inside('fp_1')
split_pane('fp_1', 'north')
expect_north_south('fp_1')
close_pane('fp_3') # not sanity checked
expect_inside('fp_1')
it "1.south 3.close", () ->
expect_inside('fp_1')
split_pane('fp_1', 'south')
expect_north_south('fp_1')
close_pane('fp_3') # not sanity checked
expect_inside('fp_1')
it "1.east 2.close", () ->
expect_inside('fp_1')
split_pane('fp_1', 'east')
expect_east_west('fp_1')
close_pane('fp_2')
expect_inside('fp_1')
it "1.west 2.close", () ->
expect_inside('fp_1')
split_pane('fp_1', 'west')
expect_east_west('fp_1')
close_pane('fp_2')
expect_inside('fp_1')
it "1.north 2.close", () ->
expect_inside('fp_1')
split_pane('fp_1', 'north')
expect_north_south('fp_1')
close_pane('fp_2') # not sanity checked
expect_inside('fp_1')
it "1.south 2.close", () ->
expect_inside('fp_1')
split_pane('fp_1', 'south')
expect_north_south('fp_1')
close_pane('fp_2') # not sanity checked
expect_inside('fp_1')
describe "scripted_expectations WORK IN PROGRESS", () ->
beforeEach ->
@test.pause_every_close = true # NOT WORKING YET
alert @test.constructor.name
xit "2.east 3.east 3.close", (done) ->
@test.pause = “is this working now?”
scripted_expectations(@test, {}, done)
it "2.east 3.close", (done) ->
@test.pause = “just 2 should be showing” alert @test.constructor.name
scripted_expectations(@test, {}, done)
it "2.east 3.north 3.close", (done) ->
@test.pause = “3 should be closed”
scripted_expectations(@test, {}, done)
scripted_expectations(@test, {‘3.close’: ‘just 2 showing?’}, done)
it "2.east 2.close", (done) ->
scripted_expectations @test, {}, done
“2.close”:”only green fp_3 should be visible”, done
it "2.east 3.north 3.close 1.east 6.close", (done) ->
scripted_expectations(@test, {}, done)
it "2.east 3.north 6.east 9.north 12.close 6.close 9.close", (done) ->
scripted_expectations(@test, {}, done)
it "2.east 3.north 6.east 9.north 12.close 9.close 6.close", (done) ->
scripted_expectations(@test, {}, done)
it "2.east 3.north 6.east 9.north 12.close 9.close 6.close 3.close", (done) ->
scripted_expectations(@test, {}, done)
@test.pause = “is this working now?”
it "2.east 3.north 6.east 6.north 2.east 3.close 6.close 9.close 12.close 15.close", (done) ->
scripted_expectations(@test, {}, done)