How to test select box without any option selected with codeception? - codeception

So the value of the field should be the first option selected.
As i see the problem is here
public function seeOptionIsSelected($select, $optionText)
{
$selected = $this->matchSelectedOption($select);
$this->assertDomContains($selected, 'selected option');
//If element is radio then we need to check value
$value = $selected->getNode(0)->tagName == 'option' ? $selected->text() : $selected->getNode(0)->getAttribute('value');
$this->assertEquals($optionText, $value);
}

This situation can be tested with the following:
$I->seeElement("#id_of_the_select_box");
$I->dontSeeElement("#id_of_the_select_box option[selected='selected']");

Related

Apache Poi Word Table, information about the Alt Text

How to get the Alt Text from a Table in Word, e.g. Title or Description.
All the Information, that I found had the context, Text, Width, Style etc. to read or modify.
My goal is to identify certain Tables in a Template, so I can modify them.
I am going to make some assumptions here. First that you are talking about the docx format, and second that by "Alt Text" you mean a caption.
A caption is just a paragraph that either precedes, or follows a table. It will have a style of Caption, a run with some text like Table, and probably includes a simple field SEQ Table. That would be the default Table caption, but it could be just a run with a name like Department Heads. The key is the style name. Word uses standard style names to calculate other things as well such as TOC.
Note: in Word, you cannot modify a caption by selecting a table, and clicking a menu option. It isn't really linked in any meaningful way. You have to modify the paragraph.
So to find a caption, you need to look in the Document elements list XWPFDocument.getBodyElements(), and find each paragraph with a style of Caption. Once you have found the one you want, then you can either look at the element immediately above or below to find the table. Your search will be easier if you can know that captions are all above or all below the tables.
So to retrieve the table following a specific named caption I would try something like this:
public XWPFTable FindTable(String name) {
boolean foundTable = false;
XWPFParagraph p;
for (IBodyElement elem : doc.getBodyElements()) {
switch (elem.getElementType()) {
case PARAGRAPH:
foundTable = false;
p = (XWPFParagraph) elem;
if (p.getStyle() == "Caption" && p.getText() == name) {
foundTable = true;
}
break;
case TABLE:
if (foundTable) {
return (XWPFTable) elem;
}
break;
case CONTENTCONTROL:
foundTable = false;
break;
default:
foundTable = false;
break;
}
}
return null;
}
In Word you can set the table caption to something unique, and then get the table in xml:
String tableXML = mytable.getCTTbl();
To extract the table caption:
String[] xml = tableXML.split(System.lineSeparator());
String caption = null;
for (String x : xml)
{
if (x.contains("w:tblCaption"))
{
caption = x.split("w:val=")[1].replace("/>", "");
caption = caption.replace("\"", "");
}
}

Validation .passes if null/empty/length == 0 doesn't fire

