-
Notifications
You must be signed in to change notification settings - Fork 2
Guide: dom-events.md #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
# Testing Key, Mouse and other DOM events | ||
# Tester le clavier, la souris et les autres événements DOM | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On utilise la graphie post 1990. Donc évèments |
||
|
||
## Trigger events | ||
## Déclencheur d'événements | ||
|
||
The `Wrapper` expose a `trigger` method. It can be used to trigger DOM events. | ||
|
||
Le `Wrapper` expose une méthode `trigger` method. Elle peut être utilisée pour déclencher des événements du DOM. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
```js | ||
const wrapper = mount(MyButton) | ||
|
||
wrapper.trigger('click') | ||
``` | ||
|
||
You should be aware, that find returns a wrapper as well. Assuming `MyComponent` contains a button, the following code clicks the button. | ||
Vous devez être au courant que la méthode find retourne un wrapper aussi. Partant du principe que `MyComponent` contient un bouton, le code suivant clique sur le bouton. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
(Tu peux PR l'original) |
||
|
||
```js | ||
const wrapper = mount(MyComponent) | ||
|
@@ -20,9 +21,9 @@ wrapper.find('button').trigger('click') | |
|
||
## Options | ||
|
||
The trigger method takes an optional `options` object. The properties in the `options` object are added to the Event. | ||
La méthode trigger prend en paramètre optionnel l'objet `options`. Les propriétés de l'objet `options` sont ajoutées à l'événement Event. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
sont ajoutées à l'évènement ou sont ajoutées à l'évènement. |
||
|
||
You can run preventDefault on the event by passing `preventDefault: true` in `options`. | ||
Vous pouvez utiliser preventDefault sur l'événement en passant `preventDefault: true` dans le paramètre `options`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
```js | ||
const wrapper = mount(MyButton) | ||
|
@@ -31,31 +32,31 @@ wrapper.trigger('click', {preventDefault: true}) | |
``` | ||
|
||
|
||
## Mouse Click Example | ||
## Exemple de clic de souris | ||
|
||
**Component under test** | ||
**Componsant à tester** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Composant |
||
|
||
```js | ||
<template> | ||
<div> | ||
<button class="yes" @click="callYes">Yes</button> | ||
<button class="no" @click="callNo">No</button> | ||
<button class="oui" @click="callOui">Oui</button> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a pris le parti de ne traduire que les chaines de caractère et les commentaire ce qui donne
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Du coup tu traduirais le |
||
<button class="non" @click="callNon">Non</button> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
</div> | ||
</template> | ||
<script> | ||
export default { | ||
name: 'YesNoComponent', | ||
name: 'OuiNonComponent', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
props: { | ||
callMe: { | ||
type: Function | ||
} | ||
}, | ||
methods: { | ||
callYes() { | ||
this.callMe('yes') | ||
callOui() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
this.callMe('oui') | ||
}, | ||
callNo() { | ||
this.callMe('no') | ||
callNon() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
this.callMe('non') | ||
} | ||
} | ||
} | ||
|
@@ -66,34 +67,34 @@ export default { | |
**Test** | ||
|
||
```js | ||
import YesNoComponent from '@/components/YesNoComponent' | ||
import OuiNonComponent from '@/components/OuiNonComponent' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
import { mount } from 'vue-test-utils' | ||
import sinon from 'sinon' | ||
|
||
describe('Click event', () => { | ||
it('Click on yes button calls our method with argument "yes"', () => { | ||
describe('Evenement click', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. describe('Évènement `click`', () => { |
||
it('Cliquer sur le bouton oui appelle notre méthode avec l argument "oui"', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const spy = sinon.spy() | ||
const wrapper = mount(YesNoComponent, { | ||
const wrapper = mount(OuiNonComponent, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
propsData: { | ||
callMe: spy | ||
} | ||
}) | ||
wrapper.find('button.yes').trigger('click') | ||
wrapper.find('button.oui').trigger('click') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. button.yes |
||
|
||
spy.should.have.been.calledWith('yes') | ||
spy.should.have.been.calledWith('oui') | ||
}) | ||
}) | ||
``` | ||
|
||
## Keyboard Example | ||
## Example de test clavier | ||
|
||
**Component under test** | ||
**Composant à tester** | ||
|
||
This component allows to increment/decrement the quantity using various keys. | ||
Ce composant permet d'incrémenter/décrémenter la quantité en utilisant différentes touches. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. incrémenter / décrémenter (avec espace entre la barre) |
||
|
||
```js | ||
<template> | ||
<input type="text" @keydown.prevent="onKeydown" v-model="quantity" /> | ||
<input type="text" @keydown.prevent="onKeydown" v-model="quantite" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. garder quantity |
||
</template> | ||
<script> | ||
const KEY_DOWN = 40 | ||
|
@@ -104,36 +105,36 @@ const CHAR_A = 65 | |
export default { | ||
data() { | ||
return { | ||
quantity: 0 | ||
quantite: 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. quantity |
||
} | ||
}, | ||
methods: { | ||
increment() { | ||
this.quantity += 1 | ||
incrementer() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. increment() |
||
this.quantite += 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this.quantity |
||
}, | ||
decrement() { | ||
this.quantity -= 1 | ||
decrementer() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remettre le FR en EN |
||
this.quantite -= 1 | ||
}, | ||
clear() { | ||
this.quantity = 0 | ||
nettoyer() { | ||
this.quantite = 0 | ||
}, | ||
onKeydown(e) { | ||
if (e.keyCode === ESCAPE) { | ||
this.clear() | ||
this.nettoyer() | ||
} | ||
if (e.keyCode === KEY_DOWN) { | ||
this.decrement() | ||
this.decrementer() | ||
} | ||
if (e.keyCode === KEY_UP) { | ||
this.increment() | ||
this.incrementer() | ||
} | ||
if (e.which === CHAR_A) { | ||
this.quantity = 13 | ||
this.quantite = 13 | ||
} | ||
} | ||
}, | ||
watch: { | ||
quantity: function (newValue) { | ||
quantite: function (newValue) { | ||
this.$emit('input', newValue) | ||
} | ||
} | ||
|
@@ -145,52 +146,52 @@ export default { | |
**Test** | ||
|
||
```js | ||
import QuantityComponent from '@/components/QuantityComponent' | ||
import QuantiteComponent from '@/components/QuantiteComponent' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
import { mount } from 'vue-test-utils' | ||
|
||
describe('Key event tests', () => { | ||
it('Quantity is zero by default', () => { | ||
const wrapper = mount(QuantityComponent) | ||
expect(wrapper.vm.quantity).to.equal(0) | ||
describe('Tests événement clavier', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. évènement |
||
it('La quantité est zéro par défaut', () => { | ||
const wrapper = mount(QuantiteComponent) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remettre en EN et le reste du code (garder en FR ce qui est dans |
||
expect(wrapper.vm.quantite).to.equal(0) | ||
}) | ||
|
||
it('Cursor up sets quantity to 1', () => { | ||
const wrapper = mount(QuantityComponent) | ||
it('La flèche du haut positionne la quantité à 1', () => { | ||
const wrapper = mount(QuantiteComponent) | ||
wrapper.trigger('keydown.up') | ||
expect(wrapper.vm.quantity).to.equal(1) | ||
expect(wrapper.vm.quantite).to.equal(1) | ||
}) | ||
|
||
it('Cursor down reduce quantity by 1', () => { | ||
const wrapper = mount(QuantityComponent) | ||
wrapper.vm.quantity = 5 | ||
it('La flèche du bas réduit la quantité de 1', () => { | ||
const wrapper = mount(QuantiteComponent) | ||
wrapper.vm.quantite = 5 | ||
wrapper.trigger('keydown.down') | ||
expect(wrapper.vm.quantity).to.equal(4) | ||
expect(wrapper.vm.quantite).to.equal(4) | ||
}) | ||
|
||
it('Escape sets quantity to 0', () => { | ||
const wrapper = mount(QuantityComponent) | ||
wrapper.vm.quantity = 5 | ||
it('La touche Echap positionne la quantité à 0', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. La touche Échap |
||
const wrapper = mount(QuantiteComponent) | ||
wrapper.vm.quantite = 5 | ||
wrapper.trigger('keydown.esc') | ||
expect(wrapper.vm.quantity).to.equal(0) | ||
expect(wrapper.vm.quantite).to.equal(0) | ||
}) | ||
|
||
it('Magic character "a" sets quantity to 13', () => { | ||
const wrapper = mount(QuantityComponent) | ||
it('Le caractère magique "a" positionne la quantité à 13', () => { | ||
const wrapper = mount(QuantiteComponent) | ||
wrapper.trigger('keydown', { | ||
which: 65 | ||
}) | ||
expect(wrapper.vm.quantity).to.equal(13) | ||
expect(wrapper.vm.quantite).to.equal(13) | ||
}) | ||
}) | ||
|
||
``` | ||
|
||
**Limitations** | ||
|
||
A key name after the dot `keydown.up` is translated to a `keyCode`. This is supported for the following names: | ||
Un nom de touche après le point `keydown.up` est traduit vers un `keyCode`. Cela est supporté pour les noms suivant: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. les noms suivant : (espace avant les |
||
|
||
* enter, tab, delete, esc, space, up, down, left, right | ||
|
||
## Important | ||
|
||
vue-test-utils triggers event synchronously. Consequently, `vue.nextTick` is not required. | ||
vue-test-utils déclenche les événements de façon synchrone. Par conséquent, `vue.nextTick` n'est pas requis. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. évènements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu peux retirer le EN :) Et traduire la ligne :)