Vue test-utils: Trigger right-click event on the Wrapper - unit-testing

import { mount } from '#vue/test-utils'
import sinon from 'sinon'
import Foo from './Foo'
const clickHandler = sinon.stub()
const wrapper = mount(Foo, {
propsData: { clickHandler }
})
//click works
wrapper.trigger('click')
// right click **doesn't** work
wrapper.trigger('click.right')
// contextmenu **doesn't** work either
wrapper.trigger('contextmenu')
expect(clickHandler.called).toBe(true)
In the above code i was able to trigger mouse click but not able to trigger mouse right-click. I have attempted to trigger the required with 'click.right' and 'contextmenu' without any luck.
any ideas on how to trigger right click. There is no reference of this in the official documentation.

Indeed...wrapper.trigger('contextmenu') works. There was a problem with my code I assumed right click was not getting triggered
#ittus thanks for the link https://github.com/ittus/VueJS-Training/blob/master/vue-test-utils/test.js
Hope this helps someone as triggering right click is not found in official docs

Related

Can't catch bluetooth headset button click event in swiftui 2.0

I am trying to simply execute code on a click of a bluetooth headset button in a SwiftUI 2.0 app, but after trying many different codes, nothing have worked... Does someone have solved this issue?
Based on apple docs and some answer I found on StackOverflow (https://stackoverflow.com/a/58249502/13207818), I tried this simple code
import SwiftUI
import MediaPlayer
struct ContentView: View {
init() {
MPRemoteCommandCenter.shared().pauseCommand.isEnabled = true
MPRemoteCommandCenter.shared().pauseCommand.addTarget(handler: { (event) in
print("Pause")
return MPRemoteCommandHandlerStatus.success
})
MPRemoteCommandCenter.shared().playCommand.isEnabled = true
MPRemoteCommandCenter.shared().playCommand.addTarget(handler: { (event) in
print("Play")
return MPRemoteCommandHandlerStatus.success
})
MPRemoteCommandCenter.shared().togglePlayPauseCommand.addTarget (handler: { (event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus in
// middle button (toggle/pause) is clicked
print("event:", event.command)
return .success
})
}
var body: some View {
Text("Hello World")
}
}
Of course Enabling Background Audio as per Apple doc
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
Even tried to activate my app audio session:
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, mode: .default, options: [.duckOthers, .allowBluetooth, .allowBluetoothA2DP])
try AVAudioSession.sharedInstance().setActive(true, options: .notifyOthersOnDeactivation)
print("audioSession is Active")
} catch {
print("audioSession properties weren't set because of an error.")
print(error)
}
But everything failed...
Would someone know what I am doing wrong or would have faced such issue with swiftUI 2.0?
Thank in advance for your support
In general you shouldn’t do actions in the initializers of views. Since they represent the state of the UI, not the actual UI they could be broken down and created again whenever SwiftUI thinks it needs to.
Im not at my pc but You can probably get a Publisher for the pause button which you can bind to a view with onReceive
Finally, I got a solution for my issue.
I don't know how it works really behind but the audio focus wasn't on my app. So I've just played a silent sound for a second and I could play properly with my play/pause button. I know that it's not a proper solution, but it works!
This reminds me of a similar bug on the galaxy s8...
If I find a better one, I'll keep you posted.

How to allow a button that creates a new object in SwiftUI from not making an object on reload?

