Unit Tests - Unable to create component with mat-autocomplete - karma-jasmine

I have a reactive form component that is built on 2 mat-autocomplete form control fields and a submit.
Basically, you search a keyword, and autocomplete functionality of the angular material (ng9) lists down a list of matching entries before you can select one.
Once you have selected you click the form group submits. The implementation is working fine, I have been trying hard to write unit tests for this component, however, I am unable to access fields because TestBed is unable to mock the component even with all the injected dependencies.
I have imported mat-AutoCompleteModule in the TestBed configurations before each. I honestly have not found any relevant links that I can refer to. I have a similar reactive form with two form control fields unit tested properly, the only difference here is that I am using Mat-Autocomplete in this form

Related

'Global' parent selector: limiting scope of any selector to a certain parent

Im looking for an option to limit the scope of every selector to a parent selector.
Am trying to abstract away a lot of the (internal implementation) details of our WebApp for the testers that will actually write the UI tests.
If our application shows a Modal dialog (just a div tag that lies op top of all the other content and prevents interacting with the underlying content), I'd like to restrict all Selectors used in the tests written by testers to be automatically limited to the scope of this Modal Dialog div.
Our new client UI framework uses just divs for Modal Dialogs, while our previous client UI framework used an embedded iframe for each modal dialog. In the iframe scenario, we'd call .switchToIframe(), which would effectively limited all selectors used in tests to this iframe.
Am trying to achieve something similar for the new client framework that uses just divs
I'm not sure you can limit the scope of the DOM like that, but you could build out a Page Object Model (POM) design that would only intelliSense existing locators from their respected repos. This way, if they begin typing a locator and it doesn't pop up, a hint that they aren't in the 'scope' of the modal.

Custom Search and Filter functionality VueJS

I was hoping I could get some feedback on something I'm working on. I'm building an application that is essentially a bunch of data tables. Part of my requirement is not to use any additional frameworks (vuetify) or any type of store (vuex).
Currently, my application is constructed as follows:
API call upon creation of app
That data get's passed into a component where I would like to do all my searching/filtering
From there the next component is built specifically for Pagination
Then to the component that builds the data tables.
My question is, since I have this top down approach, how do I build both the search and filter functionality to where I don't have to pass anything back up to the parent components?
I am using scoped slots to pass/inject data into child components. My first thought was that I would have a computed property that returns an array in the control component and then pass that down to the pagination component, which works, but how do I also use that same array if I want to be able to filter results and also search filtered and none filtered items? Essentially to be able to mock the functionality of some of the Vuetify tables.
I assume you don't want to pass data/prop-drill between 3 component layers?
You can use provide/inject.
You can provide a "setArrayData" method to the child components (2 and 3 levels deep) and also provide "arrayData" data property.
You can also an event bus (see vue docs). In Vue 2 an event bus is built in, in Vue 3 it's not.

Vuejs Hide/Show Elements refreshes when Routes change

I have been developing a Vue project and something caught my attention today. I used checkboxes with some sytling (I use them as toggle switches) throughout the project and thanks to these elements, I show or hide some elements and components. Toggle elements control specific data within each component. When the data istrue, some elements are displayed on the page and when false, they are hidden. What I noticed today is a little interesting. There is probably a simple solution, but although I have been searching the internet for a while, I haven't found a solution yet.
Here is the thing;
Let's say I am at the About page of my project. I used my toggle switches and now some of my elements and some sub components are displaying in the About.vue. Then I go and visit my Services.vue page and showing and hiding some elements and sub components as well. By the way, almost all of these pages have forms and I save these forms to local storage. When I return to My About page from my Services page, I see that the elements I activated have been restored. In other words, each component welcomes me with its default state when it is returned from another component. What I want to see is, If I go and check some checkboxes to show some element, No matter how long I roam between other routes, I want those elements to remain visible or hidden when I come back. For example, a toggle element must be activated to write a username and password on a component. After activating the toggle element, the user types the username and password and clicks the Save button. Then he continues to browse many areas of the project and when he returns, he sees that the toggle element is inactive and the username and password are not entered. I don't want it to be that way. How do I fix this?
you can use vuex for solved this problem.
https://vuex.vuejs.org/
Vuex is a state management pattern + library for Vue.js applications. It serves as a centralized store for all the components in an application, with rules ensuring that the state can only be mutated in a predictable fashion. It also integrates with Vue's official devtools extension (opens new window)to provide advanced features such as zero-config time-travel debugging and state snapshot export / import.

How to utilize Angular 4 components when creating Leaflet Extended Control?

I am working now a few weeks with Leaflet and Angular CLI on a project involving geo map and in-door maps (Leaflet custom maps).
The application is conceptually very simple. I have to provide the user with a list of in-door locations (e.g. room) in a form of a simple location tree table, where, on user click, a new in-door map must be called. Also, I have to make a custom search box with a few filtering options for searching through sets of structured data and plotting the data on the maps in a form of Leaflet markers.
The question I have is the following: What would be the best way to implement the 2 above mentioned controls (location tree and search box), taking into account the nature of the app and the technology I am working with (Leaflet library and Angular CLI (angular 4.x))?
From my point of view, I can see 2 options by now:
1) Create the controls (location tree and search box with filters) using Leaflet L.control.extended (negative(-): seems to me that I have to statically type html in the L.control.extended 'onAdd' function in order to create the controls -> no possible Angular 4 templating engine advantages)
2) Create the controls using Angular 4 Component's templates, in Angular 4 fashion, neglecting the very existence of Leaflet L.control.extended (negative: It seems to me that this option unnecessary complicates the app + intuitively seems wrong since Leaflet extended control seems 'as born' for such types of problems)
It would be great if I could dynamically nest Angular component inside Leaflet custom control somehow. Any suggestions?

Attach/Render RactiveJS component outside of template

I've got an existing SPA that was developed using nested RactiveJS components. Which is great, and offers a ton of flexibility throughout the entire app. Currently I attempting to add in client side routing support using page. My navigation switches out high-level components using simple {{#visible}}{{/visible}} template markup on each component. This is a little troublesome in its current state as it always kicks off a re-render whenever the high-level component becomes visible again.
Is there a way to render a component, for example, called widget, without using the
<widget></widget>
method? I've already "registered" the component with the parent, but obviously when constructing it by means of
new App.components.widget
I am able to control how/when it's rendered/inserted/detached, but lose the recognition in the application's component hierarchy.
There is insert exactly for that. You don't even need to "register" it to the component you plan to put it to. You can use the different find* methods or nodes to easily retrieve a reference of your planned container element.
var instance = new YourDetachedWidget({ ... });
instance.insert('#your-container'); // This could be a node, selector or jQuery object