Skip to content

Commit

Permalink
Undo commit file and rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
purwandi authored and adhatama committed Jan 29, 2018
1 parent 4d993ab commit 0f7fbbd
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 66 deletions.
15 changes: 14 additions & 1 deletion resources/js/components/header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
img(src="../../images/logo.png")
span.hidden-folded.m-l.xs Tania
.collapse.pos-rlt.navbar-collapse.box-shadow.bg-white-only
ul.nav.navbar-nav.navbar-right
li
a#signout(href="#" @click.prevent="signout") Sign Out
ul.nav.navbar-nav.hidden-xs
li.dropdown.farmswitch(:class="dropdown === true ? 'open': 'closed'")
a.farm-current(href="#" @click.prevent="dropdownToggle")
Expand All @@ -22,6 +25,7 @@
</template>

<script>
import { ls } from '@/services'
import { mapGetters, mapActions } from 'vuex'
export default {
name: 'AppHeaderComponent',
Expand All @@ -38,7 +42,8 @@ export default {
},
methods: {
...mapActions([
'setCurrentFarm'
'setCurrentFarm',
'userSignOut'
]),
setFarm (farmId) {
this.setCurrentFarm(farmId)
Expand All @@ -47,6 +52,14 @@ export default {
},
dropdownToggle() {
this.dropdown = !this.dropdown
},
signout () {
this.userSignOut()
.then(data => {
ls.remove('vuex')
this.$router.push({ name: 'AuthLogin' })
})
.catch(err => console.log(error))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions resources/js/pages/auth/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default {
},
mounted () {
console.log(this.user.uid)
// redirect if the user already auntenticated
if (this.user.uid !== '') {
this.$router.push({ name: 'Home' })
Expand Down
11 changes: 11 additions & 0 deletions resources/js/stores/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ const actions = {
},
userCompletedIntro({ commit, state }) {
commit(types.USER_COMPLETED_INTRO)
},
userSignOut({commit, state}, payload) {
return new Promise((resolve, reject) => {
// @TODO sent http request to the server to revoke the
// authentication access
commit(types.USER_LOGOUT)
resolve()
})
}
}

Expand All @@ -41,6 +49,9 @@ const mutations = {
},
[types.USER_COMPLETED_INTRO] (state) {
state.current.intro = false
},
[types.USER_LOGOUT] (state, payload) {
state.current.uid = ''
}
}

Expand Down
1 change: 1 addition & 0 deletions resources/js/stores/mutation-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export const FETCH_CROP = 'FETCH_CROP'
export const CREATE_CROP_NOTES = 'CREATE_CROP_NOTES'

export const USER_LOGIN = 'USER_LOGIN'
export const USER_LOGOUT = 'USER_LOGOUT'
export const USER_COMPLETED_INTRO = 'USER_COMPLETED_INTRO'
27 changes: 27 additions & 0 deletions resources/tests/factory/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export function login() {
cy.clearLocalStorage()

cy.visit('/#/')
// Label
cy.get('label#label-username').should('contain', 'Username')
cy.get('label#label-password').should('contain', 'Password')

// Typing the form
cy.get('input#username').type('demo').should('have.value', 'demo')
cy.get('input#password').type('password')
cy.get('button.btn').click()
}

export function login_as_user() {
cy.clearLocalStorage()

cy.visit('/#/')
// Label
cy.get('label#label-username').should('contain', 'Username')
cy.get('label#label-password').should('contain', 'Password')

// Typing the form
cy.get('input#username').type('user').should('have.value', 'user')
cy.get('input#password').type('password')
cy.get('button.btn').click()
}
51 changes: 51 additions & 0 deletions resources/tests/factory/farm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export function filled_farm() {
// Label
cy.get('label#label-name').should('contain', 'Farm Name')
cy.get('label#label-description').should('contain', 'Farm Description')
cy.get('label#label-type').should('contain', 'Farm Type')
cy.get('label#label-location').should('contain', 'Location')
cy.get('label#label-country').should('contain', 'Country')
cy.get('label#label-city').should('contain', 'City')

// Typing the form
cy.get('input#name').type('FarmName2').should('have.value', 'FarmName2')
cy.get('textarea#description').type('Farm long description criteria').should('have.value','Farm long description criteria')
cy.get('select#type').select('organic')
cy.get('input#latitude').type('-6.2499848').should('have.value', '-6.2499848')
cy.get('input#longitude').type('106.68292059999999').should('have.value', '106.68292059999999')
cy.get('select#country').select('ID')
cy.get('select#city').select('JK')
cy.get('button.btn[type=submit]').click()
}

export function filled_reservoir() {
// Label
cy.get('label#label-name').should('contain', 'Reservoir Name')
cy.get('label#label-source').should('contain', 'Source')

// Typing the form
cy.get('#name').type('Reservoir1').should('have.value', 'Reservoir1')
cy.get('#type').select('TAP')
cy.get('#capacity').should('not.exist')
cy.get('#type').select('BUCKET')
cy.get('#capacity').should('exist').type('12').should('have.value', '12')
cy.get('button.btn[type=submit]').click()
}

export function filled_area() {
// Label
cy.get('label#label-name').should('contain', 'Area Name')
cy.get('label#label-size').should('contain', 'Size')
cy.get('label#label-type').should('contain', 'Type')
cy.get('label#label-location').should('contain', 'Locations')
cy.get('label#label-reservoir').should('contain', 'Select Reservoir')

// Typing the form
cy.get('#name').type('Area1').should('have.value', 'Area1')
cy.get('#size').type('2').should('have.value', '2')
cy.get('#size_unit').select('Ha')
cy.get('#type').select('SEEDING')
cy.get('#location').select('OUTDOOR')
cy.get('#reservoir').select('Reservoir1')
cy.get('button.btn[type=submit]').click()
}
67 changes: 2 additions & 65 deletions resources/tests/integration/01_intro_spec.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,5 @@
function login() {
cy.clearLocalStorage()

cy.visit('/#/')
// Label
cy.get('label#label-username').should('contain', 'Username')
cy.get('label#label-password').should('contain', 'Password')

// Typing the form
cy.get('input#username').type('demo').should('have.value', 'demo')
cy.get('input#password').type('password')
cy.get('button.btn').click()
}

function filled_farm() {
// Label
cy.get('label#label-name').should('contain', 'Farm Name')
cy.get('label#label-description').should('contain', 'Farm Description')
cy.get('label#label-type').should('contain', 'Farm Type')
cy.get('label#label-location').should('contain', 'Location')
cy.get('label#label-country').should('contain', 'Country')
cy.get('label#label-city').should('contain', 'City')

// Typing the form
cy.get('input#name').type('FarmName2').should('have.value', 'FarmName2')
cy.get('textarea#description').type('Farm long description criteria').should('have.value','Farm long description criteria')
cy.get('select#type').select('organic')
cy.get('input#latitude').type('-6.2499848').should('have.value', '-6.2499848')
cy.get('input#longitude').type('106.68292059999999').should('have.value', '106.68292059999999')
cy.get('select#country').select('ID')
cy.get('select#city').select('JK')
cy.get('button.btn[type=submit]').click()
}

function filled_reservoir() {
// Label
cy.get('label#label-name').should('contain', 'Reservoir Name')
cy.get('label#label-source').should('contain', 'Source')

// Typing the form
cy.get('#name').type('Reservoir1').should('have.value', 'Reservoir1')
cy.get('#type').select('TAP')
cy.get('#capacity').should('not.exist')
cy.get('#type').select('BUCKET')
cy.get('#capacity').should('exist').type('12').should('have.value', '12')
cy.get('button.btn[type=submit]').click()
}

function filled_area() {
// Label
cy.get('label#label-name').should('contain', 'Area Name')
cy.get('label#label-size').should('contain', 'Size')
cy.get('label#label-type').should('contain', 'Type')
cy.get('label#label-location').should('contain', 'Locations')
cy.get('label#label-reservoir').should('contain', 'Select Reservoir')

// Typing the form
cy.get('#name').type('Area1').should('have.value', 'Area1')
cy.get('#size').type('2').should('have.value', '2')
cy.get('#size_unit').select('Ha')
cy.get('#type').select('SEEDING')
cy.get('#location').select('OUTDOOR')
cy.get('#reservoir').select('Reservoir1')
cy.get('button.btn[type=submit]').click()
}
import { login } from '../factory/auth'
import { filled_farm, filled_reservoir, filled_area } from '../factory/farm'

describe('Intro specs', () => {

Expand Down
36 changes: 36 additions & 0 deletions resources/tests/integration/03_logout_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { login_as_user } from '../factory/auth'

describe('Logout specs', () => {
it ('should have logout link', () => {
login_as_user()
cy.get('#signout').should('contain', 'Sign Out')
cy.get('#signout').click()
cy.location().should( location => {
expect(location.hash).to.eq('#/auth/login')
})
})

it ('should not visit the dashboard page if the user already logout', () => {
login_as_user()
cy.get('#signout').should('contain', 'Sign Out')
cy.get('#signout').click()

cy.visit('/#/')
cy.location().should( location => {
expect(location.hash).to.eq('#/auth/login?redirect=%2F')
})

cy.visit('/#/intro/area')
cy.location().should( location => {
expect(location.hash).to.eq('#/auth/login?redirect=%2Fintro%2Farea')
})
})

it ('should not have localstorage with vuex key in the browser', () => {
login_as_user()
cy.get('#signout').should('contain', 'Sign Out')
cy.get('#signout').click()

expect(localStorage.getItem('vuex')).to.eq(null)
})
})
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8414,6 +8414,10 @@ uuid@^3.0.0, uuid@^3.0.1, uuid@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"

v-click-outside@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/v-click-outside/-/v-click-outside-1.0.2.tgz#9ca50aa0014d09ee78d257be4e6a3288caa0d753"

vali-date@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/vali-date/-/vali-date-1.0.0.tgz#1b904a59609fb328ef078138420934f6b86709a6"
Expand Down

0 comments on commit 0f7fbbd

Please sign in to comment.