Skip to content

Commit

Permalink
Ensure sign-in option doesn't show if we don't have any accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
mappum committed Dec 13, 2017
1 parent 9ae5b8b commit ff20b43
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/src/renderer/components/common/NiSessionSignUp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default {
if (key) {
this.$store.commit('setModalSession', false)
this.$store.commit('notify', { title: 'Signed Up', body: 'Your account has been created.' })
this.$store.dispatch('signUp', { password: this.fields.signUpPassword, account: this.fields.signUpName })
this.$store.dispatch('signIn', { password: this.fields.signUpPassword, account: this.fields.signUpName })
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions app/src/renderer/components/common/NiSessionWelcome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ export default {
LiSession
},
computed: {
...mapGetters(['config'])
...mapGetters(['config', 'user']),
accountExists () { return this.user.accounts.length > 0 }
},
methods: {
help () { this.$store.commit('setModalHelp', true) },
accountExists () { return !!this.$store.dispatch('accountExists') },
setState (value) { this.$store.commit('setModalSessionState', value) }
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/specs/NISessionSignUp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('NISessionSignUp', () => {
await wrapper.vm.onSubmit()
expect(store.commit.mock.calls[1][0]).toEqual('notify')
expect(store.commit.mock.calls[1][1].title.toLowerCase()).toContain('signed up')
expect(store.dispatch).toHaveBeenCalledWith('signUp', {
expect(store.dispatch).toHaveBeenCalledWith('signIn', {
password: '1234567890',
account: 'testaccount'
})
Expand Down
26 changes: 21 additions & 5 deletions test/unit/specs/NISessionWelcome.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ localVue.use(Vuex)

describe('NISessionWelcome', () => {
let wrapper, store, getters
let accounts = []

beforeEach(() => {
getters = {
config: () => ({ devMode: true })
config: () => ({ devMode: true }),
user: () => ({ accounts })
}
store = new Vuex.Store({ getters })
store.commit = jest.fn()
Expand All @@ -23,18 +25,32 @@ describe('NISessionWelcome', () => {
})
})

it('has the expected html structure', () => {
expect(htmlBeautify(wrapper.html())).toMatchSnapshot()
})

it('should open the help model on click', () => {
wrapper.findAll('.ni-session-header a').at(1).trigger('click')
expect(store.commit.mock.calls[0]).toEqual(['setModalHelp', true])
})

it('should not show sign-in link since we have no accounts', () => {
wrapper.find(LiSession).trigger('click')
expect(store.commit.mock.calls[0][1]).not.toEqual('sign-in')
})

it('(set up accounts for following tests)', () => {
accounts.push('foo', 'bar')
})

it('should show sign-in link since we have accounts', () => {
wrapper.find(LiSession).trigger('click')
expect(store.commit.mock.calls[0][1]).toEqual('sign-in')
})

it('sets desired login method', () => {
wrapper.findAll(LiSession).trigger('click')
expect(store.commit.mock.calls[0][0]).toBe('setModalSessionState')
expect(store.commit.mock.calls.map(args => args[1])).toEqual(['sign-in', 'sign-up', 'restore', 'hardware'])
})

it('has the expected html structure', () => {
expect(htmlBeautify(wrapper.html())).toMatchSnapshot()
})
})

0 comments on commit ff20b43

Please sign in to comment.