Testing Google Maps API with Mocha in React - reactjs

I would like to write tests for the Google Maps API using Mocha and Chai in React.
How would I go about writing a test for the following features?
When I hover over a div, the map's center should change.
When I hover over another div, a special icon should appear on the map.
Again, I am only looking to implement tests for these features. I know it is not the proper order to do it, but I already wrote functioning code for all of them ;)

Related

A way to precompile a single react component for a react native webview

As the title suggests I am looking for a way to precompile a single or set of normal react components to plain html/js so I can inject this into my webview.
Since I am open to any solution I will give you some background on what I am trying to achieve. We are building a react native app and need to use Leafleft maps by customer requirement. Since Leaflet is not available for react native straight away we are looking for a way to implement it. Currently we are looking at compiling the leaflet react code to normal html/js and inject this into a webview. If there are other/ better ways by all means suggest them!
Thanks for your time 😄

How to use Globe.gl React component in React Native?

I asked a similar request in the Git Repo as well here, https://github.com/vasturiano/react-globe.gl.
I have an app that uses the react component exported by this project. It depends on three.js and WebGL to work. It is an extension of this repo by the same author, https://github.com/vasturiano/globe.gl.
I made a beautiful web app with these libraries and all works as expected, on the web, but I want to extend this to a mobile app built on react native as well.
I have tried a simple port but get an error from the CSS2DRenderer trying to access the document object which clearly doesn't exist on a mobile app.
I tried using expo GLView here, but could not for the life me figure out where to start on the context creation function to be able to port the three globe to it.
My question is, based on the Repo's I have shared above, what is the best approach to implementing the Globe in React Native?
I would also take any alternatives that I could do drag/zoom Globe with dynamic plot points and interactive functions (click basically).
For a quick setup to recreate the project, I am working an out of the box react native application setup
npm i react-globe.gl
Pop below component inside of a View in the app.js and import the Globe from above library. Provide an empty array for hexBinPointsData
<Globe
globeImageUrl="//unpkg.com/three-globe/example/img/earth-night.jpg"
bumpImageUrl="//unpkg.com/three-globe/example/img/earth-topology.png"
backgroundImageUrl="//unpkg.com/three-globe/example/img/night-sky.png"
hexBinPointsData={plotData}
hexAltitude={0.1}
hexBinResolution={4}
hexBinMerge={false}
/>
Expected error: Document variable cannot be found. In the CSS2DRenderer.js file.
Any help would be appreciated!

How to pass data from stencil component to other component in react

I have created one search component using stencil and I'm integrating this stencil codebase with my react application via cdn link. I'm displaying the search component(which was created in stencil) as below in my react codebase :
<custom-search placeholder="Search"></custom-search>
The search component contains a search icon. I need to pass the text in search input field to my react code on click of this icon. How can this be achieved?
Unfortunately I haven't integrate Stencil JS component with React, but passing string data to web component should be working without too much hassle. Do you know if your React app can properly recognize your custom-search component? If not, then you might want to take a look at a link to Stencil JS official document of integrating Stencil JS component to React and make sure component get properly loaded and integrated.
If you know for sure you load the component then not sure why your placeholder is not set within your component - it is just a string after all. Maybe post the custom-search component code, as there might be issue with that (i.e. component lifecycle event you are using might not be doing what you expect to do)
Could you clarify the actual problem, please? :)
Does the component not get rendered, or are you unable to achieve communication from custom-search to the React app?
If the latter is the case, you might want to implement a Custom Event on the Stencil component, to communicate changes back to the consuming app.
As #tomokat mentioned, you should follow the official Stencil React integration docs. This is required, since React cannot handle Custom Events natively, and requires some help from the dev.
Edit: Sorry, I got confused by the first answer. Your title is quite clear, though. If you can show some example code of the component and the React integration, we could probably help in a better way.

Can custom Material-UI components be tested with React Testing Library?

I'm evaluating widget toolkits for a new project, and I want to be sure that I can write unit tests for them first. So I've created a simple component using Material-UI based on react-autosuggest using axios to query a simple API. The component works just fine, but I can't seem to get it to work with React Testing Library.
The test is failing with this: "Cannot read property 'px' of undefined"
It almost seems as though Material-UI isn't loading fully, so the component can't be tested until it is. I have no previous experience with unit testing React components, but shouldn't it load in all the dependencies at the top of my component when it renders?
Here's a demo of my failure in Code Sandbox:
https://codesandbox.io/s/testing-material-ui-problem-ndn9f

Migrate Android webview to React-Native-Webview

I have a Hybrid Android App which uses Android WebView for rendering the Web Pages.
I have Wiziwig Editor (which is written in HTML, javascript, and css). I am using Webkit Interface for communicating between Java and JavaScript
I want to integrate React Native in my Editor. Previously I was using JavaScript models and JS functions for implementing various functionalities in the WiziWig Editor and manipulating DOM.
But its UX is not fast and appealing. Moreover, I had integrated the Twitter BloodHound Engine in Editor. Whenever the user types in the Editor the typeahead list of BloodHound Engine lags.
I am thinking of using the React Native in my Editor. With React Native I can also use the Android Native components for showing messages and other things instead of the JavaScript Models. There are also other possibilities of improvement with React Native.
I built a demo app in which, I am able to communicate between Java and Javascript code using React Native Modules.
Question
My WiziWig has so much Code already written in HTML, CSS, and plain JavaScript. In order to convert my code to React Native and using Native components for UI, it would take a lot of time.
Is there a way in which I can use my old code base in React Native and then I slowly move the code to the React Native using JSX and components.
I have seen There is Render function in React Native for Rendering the html content. But I have to write the plain JS code in JSX. Is there a fast way to do it. Because my file has already 4495 lines of Code.
Thanks in advance

Resources