Enzyme - how to test initial state of inner component? - mocha.js

I am mounting a component with another component inside it like so:
const wrapper = mount(<IntlProvider><SignUpForm /></IntlProvider>);
The component <SignUpForm /> should have an initial state of {errors: {}}. I am using the following assertion:
expect(wrapper.find(SignUpForm).state('errors')).to.equal({});
but I am receiving the following error when running the test:
Error: ReactWrapper::state() can only be called on the root
So, how do I acces the state of the <SignUpForm /> component?

Well, you can't do that using enzyme (as far as I know), but there is a really good reason for that - unit tests should test some separated part of the application (never two parts in one test). This Provider is really a component, so you try to test child component mounting parent component...
The same issue is when you have components connected to the redux store, you can wrap them in Provider, but that is not the case. You should separate component from wrapped version, and then test only the component with isolation from third parties/parent/siblings.
I export component and connected component from one file (two exports, one named, one default) and in tests I only import named (NOT connected) component. I don't really wan't to test redux provider ;)
//component.jsx
export function MyComp() {}
export default connect()(MyComp)
//component.test.js
import {MyComp} from "./component"
//another component
import MyComp from "./component"

Related

Configure subnetwork for vertex ai pipeline component

I have a vertex ai pipeline component that needs to connect to a database. This database exists in a VPC network. Currently my component is failing because it is not able to connect to the database, but I believe I can get it to work if I can configure the component to use the subnetwork.
How do I configure the workerPoolSpecs of the component to use the subnetwork?
I was hoping I could do something like that:
preprocess_data_op = component_store.load_component('org/ml_engine/preprocess')
#dsl.pipeline(name="test-pipeline-vertex-ai")
def pipeline(project_id: str, some_param: str):
preprocess_data_op(
project_id=project_id,
my_param=some_param,
subnetwork_uri="projects/xxxxxxxxx/global/networks/data",
).set_display_name("Preprocess data")
However the param is not there, and i get
TypeError: Preprocess() got an unexpected keyword argument 'subnetwork_uri'
How do I define the subnetwork for the component?
From Google docs, There is no mention of how you can run a specific component on a subnetwork.
However, it is possible to run the entire pipeline in a subnetwork by passing in the subnetwork as part of the job submit api.
job.submit(service_account=SERVICE_ACCOUNT, network=NETWORK)

How can I import Bootstrap-Table into a Laravel/Vue Project?

I'm trying to implement Bootstrap-Table (https://github.com/wenzhixin/bootstrap-table) inside my Laravel and Vue.js project, but something is wrong.
I tried all ways of importing I could think of (inside app.js, app.blade, bootstrap.js, even vite.config.js) and all of them failed.
What I've Tried:
Inside app.js
import 'bootstrap-table/dist/bootstrap-table.js'
import bootstrapTable from 'bootstrap-table/dist/bootstrap-table.js';
import BootstrapTable from 'bootstrap-table/dist/bootstrap-table-vue.esm.js'
app.component('BootstrapTable', BootstrapTable);
These normally lead to
Could not find a declaration file for module 'bootstrap-table/dist/bootstrap-table.js'.
The errors I'm getting are:
Uncaught TypeError: Cannot set properties of undefined (setting 'BootstrapTable')
at bootstrap-table.min.js:10:132646
at bootstrap-table.min.js:10:233
at bootstrap-table.min.js:10:245
bootstrap-table-vue.min.js:10 Uncaught TypeError: Cannot read properties of undefined (reading 'fn')
at bootstrap-table-vue.min.js:10:1806
at bootstrap-table-vue.min.js:10:1905
at bootstrap-table-vue.min.js:10:205
at bootstrap-table-vue.min.js:10:209
There are some scripts/links necessary to run, and I think I'm also confused about this and where it should go.
For example:
<script src="https://unpkg.com/bootstrap-table#1.21.0/dist/bootstrap-table.min.js"></script>
My objective:
I want to render the table inside a Vue.component, with some data I get from axios. So I figured I couldn't put the scripts inside the component itself. I need to make the table component (or a way to render it) global.
Please help me get this right

WrappedAPIView.__name__ = func.__name__ . AttributeError: 'dict' object has no attribute '__name__'

