Using 'or' in Protractor expected conditions - angularjs

I am trying to write an expects statement in Protractor that uses the or expected condition. However, the documentation does not have any examples of how to use 'or' or 'and' with these blocks.
I have tried doing
expect(myString).or.toEqual('a string').toEqual('another string')
expect(myString).toEqual('a string').or.toEqual('another string')
and just for kicks
expect(myString).toEqual('a string', 'another string')
This question has been asked previously but only a workaround was given.
I would like to actually use the or function that is built into Protractor as it should allow the message to read something like
Expected 'a totally different string' to be 'a string' or 'another string'

Examples are provided here: http://angular.github.io/protractor/#/api?view=ExpectedConditions. However, you're confusing the use of expected conditions, which is used for browser.wait and not expects.

You can always write a custom matcher. In this case, there is no need to write one, the one provided at Expect item in array would fit your use case. For jasmine 1.x:
this.addMatchers({
toBeIn: function(expected) {
var posibilities = Array.isArray(expected) ? expected : [expected];
return posibilities.indexOf(this.actual) > -1;
}
});
Usage:
expect(myString).toBeIn(["a string", "another string"]);
Just FYI, there is also a useful library of custom jasmine matchers: jasmine-matchers.

This is a bit of a hack, but it just helped me. I am posting it in case it would be useful to someone, not because I think it is the most elegant approach (and it may also be a "workaround"). It works if your strings are really different, and it works for strings, not more generally. For my case, I had to resolve the promise first.
myString.getText().then(function(text){
expect('a stringanother string'.search(text)).toBeGreaterThan(-1);
});
Of course the above would be quite happy to pass partial matches like 'n' or 'another' or nonsense like 'ngano'. None of those were going to happen in my case.

Related

Can't get Logic App Contains to work with array or comma separated string

I'm trying to look for specific keywords inside of text from a for each loop.
var text = "The lazy fox jumped over the brown dog."
var keywords = "fox,dog,sun";
If true, I want to do something with the text. If false, I want to ignore the text.
Does anyone know how to use an Array filter, Function, Select, Condition or inline code to check for this? If so, specific examples would be great.
By the way, I have a C# function that handles this extremely well in an ASP.net Core app.
UPDATE 1:
This doesn't work.
UPDATE 2:
The Condition is always false after the for each loop even after changing the settings and parallelism to 1.
Azure Logic App Condition does not work in loop if based on changing values
Thanks in advance!
There are so many ways to achieve what you need. Here are the 3 options that came to my mind within a minute.
The first one does use a For each loop, but I wouldn't recommend using it as it's not very efficient.
The For each parameter looks like this:
The Condition parameter looks like this:
The second option is much easier - no need for a loop, just filter the array straight away, then you can check whether it's empty or it has some items:
The Filter array parameters look as follows.
The split function is identical to the one used in option 1.
If you know JavaScript, you might decide to use regular expressions in inline code instead, e.g.:
Then you'd just need to check the output of the inline code. JavaScript code used in the example above:
var text = workflowContext.actions.Compose_text.outputs;
var keywords = workflowContext.actions.Compose_keywords.outputs;
return text.match(new RegExp("(" + keywords.split(",").join("|") + ")", "gi"));
My personal preference is option 2. However, please note that all 3 options above would find "sun" in text "The weather was sunny" even though there's no word "sun" in the text. If you do need "sun" to match only word "sun" - not "sunny", "asunder" or "unsung" - then go for option 3, just use a different, more complex regular expression.
One of the workaround would be use of Condition Connector. I have initialized the sentence in a string and then used Condition Connector which will be checking the conditions.
Finally, In the true section you can add the connectors accordingly.
Placing a Compose behind the for each loop and referencing the Output in the Condition is what finally worked for me. I used the toLower() function in my Compose. The Compose looks like this.
toLower(items('For_each_2')?['day']?['longPhrase'])

Structure members break, when accompanied with brackets

