spec/kern/controller_spec.rb in flok-0.0.56 vs spec/kern/controller_spec.rb in flok-0.0.57
- old
+ new
@@ -612,11 +612,10 @@
}
expect(ctx.eval("read_res_called")).to eq(true)
end
-
it "Does allow interval (every) events" do
#Compile the controller
ctx = flok_new_user File.read('./spec/kern/assets/interval.rb')
#Run the embed function
@@ -764,7 +763,109 @@
4.times do
@driver.int "int_timer"
end
expect(ctx.eval("timer_called")).to eq(2)
+ end
+
+ it "Does support the optional choose_action function" do
+ #Compile the controller
+ ctx = flok_new_user File.read('./spec/kern/assets/choose_action.rb')
+
+ #Run the embed function
+ ctx.eval %{
+ //Call embed on main root view
+ base = _embed("my_controller", 0, {}, null);
+ }
+ end
+
+ it "Does support the optional choose_action function with on_entry, and on_entry is called after on_entry global and before the first actions on_entry" do
+ #Compile the controller
+ ctx = flok_new_user File.read('./spec/kern/assets/choose_action.rb')
+
+ #Run the embed function
+ dump = ctx.evald %{
+ //Call embed on main root view
+ dump.base = _embed("my_controller", 0, {}, null);
+ dump.on_entry_call_order = on_entry_call_order;
+
+ for (var i = 0; i < 100; ++i) {
+ int_dispatch([]);
+ }
+ }
+
+ #Global on_entry should be called before choose_action_on_entry
+ expect(dump["on_entry_call_order"]).to eq([
+ "global_on_entry",
+ "choose_action_on_entry",
+ "index_on_entry"
+ ])
+
+ #Expect not to get an event from the choose_action
+ @driver.ignore_up_to "if_event"
+ @driver.mexpect("if_event", [Integer, "action", {"from" => nil, "to" => "index"}])
+ end
+
+ it "Does support a controller that lacks choose_action, the first action will be the first action that appears in the controller" do
+ #Compile the controller
+ ctx = flok_new_user File.read('./spec/kern/assets/no_choose_action.rb')
+
+ #Run the embed function
+ dump = ctx.evald %{
+ //Call embed on main root view
+ dump.base = _embed("my_controller", 0, {}, null);
+ dump.on_entry_call_order = on_entry_call_order;
+
+ for (var i = 0; i < 100; ++i) {
+ int_dispatch([]);
+ }
+ }
+
+ #Global on_entry should be called before choose_action_on_entry
+ expect(dump["on_entry_call_order"]).to eq([
+ "global_on_entry",
+ "index_on_entry"
+ ])
+
+ #Expect not to get an event from the choose_action
+ @driver.ignore_up_to "if_event"
+ @driver.mexpect("if_event", [Integer, "action", {"from" => nil, "to" => "index"}])
+ end
+
+ it "Does support using a synchronous request in choose_action" do
+ ctx = flok_new_user File.read('./spec/kern/assets/choose_action_sync.rb'), File.read("./spec/kern/assets/test_service/config0.rb")
+ dump = ctx.evald %{
+ base = _embed("my_controller", 0, {}, null);
+
+ //Drain queue
+ int_dispatch([]);
+ }
+
+ #Expect not to get an event from the choose_action
+ @driver.ignore_up_to "if_event"
+ @driver.mexpect("if_event", [Integer, "action", {"from" => nil, "to" => "index"}])
+ end
+
+ it "Not setting a Goto will result in an exception" do
+ ctx = flok_new_user File.read('./spec/kern/assets/choose_action_sync_no_goto.rb'), File.read("./spec/kern/assets/test_service/config0.rb")
+ expect {
+ ctx.evald %{
+ base = _embed("my_controller", 0, {}, null);
+
+ //Drain queue
+ int_dispatch([]);
+ }
+ }.to raise_exception
+ end
+
+ it "Calling an asynchronous request for the Goto in choose_action will result in an exception" do
+ ctx = flok_new_user File.read('./spec/kern/assets/choose_action_async.rb'), File.read("./spec/kern/assets/test_service/config0.rb")
+ expect {
+ ctx.evald %{
+ base = _embed("my_controller", 0, {}, null);
+
+ //Drain queue
+ int_dispatch([]);
+ }
+ }.to raise_error(/choose_action.*Goto/)
end
end