Validation doesn't seem to be called when the property has no value.
This is the code I'm using to try and make it work:
.ensure('baseContent.SetNamePrint').passes((name) =>
{
var webNameLength = this.baseContent.SetNameWeb.length;
var printNameLength = name.length;
console.log(webNameLength);
console.log(printNameLength);
if ((webNameLength > 1 && webNameLength < 51) || (printNameLength > 1 && printNameLength < 51)) {
return true;
}
return false;
}).withMessage('Web Name or Print Name is Required')
The passes only fires when the value of the property changes to something with a length, when it's empty (a blank string) nothing happens.
What I need is for the .passes() to be called every time there is a change to the value not just when there is a change and it has a value.
You need to additionally constraint the target property with isNotEmpty.
.ensure('baseContent.SetNamePrint').isNotEmpty().passes(...
From the documentation:
The isNotEmpty rule is always checked first before any other
validation rule. This means that without the isNotEmpty rule, the
.hasMinLength(5) rule would still consider a value of '' as valid
because the field is allowed to be empty.
PS: I heard that aurelia-validation is under rewriting. Perhaps that's why I can't find the documentation from the master branch anymore, but in another branch here
To get what I wanted I ended up with the following code.
this.validator = this.validation.on(this)
.ensure('SetNameWeb', (config) => {config.computedFrom(['SetNamePrint', 'SetNameWeb'])})
.if(() => { return this.HasImageEitherPrintNameOrWebName === false })
.isNotEmpty().withMessage('or "Print Name" is required')
.hasLengthBetween(0, 50)
.endIf()
.ensure('SetNamePrint', (config) => {config.computedFrom(['SetNameWeb', 'SetNamePrint'])})
.if(() => { return this.HasImageEitherPrintNameOrWebName === false })
.isNotEmpty().withMessage('or "Web Name" is required')
.hasLengthBetween(0, 50)
.endIf()
This gave me the functionality I needed with both of the fields being updated with each other.
However there was a bug in the aurelia code with the way it handles computedFrom that needed fixing to get this to work.
This problem was with aurelia-validation#0.6.8 though and there is now a new version which works in a completely different way so my recommendation is to update if you're having this problem.

AgileToolkit - Custom SQL request + Paginator

Hello I a little problem with my paginator, i would like to use some custom SQL Request but each time i click on a paginator link it loads my model without the custom request
I enter informations on a form that I send by GET method:
$view->grid->js()->reload(array("From" =>
$form->get("From"),"To" => $form->get("To"),"SSID" => $form->get("SSID")))
->execute();
On my view I have :
$this->request=$this->api->db->dsql();
$this->grid=$this->add('Grid');
$this->grid->setModel('Systemevents',array('ID','ReceivedAt','Message'));
$this->grid->addPaginator(10);
if (isset($_GET["SSID"])) {
$this->ssid = $_GET["SSID"];
}
if (isset($_GET["From"])) {
$this->from = $_GET["From"];
}
if (isset($_GET["To"])) {
$this->to = $_GET["To"];
}
$this->grid->dq->where($this->requette->expr('Message like "%.% '
. $this->ssid . ' % src=%"'))
->where($this->requette->expr("ReceivedAt >= '".$this->from. "'
AND ReceivedAt <= '".$this->to."'"));
The problem is that the where condition disapear when i change the page with the paginator.
I did not found any solution to my problem so I have done something differently
I added two buttons to my grid wich allows me to change the limit of the sql request.
The previous button is hidden if the limit is 0.
Now i have to found how to count the number of lines (select count('ID') from 'SystemEvents' where....) and to stock it in a variable.
Finally the ultimate solution was to do :
if ((isset($_GET["SSID"])) || (isset($_GET["From"])) || (isset($_GET["To"]))) {
//GET Method from Recherche.php
$this->ssid = ($_GET["SSID"] == "null" ? null : $_GET["SSID"]);
$this->api->stickyGET("SSID"); // the solutiuon is here
$this->from = ($_GET["From"] == "null" ? null : $_GET["From"]);
$this->api->stickyGET("From"); // <===== the solutiuon is here
$this->to = ($_GET["To"] == "null" ? null : $_GET["To"]);
$this->api->stickyGET("To"); // <===== the solutiuon is here
}

Disable or enable edit for selective cell in dojox data grid

How to disable or enable edit for selective cell in dojox data grid i.e
Imagine I have two columns (A, B) in a data grid. I want column value of B to be editable based on the value of column A. I have seen one solution in stack overflow which was specific to a DOJO version. I would like to know if there are APIs by which we can achieve above objective.
My preferred method is to override the
canEdit: function(inCell, inRowIndex)
method of the DataGrid. From that, you can get the item:
this.getItem(inRowIndex)
then work out if it should be editable or not, and return true/false.
This does override the editable flag on the column though, so you'll need to do something with that if needed.
There is no API as such. I also had similar requirement recently and here is how I implemented it:
1) Initially the column B is editable because I made it so in the Fields section of grid
2) Use onRowClick to capture the rendering of rows. Something like this should do
dojo.connect(grid, "onRowClick", grid, function(evt){
var idx = evt.rowIndex,
item = this.getItem(idx);
// get a value out of the item
msname = this.store.getValue(item, "msname");
if(msname != null &U& (trim(msname) == trim(offsetName))) {
dojox.grid.cells._Base.prototype.format(idx, item);
}
});
The following method then disallows inline editing of required column. We are passing row index and column index to this following function:
dojox.grid.cells._Base.prototype.format = function(inRowIndex, inItem){
var f, i=grid.edit.info, d=this.get ? this.get(inRowIndex, inItem) : (this.value || this.defaultValue);
d = (d && d.replace && grid.escapeHTMLInData) ? d.replace(/&/g, '&').replace(/</g, '<') : d;
//Check inRowIndex and inItem to determine whether to be editable for this row here.
if(this.editable && (this.alwaysEditing || (i.rowIndex==inRowIndex && i.cell==this))){
return this.formatEditing(d, inRowIndex);
}else{
return this._defaultFormat(d, [d, inRowIndex, this]);
}
}
Hope that helps. Probably you can add a jsfiddle and we can try fixing it.

Refresh a dijit.form.Select

First, you have to know that I am developing my project with Struts (J2EE
Here is my problem :
I have 2 dijit.form.Select widgets in my page, and those Select are filled with the same list (returned by a Java class).
When I select an option in my 1st "Select widget", I would like to update my 2nd Select widget, and disable the selected options from my 1st widget (to prevent users to select the same item twice).
I succeed doing this (I'll show you my code later), but my problem is that when I open my 2nd list, even once, it will never be refreshed again. So I can play a long time with my 1st Select, and choose many other options, the only option disabled in my 2nd list is the first I've selected.
Here is my JS Code :
function removeSelectedOption(){
var list1 = dijit.byId("codeModif1");
var list2 = dijit.byId("codeModif2");
var list1SelectedOptionValue = list1.get("value");
if(list1SelectedOptionValue!= null){
list2.reset();
for(var i = 0; i < myListSize; i++){
// If the value of the current option = my selected option from list1
if(liste2.getOptions(i).value == list1SelectedOptionValue){
list2.getOptions(i).disabled = true;
} else {
list2.getOptions(i).disabled = false;
}
}
}
Thanks for your help
Regards
I think you have to reset() the Select after you've updated its options' properties. Something like:
function removeSelectedOption(value)
{
var list2 = dijit.byId("codeModif2"),
prev = list2.get('value');
for(var i = 0; i < myListSize; i++)
{
var opt = myList[i];
opt.disabled = opt.value === value;
list2.updateOption(opt);
}
list2.reset();
// Set selection again, unless it was the newly disabled one.
if(prev !== value) list2.set('value', prev);
};
(I'm assuming you have a myList containing the possible options here, and the accompanying myListSize.)