So I'm making a button for a "New Note" in Swift UI similar to the Apple Notes app.
Right now my "New Button" is a "Navigation Link" like so:
NavigationLink(
destination: EditorView(makeNewNote())
) {
Text("New")
}
Unfortunately—this triggers my app to create a new note every time the view loaded. :(
:/
I've been looking for a way to initate a segue on button push but I'm not finding success on this yet.
When I tried a modal—I found myself having the same problem
Button("New") {
self.isNew = true
}.sheet(isPresented: $isNew, content: {
EditorView(makeNewNote())
})
I'm wondering what the best way to approach this would be.
Having no success :(
Edit:
I referred to this and the documentation but I haven’t found a way to segue via a button push which would be ideal. (The function dosent get triggered in the closure :)
https://www.hackingwithswift.com/quick-start/swiftui/how-to-push-a-new-view-onto-a-
Also...if you were curious what makeNewButton() does—it basically inserts a new Core Data object into my app’s managed context.
I'm not entirely sure, but it kinda sounds like to me your problem lies in your model. Because each time your View loads it calls the makeNewButton() function right?
Maybe you can fix the problem by displaying the "new note" view and having an extra "Save" button that only makes changes to your model once it's triggered.
Alternatively, you could use context.rollback() to discard changes. Also, check out this Project. It's Beta 4 but works just the same and imo is a good example how to use CoreData with SwiftUI. :)

Differences beetween ModalController and NavController

I need to understand the differences between ModalController and NavController in Ionic 2. When should I choose NavController and when to choose ModalController?
In the ModalController doc:
A modal uses the NavController to present itself in the root nav
stack. It is added to the stack similar to how NavController.push
works.
So we can say, in mechanism, they are the same. Lets talk about UX.
A Modal is a content pane that goes over the user's current page
A modal actually go over the page. It is like a popup. In small device, it take all the space of screen so you can not realize the diffentce from it and page. But if you test it in tablet like a ipad you will see the modal just take a part of screen and the current page is behind it.(Image description below).
What should be used?
In most case, you can use modal or page base on what you prefer but to ensure the properly UX modal should be used in case editing, making choice or getting information, other case page should be used
The ModalController is used to create and present modals. Modals are commonly used for galleries, edit forms, and other content that should be push on top of the current page.
import { ModalController } from 'ionic-angular';
import { Page1 } from './pages';
constructor(private modalCtrl: ModalController) {}
let modal = this.modalCtrl.create(Page1);
modal.present();
modal.onDidDismiss(() => {
// Action done after dismissing the modal.
});
The NavController is used for navigation functionality (think about Tabs or just basic page navigation). This controller also contains your navigation history.
import { NavController } from 'ionic-angular';
import { Page1 } from './pages';
constructor(private navCtrl: NavController) {
}
this.navCtrl.push(Page1);
So there are two different approaches to present the desired page. For more information/options/methods please ready the provided links, containing all available features available on the Modal- and NavController components.

Issue with loading on pushed page

I have some flow on my app that, in some moment, I push a page to the stack and, on that page, I call a loading dialog for some data load. The problem is that the loading dialog didn't showed up. Then I realized that when I got back to the previous page, the loading was there, under my page that was being showed up. If in my navigation flow, instead of nav.push I use nav.setRoot, it works fine, so I think it's some glitch with that navigation stack. I really wanna use nav.pushcause it makes more sense for my app.
Any ideas?
EDIT:
my function that call the page:
onViewUnidade(unidade){
if (unidade.tipo == "Unidade Consumidora"){
this.nav.push(UnidadeConsumidoraPage, unidade);
}else if (unidade.tipo == "Usina"){
this.nav.push(UsinaPage, unidade);
}
}
my onInit method:
ngOnInit(){
console.log("show loading");
this.loading = this.loadingCtrl.create({
content: "some message"
});
this.loading.present();
}
My console.log executes, and I even didn't dismissed it, so I could see it correctly. The Loading and LoadingController are properly imported and injected.
EDIT 2:
I noticed that issue only happens when the page that redirects to my last page with the loading is a modal. If I change it for a regular page, it works correctly. Also, tried to dismiss the modal and popToRoot before navigate to new page... but still gotting same issue. Any ideas?
got my answer on documentation:
Instead of injecting navigation controller, when you wanted to navigate from an overlay component (popover, modal, alert, etc), we have to get a reference of the root NavController in our app, using the getRootNav() method:
this.appCtrl.getRootNav().push(SecondPage);
Hope this helps who got the same problem!
Have a look at LoadingOptions
export interface LoadingOptions {
spinner?: string;
content?: string;
cssClass?: string;
showBackdrop?: boolean;
dismissOnPageChange?: boolean;
delay?: number;
duration?: number;
}
You can set dismissOnPageChange(to true). Make sure you dismiss the loading dialog or set duration.

Need help catching GwtQuery Datepicker select event

I want to execute some code when a date is selected using the Datepicker widget that is packaged with the GWT Query UI plug-in.
My attempt is below. The widget appears on the screen, and is apparently operational; but the callback function does not fire. Can you see where I have gone wrong?
$("#pick").as(Ui).datepicker().bind(Datepicker.Event.onSelect, new Function() {
public boolean f(Event e, Object data) {
Window.alert("Date selected");
return true;
}
});
Working with the GwtQuery developer by email, I arrived at a work-around for what appears to be a bug.