bUnit: Check for attribute addition - bunit

Here is the code where dynamicValue might be null, that is causing attribute not to be included in the output HTML:
<div data-cell-state="#dynamicValue"></div>
Test:
var diffs = cut.GetChangesSinceFirstRender();
diffs.ShouldHaveChanges(
diff => diff.ShouldBeAddition("div[data-cell-state]")
);
Error message:
Message: 
Bunit.DiffChangeAssertException : The change was not an addition.
Actual change: Added
Expected change: Added
Am I doing anything wrong here?

Related

Equivalent of Platform::IBoxArray in C++/WinRT

I am currently porting an UWP application from C++/CX to C++/WinRT. I encountered a safe_cast<Platform::IBoxArray<byte>^>(data) where data is of type Windows::Foundation::IInspectable ^.
I know that the safe_cast is represented by the as<T> method, and I know there are functions for boxing (winrt::box_value) and unboxing (winrt::unbox_value) in WinRT/C++.
However, I need to know the equivalent of Platform::IBoxArray in order to perform the cast (QueryInterface). According to https://learn.microsoft.com/de-de/cpp/cppcx/platform-iboxarray-interface?view=vs-2017, IBoxArray is the C++/CX equivalent of Windows::Foundation::IReferenceArray, but there is no winrt::Windows::Foundation::IReferenceArray...
Update for nackground: What I am trying to achieve is retrieving the view transform attached by the HoloLens to every Media Foundation sample from its camera. My code is based on https://github.com/Microsoft/HoloLensForCV, and I got really everything working except for this last step. The problem is located around this piece of code:
static const GUID MF_EXTENSION_VIEW_TRANSFORM = {
0x4e251fa4, 0x830f, 0x4770, 0x85, 0x9a, 0x4b, 0x8d, 0x99, 0xaa, 0x80, 0x9b
};
// ...
// In the event handler, which receives const winrt::Windows::Media::Capture::Frames::MediaFrameReader& sender:
auto frame = sender.TryAcquireLatestFrame();
// ...
if (frame.Properties().HasKey(MF_EXTENSION_VIEW_TRANSFORM)) {
auto /* IInspectable */ userData = frame.Properties().Lookup(MF_EXTENSION_VIEW_TRANSFORM);
// Now I would have to do the following:
// auto userBytes = safe_cast<Platform::IBoxArray<Byte> ^>(userData)->Value;
//viewTransform = *reinterpret_cast<float4x4 *>(userBytes.Data);
}
I'm also working on porting some code from HoloLensForCV to C++/WinRT. I came up with the following solution for a very similar case (but not the exact same line of code you ask about):
auto user_data = source.Info().Properties().Lookup(c_MF_MT_USER_DATA); // type documented as 'array of bytes'
auto source_name = user_data.as<Windows::Foundation::IReferenceArray<std::uint8_t>>(); // Trial and error to get the right specialization of IReferenceArray
winrt::com_array<std::uint8_t> arr;
source_name.GetUInt8Array(arr);
winrt::hstring source_name_str{ reinterpret_cast<wchar_t*>(arr.data()) };
Specifically, you can replace the safe_cast with .as<Windows::Foundation::IReferenceArray<std::uint8_t> for a boxed array of bytes. Then, I suspect doing the same cast as me (except to float4x4* instead of wchar_t*) will work for you.
The /ZW flag is not required for my example above.
I can't believe that actually worked, but using information from https://learn.microsoft.com/de-de/windows/uwp/cpp-and-winrt-apis/interop-winrt-cx, I came up with the following solution:
Enable "Consume Windows Runtime Extension" via /ZW and use the following conversion:
auto abi = reinterpret_cast<Platform::Object ^>(winrt::get_abi(userData));
auto userBytes = safe_cast<Platform::IBoxArray<byte> ^>(abi)->Value;
viewTransform = *reinterpret_cast<float4x4 *>(userBytes->Data);
Unfortunately, the solution has the drawback of generating
warning C4447: 'main' signature found without threading model. Consider using 'int main(Platform::Array^ args)'.
But for now, I can live with it ...

Customize protractor-html-screenshot-reporter

