Skip to content

Commit

Permalink
Test KomaUI() click buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
beorostica committed Jul 10, 2023
1 parent d22f81b commit a116589
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 93 deletions.
16 changes: 16 additions & 0 deletions src/KomaMRI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,23 @@ using MRIReco
include("reconstruction/Recon.jl")

#GUI
const global CONT_INDEX = "index"
const global CONT_SEQUENCE = "sequence"
const global CONT_KSPACE = "kspace"
const global CONT_M0 = "m0"
const global CONT_M1 = "m1"
const global CONT_M2 = "m2"
const global CONT_PHANTOM = "phantom"
const global CONT_SCANNER_PARAMS = "scanneparams"
const global CONT_SIM_PARAMS = "simparams"
const global CONT_REC_PARAMS = "recparams"
const global CONT_ABSI = "absi"
const global CONT_ANGI = "angi"
const global CONT_ABSK = "absk"
const global CONT_SIG = "sig"
include("KomaUI.jl")
export CONT_INDEX, CONT_SEQUENCE, CONT_KSPACE, CONT_M0, CONT_M1, CONT_M2, CONT_PHANTOM,
CONT_SCANNER_PARAMS, CONT_SIM_PARAMS, CONT_REC_PARAMS, CONT_ABSI, CONT_ANGI, CONT_ABSK, CONT_SIG

export KomaUI

Expand Down
1 change: 1 addition & 0 deletions src/KomaUI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ end
## MENU FUNCTIONS
handle(w, "index") do args...
content!(w, "div#content", index)
@js_ w document.getElementById("content").dataset.content = $CONT_INDEX
end
handle(w, "pulses_seq") do args...
loading = replace(open(f->read(f, String), path*"/ui/html/loading.html"), "LOADDES"=>"Plotting sequence ...")
Expand Down
1 change: 1 addition & 0 deletions src/ui/PhantomGUI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ columnbuttons = Observable{Any}(makebuttons(phantom))

