-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from SnowdogApps/feature/68
Feature/68
- Loading branch information
Showing
8 changed files
with
175 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,33 @@ | ||
import { shallowMount } from '@vue/test-utils' | ||
import Vuex from 'vuex' | ||
import { shallowMount, createLocalVue } from '@vue/test-utils' | ||
import App from '../view/frontend/web/js/App.vue' | ||
|
||
const localVue = createLocalVue() | ||
localVue.use(Vuex) | ||
|
||
describe('App.test.js', () => { | ||
let store | ||
let actions | ||
let wrapper | ||
|
||
beforeEach(() => { | ||
actions = { | ||
getCustomerData: jest.fn() | ||
} | ||
store = new Vuex.Store({ | ||
actions | ||
}) | ||
|
||
wrapper = shallowMount(App, { | ||
computed: { | ||
isCustomerLoggedIn: () => true | ||
}, | ||
store, | ||
localVue | ||
}) | ||
}) | ||
|
||
it('has the expected html structure', () => { | ||
const wrapper = shallowMount(App) | ||
expect(wrapper.element).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<template> | ||
<div> | ||
<BaseInput | ||
v-model.trim="$v.email.$model" | ||
:validation="$v.email" | ||
label="Email" | ||
name="email" | ||
type="email" | ||
@input="checkIsEmailAvailable" | ||
/> | ||
<span | ||
v-if="emailAvailabilityMessage" | ||
v-html="emailAvailabilityMessage" | ||
/> | ||
<hr> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import BaseInput from './BaseInput.vue' | ||
import axios from './../utils/checkout-axios.js' | ||
import { required, email } from 'vuelidate/lib/validators' | ||
export default { | ||
components: { | ||
BaseInput | ||
}, | ||
data () { | ||
return { | ||
email: '', | ||
emailAvailable: false | ||
} | ||
}, | ||
validations: { | ||
email: { | ||
required, | ||
} | ||
}, | ||
computed: { | ||
customerData () { | ||
return this.$store.state.customer | ||
}, | ||
ready () { | ||
return !this.$v.email.$invalid | ||
}, | ||
emailAvailabilityMessage () { | ||
if (this.email !== '' && !this.$v.email.$error) { | ||
if (this.emailAvailable) { | ||
return `You can create an account after checkout.` | ||
} else { | ||
return ` | ||
You already have an account with us. | ||
Sign in <a href="/customer/account/login/">here</a> or continue as guest. | ||
` | ||
} | ||
} else { | ||
return false | ||
} | ||
} | ||
}, | ||
watch: { | ||
ready (val) { | ||
this.$emit('ready', val) | ||
} | ||
}, | ||
created () { | ||
if ( | ||
this.customerData !== null && | ||
this.customerData.hasOwnProperty('email') | ||
) { | ||
this.email = this.customerData.email | ||
} | ||
}, | ||
methods: { | ||
touch () { | ||
this.$v.email.$touch() | ||
}, | ||
checkIsEmailAvailable () { | ||
const options = { | ||
method: 'POST', | ||
data: JSON.stringify({ | ||
'customerEmail': this.email | ||
}), | ||
url: 'customers/isEmailAvailable' | ||
} | ||
axios(options) | ||
.then(({data}) => { | ||
this.emailAvailable = data | ||
}) | ||
.catch(error => { | ||
console.error('Looks like there was a problem: \n', error) | ||
}) | ||
this.$store.commit('setItem', { | ||
item: 'customer', | ||
value: { | ||
email: this.email | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters