Fixed settings form and its test

This commit is contained in:
Grzegorz Leoniec 2019-01-18 13:45:40 +01:00
parent ab5432c830
commit 4d80dab441
No known key found for this signature in database
GPG Key ID: 3AA43686D4EB1377
2 changed files with 63 additions and 49 deletions

View File

@ -16,9 +16,9 @@ const setUserName = name => {
cy.get('input[id=name]') cy.get('input[id=name]')
.clear() .clear()
.type(name) .type(name)
cy.contains('Save') cy.get('[type=submit]')
.click() .click()
.wait(200) .not('[disabled]')
myName = name myName = name
} }
@ -31,7 +31,9 @@ When('I save {string} as my location', location => {
cy.get('.ds-select-option') cy.get('.ds-select-option')
.contains(location) .contains(location)
.click() .click()
cy.contains('Save').click() cy.get('[type=submit]')
.click()
.not('[disabled]')
myLocation = location myLocation = location
}) })
@ -39,7 +41,9 @@ When('I have the following self-description:', text => {
cy.get('textarea[id=bio]') cy.get('textarea[id=bio]')
.clear() .clear()
.type(text) .type(text)
cy.contains('Save').click() cy.get('[type=submit]')
.click()
.not('[disabled]')
aboutMeText = text aboutMeText = text
}) })

View File

@ -1,45 +1,51 @@
<template> <template>
<ds-card space="small"> <ds-form
<ds-heading tag="h3"> v-model="form"
{{ $t('settings.data.name') }} @submit="submit"
</ds-heading> >
<ds-input <ds-card space="small">
id="name" <ds-heading tag="h3">
v-model="form.name" {{ $t('settings.data.name') }}
icon="user" </ds-heading>
:label="$t('settings.data.labelName')" <ds-input
:placeholder="$t('settings.data.labelName')" id="name"
/> model="name"
<!-- eslint-disable vue/use-v-on-exact --> icon="user"
<ds-select :label="$t('settings.data.labelName')"
id="city" :placeholder="$t('settings.data.labelName')"
v-model="form.locationName" />
:options="cities" <!-- eslint-disable vue/use-v-on-exact -->
icon="map-marker" <ds-select
:label="$t('settings.data.labelCity')" id="city"
:placeholder="$t('settings.data.labelCity')" model="locationName"
@input.native="handleCityInput" icon="map-marker"
/> :options="cities"
<!-- eslint-enable vue/use-v-on-exact --> :label="$t('settings.data.labelCity')"
<ds-input :placeholder="$t('settings.data.labelCity')"
id="bio" @input.native="handleCityInput"
v-model="form.about" />
type="textarea" <!-- eslint-enable vue/use-v-on-exact -->
rows="3" <ds-input
:label="$t('settings.data.labelBio')" id="bio"
:placeholder="$t('settings.data.labelBio')" model="about"
/> type="textarea"
<template slot="footer"> rows="3"
<ds-button :label="$t('settings.data.labelBio')"
style="float: right;" :placeholder="$t('settings.data.labelBio')"
icon="check" />
primary <template slot="footer">
@click.prevent="submit" <ds-button
> style="float: right;"
{{ $t('actions.save') }} icon="check"
</ds-button> type="submit"
</template> :loading="sending"
</ds-card> primary
>
{{ $t('actions.save') }}
</ds-button>
</template>
</ds-card>
</ds-form>
</template> </template>
<script> <script>
@ -57,6 +63,7 @@ export default {
return { return {
axiosSource: null, axiosSource: null,
cities: [], cities: [],
sending: false,
form: { form: {
name: null, name: null,
locationName: null, locationName: null,
@ -83,7 +90,7 @@ export default {
}, },
methods: { methods: {
submit() { submit() {
console.log('SUBMIT', { ...this.form }) this.sending = true
this.$apollo this.$apollo
.mutate({ .mutate({
mutation: gql` mutation: gql`
@ -110,7 +117,9 @@ export default {
variables: { variables: {
id: this.user.id, id: this.user.id,
name: this.form.name, name: this.form.name,
locationName: this.form.locationName, locationName: this.form.locationName
? this.form.locationName['label'] || this.form.locationName
: null,
about: this.form.about about: this.form.about
}, },
// Update the cache with the result // Update the cache with the result
@ -139,13 +148,14 @@ export default {
} */ } */
}) })
.then(data => { .then(data => {
console.log(data)
this.$toast.success('Updated user') this.$toast.success('Updated user')
}) })
.catch(err => { .catch(err => {
console.error(err)
this.$toast.error(err.message) this.$toast.error(err.message)
}) })
.finally(() => {
this.sending = false
})
}, },
handleCityInput(value) { handleCityInput(value) {
clearTimeout(timeout) clearTimeout(timeout)