map!(makebuttons, columnbuttons, pha_obs)
ui = dom"div"(vbox(columnbuttons, plt))
@js_ w document.getElementById("content").dataset.content = $CONT_PHANTOM
content!(w, "div#content", ui)
1 change: 1 addition & 0 deletions src/ui/PulsesGUI_M0.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plt = Observable{Any}(plot_M0(seq;darkmode))
ui = dom"div"(plt)
map!(p->plot_M0(p;darkmode), plt, seq_obs)
@js_ w document.getElementById("content").dataset.content = $CONT_M0
content!(w, "div#content", ui)
1 change: 1 addition & 0 deletions src/ui/PulsesGUI_M1.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plt = Observable{Any}(plot_M1(seq;darkmode))
ui = dom"div"(plt)
map!(p->plot_M1(p;darkmode), plt, seq_obs)
@js_ w document.getElementById("content").dataset.content = $CONT_M1
content!(w, "div#content", ui)
1 change: 1 addition & 0 deletions src/ui/PulsesGUI_M2.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plt = Observable{Any}(plot_M2(seq;darkmode))
ui = dom"div"(plt)
map!(p->plot_M2(p;darkmode), plt, seq_obs)
@js_ w document.getElementById("content").dataset.content = $CONT_M2
content!(w, "div#content", ui)
1 change: 1 addition & 0 deletions src/ui/PulsesGUI_kspace.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plt = Observable{Any}(plot_kspace(seq;darkmode))
ui = dom"div"(plt)
map!(p->plot_kspace(p;darkmode), plt, seq_obs)
@js_ w document.getElementById("content").dataset.content = $CONT_KSPACE
content!(w, "div#content", ui)
1 change: 1 addition & 0 deletions src/ui/PulsesGUI_seq.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plt = Observable{Any}(plot_seq(seq; darkmode, range=[0 30]))
ui = dom"div"(plt)
map!(p->plot_seq(p; darkmode, range=[0 30]), plt, seq_obs)
@js_ w document.getElementById("content").dataset.content = $CONT_SEQUENCE
content!(w, "div#content", ui)
1 change: 1 addition & 0 deletions src/ui/RecParams_view.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ui = plot_dict(recParams)
title = """<h1 style="padding: 8px 16px; color: #868888;">Reconstruction parameters</h1>"""
@js_ w document.getElementById("content").dataset.content = $CONT_REC_PARAMS
content!(w, "div#content", title*ui)
1 change: 1 addition & 0 deletions src/ui/ReconGUI_absI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ end
plt = Observable{Any}(plotInteract())
map!(t-> plotInteract(), plt, img_obs)
ui = dom"div"(plt)
@js_ w document.getElementById("content").dataset.content = $CONT_ABSI
content!(w, "div#content", ui)
1 change: 1 addition & 0 deletions src/ui/ReconGUI_absK.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ end
plt = Observable{Any}(plotInteract())
map!(t-> plotInteract(), plt, img_obs)
ui = dom"div"(plt)
@js_ w document.getElementById("content").dataset.content = $CONT_ABSK
content!(w, "div#content", ui)
1 change: 1 addition & 0 deletions src/ui/ReconGUI_angI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ end
plt = Observable{Any}(plotInteract())
map!(t-> plotInteract(), plt, img_obs)
ui = dom"div"(plt)
@js_ w document.getElementById("content").dataset.content = $CONT_ANGI
content!(w, "div#content", ui)
1 change: 1 addition & 0 deletions src/ui/ScannerParams_view.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ sys_dict = Dict("B0" => sys.B0,
"ADC_dead_time_T" => sys.ADC_dead_time_T)
plt = plot_dict(sys_dict)
title = """<h1 style="padding: 8px 16px; color: #868888;">Scanner parameters</h1>"""
@js_ w document.getElementById("content").dataset.content = $CONT_SCANNER_PARAMS
content!(w, "div#content", title*plt)
1 change: 1 addition & 0 deletions src/ui/SignalGUI.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plt = Observable{Any}(plot_signal(raw_ismrmrd; darkmode))
ui = dom"div"(plt)
map!(p->plot_signal(p; darkmode), plt, sig_obs)
@js_ w document.getElementById("content").dataset.content = $CONT_SIG
content!(w, "div#content", ui)
1 change: 1 addition & 0 deletions src/ui/SimParams_view.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
plt = plot_dict(simParams)
title = """<h1 style="padding: 8px 16px; color: #868888;">Simulation parameters</h1>"""
@js_ w document.getElementById("content").dataset.content = $CONT_SIM_PARAMS
content!(w, "div#content", title*plt)
2 changes: 1 addition & 1 deletion src/ui/html/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,4 @@
}
</script>
<!-- For index.html -->
<div class="container" style="padding: 0px !important;" id="content">
<div class="container" style="padding: 0px !important;" id="content" data-content="index">
108 changes: 16 additions & 92 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,127 +39,51 @@ end

using Blink, Interact

"""
Execute function f() with a timeout of `timeout` seconds. Returns the
result of f() or `nothing` in the case of a timeout.
"""
function with_timeout(f::Function, timeout)
c = Channel{Any}(1)
@async begin
put!(c, f())
end
@async begin
sleep(timeout)
put!(c, nothing)
end
take!(c)
end

#w = with_timeout(()->KomaUI(dev_tools=true; blink_show=false), 60)
w = KomaUI(dev_tools=true; blink_show=false)

#@testset "Open UI" begin
# w = with_timeout(()->KomaUI(dev_tools=true; blink_show=false), 60)
# if !isnothing(w)
# close(w)
# @test true
# elseif VERSION < v"1.7"
# @test true
# else
# @test false
# end
#end
@testset "Open UI" begin
@test CONT_INDEX == @js w document.getElementById("content").dataset.content
end

