Multiple replaceWith<>() actions - kotlin

I have two views in the tornadofx Kotlin app.
Within View # 1 input for certain initial values is performed, certain calculations are made and results are added to mutableListOf <>().
Then View # 1 is replacedWith View # 2 upon pressing the button "Next). The results of calculation are demonstrated in View # 2 in the set of
fileldset{
field("") {label(SimpleFloatProperty(result1))}
}
When the first replaceWith View # 2 operation is performed everything is fine.
But.
In some cases the user has to return to View # 1, change some initial values there, perform the same calculations with the new input and go again to View # 2 to view updated results. I send him to View # 1 with replaceWith command initiated by the button "Back".
He comes back to View # 2 by the button "Next" (= replaceWith View #2).
And here comes the problem. All output (field(""){label (SimpleFloatProperty(result1))}in View # 2 remains the same. They do not change! Despite the fact that the values themselves change OK (debugged that by println of these SimpleFloatProperty).
I tried different workouts - used textfields, for example. It does not help.
I've got a feeling that the fieldset in View is initialized only once - when the View is entered first.
Please, advise how to resolve the described problem.
Thank in advance.

Related

composeTestRule checking that atleast 1 item exists

I have a list which has 2 different items. However, if the user gets close to the end of the list then the 2 same items are added again and again to create an infinite scrolling feel.
I've created a test to basically verify that the item exists like so:
composeTestRule
.onAllNodesWithContentDescription("Home")
.assertCountEquals(2)
As you can see this just finds nodes with the content description of "Home" and checks if their are 2.
Currently, this works as the screen size is small but let's say the screen size is doubled then this will fail as the assertCountEquals(2) would need to check for 4.
I was wondering to make this code better, is there a way to basically check that atleast 1 exists?
onAllNodes methods return an array, grab the first element and check whether it exists or is displayed.
composeTestRule
.onAllNodesWithContentDescription("Home")
.onFirst().assertExists()

Apex, Dynamic action, Confirm action, not picking up correct text - what am I missing?

I'm obviously missing something and hoping someone might be able to help.
I've an Interactive Grid, and a button.
When the button is pressed the dynamic action on the button has 2 steps.
Action 1 - Execute Javascript to take a value from one of the IG cells and put it into a page item.
Action 2 - Confirm Action - Are you sure you wish to delete &P10_JOB_ID.
I've made the page item, &P10_JOB_ID, visible and I can see the value has correctly been changed to the value from the IG.
I write P10_JOB_ID into a database table - I get the correct value
But the confirm message isn't picking up the correct value from P10_JOB_ID.
Namely it uses the value in P10_JOB_ID when the page starts, but then as I move around the IG pressing the button and changing the value of P10_JOB_ID, the text in the confirm message never changes.
Can anyone suggest what I might have missed, I'm baffled.
Thanks a lot
Substitutions like &P10_JOB_ID. are made when the page is rendered, not dynamically, so reflect the value at time of page load.
You will need to use Javascript to perform the conform action, something like:
apex.page.confirm ('Are you sure you wish to delete ' + $v('P10_JOB_ID') + '?', 'DELETE');
$v is an APEX Javascript function that returns the current value of a page item.
I used 'DELETE' as an example of a request value; you may want to do something different here.
Ok - having the setting of value and confirm as 2 separate actions is what causes the problem.
As per fac586
That is the expected behaviour. Static text substitutions are performed once during page show processing. They are not evaluated dynamically in the browser at runtime as values change.
Drop the second action and extend the first to display the confirm dialog using the apex.message.confirm JS API method, accessing the item value using the $v shorthand method.

Best practice for ensuring test methods order

Django 1.9. I want to test that input forms are invisible normally. And only when a user presses toggle menu button, login and password input elements appear.
The problem is that this is all about methods of a class. I want to be sure that one method executes before another. I have found this solution with 0 and 1 in method names.
class FuncTestTablets(TestCase):
#classmethod
def setUpClass(cls):
pass
#classmethod
def tearDownClass(cls):
pass
def test_0_tablets_login_input_form_absent(self):
# At home page with tablet screen size Edith sees no login input element.
## 0 is for stating explicitly that this test goes before the ones with 1 in their name.
self.browser.get('http://localhost:8000')
login_input = self.browser.find_element_by_id('login')
self.assertFalse(login_input.is_displayed(), "Login input element is visible on large devices")
def test_1_tablets_login_input_form_present_when_menu_button_pressed(self):
# At home page Edith presses menu button and login input appears.
## 1 is for stating explicitly that this test goes after the ones with 0 in their name.
menu_button = self.browser.find_element_by_class_name('navbar-toggle')
menu_button.click()
login_input = self.browser.find_element_by_id('login')
self.assertTrue(login_input.is_displayed(), "Login input element is not visible on tablet devices when menu button is pressed.")
This seems to work. Could you tell me is there some generally known methodology for such cases. Maybe some best practice.
I've just started Django and I don't think that my solution is at once the best.
That's why I decided to ask you. Thank you in advance.
Best practice is that the order of your test methods does not matter at all and if you inherit from django.test.TestCase, it should not matter. I have, however, been in the situation where I wanted to test a feature 'foo' in one method and then, for convenience (like not having to wrap it in try-except), assume that it is working properly in other methods that test something else ('bar').
I named my test methods
test_a_foo
test_b_bar
This seems more appropriate then using numbers because tests are executed in lexicographic order where, e.g.
test_11_eleven
is executed before
test_2_two
If you then have to insert another test later, you can still change the names to:
test_b1_first_b
test_b2_second_b

Does mvc 4 application need another model to return aggregate data on an existing table and model

I have a table (and model) with the following properties in an asp.net MVC 4 application:
TV Table
height
width
depth
type
brand
cost
When the user answes a question about the space that they have for the TV I then do an ajax call to determine which types are possible to fit into the space they have specified. Which type of TV type they want is the following question, so some options may need to be disabled. The SQL for what types fit in the space is "select distinct type from TV where height < #height and width < #width and depth < #depth".
Should I:
1. create a new model that I call from the TV controller just to return the distinct types
2. add a method to the TV model that I call from the TV controller that just returns a list of string with the types that fit
Depends on what you want to display to the user based on her selection' e. g.
If you want to display TV name + its description then returning a list of TV model will make sense.
If you are just going to display a list of TV names in combo box, then returning a list of string will suffice.
Calling a new action make sense in both cases IMHO.
EDIT:
For 2 - I want to return a list of string - should I create a new data model for this, or add a method in the existing TV data model that returns a list of string?
To expand on above query, since its not clear (at least I do not visualize it) from your question i will assume few things.
Case 1: You are displaying a view say "TVSelection" to the user that does not contain list of TVModels. In this view you are expecting user to enter three values i.e. Width, Height, Depth. Now when user enter these values, she can submit the form or you can fetch the TV Brand name list on Lost Focus event as well. In any case, the question would be are you updating existing view by populating the combo box or you are displaying a new view. I am assuming you are updating existing "TVSelection" view by the means of making an AJAX call. In that case you can just call a method on your controller (which displayed the "TVSelection" view) that returns a list of TV Brand names.
Case 2: You are displaying "TVSelection" view that already has a list of TVModel objects and you update it dynamically on selection of required field (filtering). In this case you can add a method in the TVModel itself to filter names only that matches the user selection.
I found these links relevant 1 & 2.
Hope that make sense.
Please add more details to your question if this does not answer your question.

ExtJS grid 'reset'

I'm on ExtJS 4 and using an MVC approach. I've created a simple grid view class, and have added a componentquery type 'ref' to that view in my controller. Within the initial grid view itself I set several columns to be hidden and some to be visible by default. The rendering of the grid with those settings is all working fine.
Then I have a button that, when clicked and based on some other conditions, will make some of the initially hidden grid columns visible. This works as well.
But what I need is a way to later 'reset' the grid to its initial view (with the correct columns hidden/visible, as they were initially).
I've tried various permutations of the following with no effect:
var theGrid = this.getTheGrid();
theGrid.reconfigure(store, theGrid.initialConfig.columns);
theGrid.getView().refresh();
I suppose I could loop through every column and reset its 'hidden' state, but would think there's a way to just 'reset' back to what's set in the class? Advice?
SOLUTION UPDATE
Appreciate the pointer from tuespetre. For anyone coming along in the future looking for specifics, here is what was needed (at least for my implementation):
Within the view, moved the column defs into a variable
Within the view, columns ref within the class becomes:
columns: myColumns,
Within the view, the following function created within the class:
resetGrid: function(){
this.reconfigure(null, myColumns);
},
Within the controller:
var theGrid = this.getTheGrid();
theGrid.resetGrid();
You will just need to create a function on your view class to encapsulate that functionality.