Example:
.. member:: CK_UTF8CHAR model[16]
Gives me both the type and the name bolded and hyperlink not working.
Practically we are forced to use this cases like that:
.. member:: model
Because otherwise it would be incorrect (use it without array and with the same type).
Well, this seems to be a real bug in Sphinx. I reported that and it was confirmed. I've come up with a little workaround for now, but it's more of a crutch. Just put the following to the layout.html file of your Sphinx theme:
<script>
$('dl.member dt').each(function() {
$(this).find('big:first').text('[')
$(this).find('big:last').text(']')
});
</script>
Now you may use parenthesis instead of brackets in broken structures: model(16) becomes model[16] (and label(\ ) becomes label[], but only within the .. member:: directive.
I know it is not a very elegant solution, but it is OK as a temporary fix, until the bug gets resolved.

$httpBackend.whenGET with more than one parameter

I have this URL to match:
$httpBackend.whenGET('/api/alerts/1121212156/0/4/0').repond(someObject)
The problem is that 1121212156 is a tick so it can be different every time. Does someone know how to create a regex to do that?
$httpBackend.whenGET(/\api/alerts/[0-9]+/2/4/0/).
respond(someObject);
The docs for $httpBackend.whenGET say that you can can pass in a regex object in place of a URL. I just did a quick test on regexpal.com to see if this regex works, and it says it does, although I didn't actually test it through whenGET.
var urlRegex = /\/api\/alerts\/[\d]+\/0\/4\/0/;
urlRegex.test('/api/alerts/1121212156/0/4/0'); // returns true
Hope that helps.

CakePHP/Croogo: Searching for strings with some special chars returns no results

I noticed there is a bug in Croogo's NodesController::search() when searching for words with some non-ascii chars on them e.g. 'üäö'. If I search for example for 'Steuergeräte' (german) I get no results, even though I should. If I search for 'Steuergerate' (which would be misspelled in german) I get the desired results. Which is totally weird.
A direct query on the db I works fine:
"SELECT * FROM i18n WHERE content LIKE '%Steuergeräte%';"
Which returns the expected records.
But it's not a general problem with unicode-chars, as for example, searching for a japanese word worked as expected. So this only affect some chars.
Cakephp: 2.4.0, Croogo: 1.4.5
Ok, I found the cause of the problem.
On the search-view, the string to be searched for is cleaned with:
$q = Sanitize::clean($this->request->params['named']['q']);
Which among other things runs html_entities on the string as default, when 'encode' => true is set (default). This would turn e.g. ö into ö and then search for words with html-entities on them.
I got a workaround by doing:
$q = $this->request->params['named']['q'];
// Use encode=false on Sanitize::clean to prevent äüöß etc. getting
// replaced by html entities. And strip tags manually first to prevent
// html injected strings.
$q = strip_tags($q);
$q = Sanitize::clean($q, array('encode' => false));
Note: If like in my case, TinyMCE is set with 'entity_encoding' => 'raw' then the body field in the nodes table would contain äöü instead of htmlentities as well, which IMO is a far better practice as replacing them with htmlentities. Per default though, tinymce replaces chars with htmlentities, so the body field would work with the default search behaviour of Croogo/Cakephp. But searching, for example, in the title-field wouldn't.
Update
Ok, as mark comments suggested, sanitizing and using cake's paginate method, is not necessary, so the Sanitize part can be skipped. I also found using htmlspecialchars even better as strip_tags, as strip_tags wouldn't take care of e.g. '&', and on the body, tinyMCE saves those as html_entities. So the updated code would look like this:
$q = htmlspecialchars($this->request->params['named']['q']);
// go on with searching for nodes on paginate-method

How can I do a complex IF statement in visualforce?

I'm totally new to this, the task has been thrown at me as important and I've never done anything like this before. I have been given a template containing roughly this:
<apex:column headervalue="Amount"><c2g:CODAFormatterController number="{!IF([some condition],[something],[something else])}"/></apex:column>
I've replaced the statements with condition/something/something else
is there a way to use a function as you'd do in javascript, so something like
number="getNumber(x);"
or do I have to chain some IF statements together somehow? Is there an IF...ELSE?
I don't know what a CODAFormatterController is as it returned 0 results on google.
Any advice would help, I'm afraid I've been thrown in at the deep end here!
The VForce inlines are functional, they must ultimately return a value, be that a simple value or an invocation point for a piece of server side code. They do not support imperative coding and they are being resolved server-side (long before JS comes into play). in that regard the IF(condition,valuetrue,valuefalse) is an equivalent to IF..THEN..ELSE..ENDIF
You are off course free to chain any number of functions provided there is no type mismatch, meaning your valuetrue could itself be a function, including being an IF function itself.
Usually when people encounter these kind of problems there is always a workaround by using a slightly different approach. It all depends on what you are trying to do here...
I stumbled upon this question while doing some work myself on visualforce pages. Anyway, if anybody else sees this question they should know that there's no need to use the complicated nested IF statements, now there is a CASE function available in Salesforce.
Documentation - https://developer.salesforce.com/docs/atlas.en-us.198.0.pages.meta/pages/pages_variables_functions.htm
{!CASE(Opportunity.StageName,
"Prospecting", "1",
"Needs Analysis", "2",
"Proposal/Price Quote", "3",
"default val")} <!-- the last one returns if none of the previous results matched -->

Resources