@testset "PulsesGUI" begin
@js w document.getElementById("button_pulses_seq").click()
@test CONT_SEQUENCE == @js w document.getElementById("content").dataset.content
@js w document.getElementById("button_pulses_kspace").click()
@test CONT_KSPACE == @js w document.getElementById("content").dataset.content
@js w document.getElementById("button_pulses_M0").click()
@test CONT_M0 == @js w document.getElementById("content").dataset.content
@js w document.getElementById("button_pulses_M1").click()
@test CONT_M1 == @js w document.getElementById("content").dataset.content
@js w document.getElementById("button_pulses_M2").click()
@test true
#w = with_timeout(()->KomaUI(dev_tools=true; blink_show=false), 60)
#if !isnothing(w)
# @js w document.getElementById("button_pulses_seq").click()
# @js w document.getElementById("button_pulses_kspace").click()
# @js w document.getElementById("button_pulses_M0").click()
# @js w document.getElementById("button_pulses_M1").click()
# @js w document.getElementById("button_pulses_M2").click()
# close(w)
# @test true
#elseif VERSION < v"1.7"
# @test true
#else
# @test false
#end

@test CONT_M2 == @js w document.getElementById("content").dataset.content
end

@testset "PhantomGUI" begin
@js w document.getElementById("button_phantom").click()
@test true
#w = with_timeout(()->KomaUI(dev_tools=true; blink_show=false), 60)
#if !isnothing(w)
# @js w document.getElementById("button_phantom").click()
# close(w)
# @test true
#elseif VERSION < v"1.7"
# @test true
#else
# @test false
#end
@test CONT_PHANTOM == @js w document.getElementById("content").dataset.content
end

@testset "ParamsGUI" begin
@js w document.getElementById("button_scanner").click()
@test CONT_SCANNER_PARAMS == @js w document.getElementById("content").dataset.content
@js w document.getElementById("button_sim_params").click()
@test CONT_SIM_PARAMS == @js w document.getElementById("content").dataset.content
@js w document.getElementById("button_rec_params").click()
@test true
#w = with_timeout(()->KomaUI(dev_tools=true; blink_show=false), 60)
#if !isnothing(w)
# @js w document.getElementById("button_scanner").click()
# @js w document.getElementById("button_sim_params").click()
# @js w document.getElementById("button_rec_params").click()
# close(w)
# @test true
#elseif VERSION < v"1.7"
# @test true
#else
# @test false
#end
@test CONT_REC_PARAMS == @js w document.getElementById("content").dataset.content
end

@testset "ReconGUI" begin
@js w document.getElementById("button_reconstruction_absI").click()
@test CONT_ABSI == @js w document.getElementById("content").dataset.content
@js w document.getElementById("button_reconstruction_angI").click()
@test CONT_ANGI == @js w document.getElementById("content").dataset.content
@js w document.getElementById("button_reconstruction_absK").click()
@test true
#w = with_timeout(()->KomaUI(dev_tools=true; blink_show=false), 60)
#if !isnothing(w)
# @js w document.getElementById("button_reconstruction_absI").click()
# @js w document.getElementById("button_reconstruction_angI").click()
# @js w document.getElementById("button_reconstruction_absK").click()
# close(w)
# @test true
#elseif VERSION < v"1.7"
# @test true
#else
# @test false
#end
@test CONT_ABSK == @js w document.getElementById("content").dataset.content
end

@testset "SignalGUI" begin
@js w document.getElementById("button_sig").click()
@test true
#w = with_timeout(()->KomaUI(dev_tools=true; blink_show=false), 60)
#if !isnothing(w)
# @js w document.getElementById("button_sig").click()
# close(w)
# @test true
#elseif VERSION < v"1.7"
# @test true
#else
# @test false
#end
@test CONT_SIG == @js w document.getElementById("content").dataset.content
end

close(w)
Expand Down

1 comment on commit a116589

@cncastillo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little over engineered. I would suggest to remove the global constant variables.

Please sign in to comment.