I am in a little bit of a pickle.
I have multiple decorators wrapping my view functions. I want to test that view function using pytest and this means the decorators will also be executed. Now, in some of those decorators, I am making API calls to an external service and I do not want to make those API calls while running my test, what I am doing instead is to mock the response from those decorators. When I ran the test I got AttributeError: 'dict' object has no attribute '__name__' and pytest is pointing to the decorators.py file in the djangorestframework package as the source of the error. Any idea what I am doing wrong?
Views.py file
#api_view(['POST'])
#DecoratorClass.decorator_one
#DecoratorClass.decorator_two
#DecoratorClass.decorator_three
#DecoratorClass.decorator_four
#DecoratorClass.decorator_five
#DecoratorClass.decorator_six
#DecoratorClass.decorator_seven
def my_view_fun(request):
my_data = TenantService.create_tenant(request)
return ResponseManager.handle_response(message="sucessful", data=my_data.data, status=201)
This works perfectly with manual testing, I only get this problem when I am running the test with pytest.
I am making the external API calls in decorators three, four and five.
TL;DR:
How can I handle the decorators wrapped around a view function when testing that view function in a situation where some of those decorators are making external API calls which should ideally be mocked in a test.

Omnet/Inet : how to access class/submodules to get variables values

in my simulation there is a mobile node composed by the following components from the inet framework:
Now I am working on the UdpApp which is UDPVideoStreamCli.cc which is also given by inet framework as one of example udp application.
Now as you can see from the image I had to access to the lisp module (which is an instance of LispRouting.cc) because I have to read some values or call some public methods of that class...how can I do that? All I know is that I have to start from
getParentModule()->getSubmodule();
but then I don't know how to go on...can you help?
(LispRouting *)getParentModule()->getSubmodule("lisp")
will do the trick. Be sure to check if the returned pointer is not null.
Generally this is bad design as it hard-codes the name and the relative position of the LispRouting module. Any change in naming/architecture will cause crashes.
A proper design would be to create a parameter that specifies the name/path of the lisp submodule (with default value) and then use
#include "inet/common/ModuleAccess.h"
...
LispRouting *lr = getModuleFromPar<LispRouting>(par("lispModule"), this);
and then add a parameter to the module's NED file:
string lispModule = default("^.lisp");
meaning the default place where you can find the lisp module is: go one level up and then find the submodule named "lisp". This is a much better pattern, because the user can later reconfigure the name/placement of the lisp module without breaking the code.

MX components in a spark container are null

I have a spark Group container, but all its sub-components are MX components. I need to perform some operations on the MX components when the container is initialized. I tried to put the operations in the commitProperties function, but the sub-components are still null there. I tried moving them to the childrenCreated function, but they are still null. What function can I use for working with the components? Thanks.
protected override function commitProperties():void
{
var defaultFinishedDate:Date=new Date();
defaultFinishedDate.date--;
includeFinishedDateSelector.selectedDate=defaultFinishedDate;
}
The includeFinishDateSelector is null in this function, and thus I'm getting a run-time error. It's defined as:
<mx:DateField id="includeFinishedDateSelector" formatString="{GeneralUtils.DATE_FORMAT_STRING}"
enabled="{includeFinishedCheckBox.selected}" width="18%"/>
And as I said, its container is a spark Group container.
I would have expected the Flex life cycle method createChildren() is where you could do your operations. But you'd want to only do this work AFTER the super class has executed createChildren():
override protected function createChildren():void
{
super.createChildren();
// now do your thing
}
Another thing is that in the commitProperties() method you show above, you are not calling the super class method. That is a big no-no. The commitProperties() method is invoked by the Flex framework AFTER createChildren(). So theoretically, your approach with commitProperties() should have worked -- you might go back and put a call to super.commitProperties() in that code and give it another go.
Finally, if none of this works it may be due to the way Flex instantiates the children objects in MXML containers. So an approach that will definitely work is to listen for Flex life cycle events from the Group container. When the creationComplete event is dispatched by the Group, it is guaranteed that all of the children exist.
You can also try to wrap your code in callLater, it will essentially queue it to run on the next pass.
So in creationComplete try the following:
callLater(function():*{
var defaultFinishedDate:Date=new Date();
defaultFinishedDate.date--;
includeFinishedDateSelector.selectedDate=defaultFinishedDate;
});
It's not very elegant, but it should work.
Thanks to whomever tried to help. In the end I solved this by changing the direct container (parent) of the MX components to a spark container (it was originally an MX container in a spark container).

Resources