I'm generating an HTML report using protractor-html-screenshot-reporter.
I get false/true under the Passed column but I want Passed/Failed instead.
Expected - Failed(in red) or Passed(in green)
Actual - False(in red) or True(in green)
Code Snippet -
function defaultMetaDataBuilder(spec, descriptions, results, capabilities) {
var metaData = {
description: descriptions.join(' ')
, passed: results.passed()
, os: capabilities.caps_.platform
, browser: {
name: capabilities.caps_.browserName
, version: capabilities.caps_.version
}
, message: ''
}
If I replace passed: results.passed() by this code -
passed: results.passed() ? 'Passed' : 'Failed'.
I get Passed/Failed instead of True/False but Failed also comes in Green.
How should I handle this scenario. Any suggestions are always welcome
You have to alter how the page is rendered. Looking at source code for protractor-html-screenshot-reporter I can see that the page is fully created in javascript file.
Go to this library source code to jsonparser.js(protractor-html-screenshot-reporter/lib/jsonparser.js) and modify function generateHTML(data). Currently it looks at data.passed to see if this boolean is true or false. Based on that it generates color and prints this value to the column. You want to edit this line to something like this:
str += '<td class="status-col" style="color:#fff;background-color: '+ bgColor+'">' + (data.passed ? "Passed" : "Failed") + '</td>';
Personally if you expect to modify this page even more, I would advice you to move this code into html page instead of generating it inside javascript file.

unable to insert html code inside filter?

Angualr JS code:
$scope.rupee = $filter('currency')($scope.dols * 67.33, 'INR', 3);
I am trying to insert html code inside this filter. That is instead of 'INR', I wish to get ₹ symbol. Please help me to solve this. And the problem is not getting the ₹ through filter. Instead of 'INR', I want to use &#8377 but it's not rendering as I expected.
html code:
<div>{{rupee}}</div>
Modify your statement to
$scope.rupee = $filter('currency')($scope.dols * 67.33, '\u20B9', 3);
As you asked, "Can we write HTML code inside symbolFormat parameter?"
Answer will be below:
It takes a string parameter, so whatever string you are providing, it will be used to apply as currency symbol
For reference you can check Here
You can try like this:
{{ currency_expression | currency : symbol : fractionSize}}
$scope.rupee = $filter('currency')($scope.dols * 67.33, '₹', 3);
See all use cases (currency symbol & sign - in controller & directly on view):
<div ng-app ng-controller="RupeeCtrl">
<b>From controller with sign</b><br/>
{{rupeeSign}}
<br/><br/>
<b>From controller with code</b><br/>
{{rupeeCode}}
<br/><br/>
<b>From view</b><br/>
{{ price | currency:'₹'}}
</div>
function RupeeCtrl($scope, $filter) {
$scope.price = 75.255;
$scope.rupeeSign = $filter('currency')($scope.price, '₹', 3);
$scope.rupeeCode = $filter('currency')($scope.price, '\u20B9', 3);
}
JSFiddle
Mixed with answer from #Romesh Jain
This looks like a duplicate question to this: How to get specific currency symbol(rupee symbol in my case) in angular js instead of the default one (dollar $ symbol)
Just use this ASCII code for the Rupee symbol: ₹
See the ASCII code here: http://www.fileformat.info/info/unicode/char/20b9/index.htm

Hovertool Bokeh "Cannot read property"

My problem is that in Chrome, when I have my cursor on my histogram hover my data, I have this error :
Uncaught TypeError: Cannot read property '0'
There is my code :
hist, edges = np.histogram(data,bins=3000)
plot = quad(
top=hist,
bottom=0,
left=edges[:-1],
right=edges[1:],
fill_color="#036564",
line_color="#033649",
tools="pan,wheel_zoom,box_zoom,reset, hover",
x_range=[-0.5,3.5],
plot_width=1100,
title="",
)
hover = plot.select(dict(type=HoverTool))
hover.tooltips = [('index','$index')]
resources = Resources("inline")
plot_script, plot_div = components(plot, resources)
html_script = mark_safe(encode_utf8(plot_script))
html_div = mark_safe(encode_utf8(plot_div))
figure()
return html_script, html_div
"data" is a array like this :
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.24,1,1.32,1,2,3]
I tried to add a "source" in the quad, changed the figure, changed my code for the one on the documentation but I still have my error.
For information, everything is working very well, except the hover tool.
Indeed, in the "hover box" I want another informations then just "index", but it's just for testing.
Thanks for reading !
Sorry I missed this earlier. You have uncovered a small bug with the hover tool that is particular to quad glyphs. In the mean time you can add hover.snap_to_data = False to get it to work.
Here is a GH issue you can track for the full solution:
https://github.com/bokeh/bokeh/issues/1644
A fix should be in the 0.7.1 release next Monday.
Also BTW, you are using a deprecated API. You should now write code like:
p = figure(...)
p.quad(...)

HTML Codes in CakePHP $html->link function

This code
$html->link(" »", '/events/view/'.$event['Event']['id']), array('escape'=>false,'class'=>'more') )
Outputs
&raquo;
instead of >>
Any idea?
basically you have syntax error instead you should have:
$this->Html->link(" »", '/events/view/'.$event['Event']['id'], array('escape'=>false,'class'=>'more') );
At least that's what I see.