Merge pull request #761 from Human-Connection/undo_location_reload

Disable the location.reloads
This commit is contained in:
mattwr18 2019-06-06 14:17:50 -03:00 committed by GitHub
commit 0d4433a79f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 17 deletions

View File

@ -26,12 +26,15 @@ describe('DisableModal.vue', () => {
truncate: a => a,
},
$toast: {
success: () => {},
error: () => {},
success: jest.fn(),
error: jest.fn(),
},
$t: jest.fn(),
$apollo: {
mutate: jest.fn().mockResolvedValue(),
mutate: jest
.fn()
.mockResolvedValueOnce({ enable: 'u4711' })
.mockRejectedValue({ message: 'Not Authorised!' }),
},
location: {
reload: jest.fn(),
@ -151,6 +154,10 @@ describe('DisableModal.vue', () => {
await wrapper.find('button.confirm').trigger('click')
})
afterEach(() => {
jest.clearAllMocks()
})
it('calls mutation', () => {
expect(mocks.$apollo.mutate).toHaveBeenCalled()
})
@ -174,6 +181,18 @@ describe('DisableModal.vue', () => {
expect(wrapper.emitted().close).toBeTruthy()
})
})
describe('handles errors', () => {
beforeEach(() => {
wrapper = Wrapper()
// second submission causes mutation to reject
wrapper.find('button.confirm').trigger('click')
})
it('shows an error toaster when mutation rejects', async () => {
await expect(mocks.$toast.error).toHaveBeenCalledWith('Not Authorised!')
})
})
})
})
})

View File

@ -68,9 +68,6 @@ export default {
setTimeout(() => {
this.$emit('close')
}, 1000)
setTimeout(() => {
location.reload()
}, 250)
} catch (err) {
this.$toast.error(err.message)
}

View File

@ -23,12 +23,15 @@ describe('ReleaseModal.vue', () => {
truncate: a => a,
},
$toast: {
success: () => {},
error: () => {},
success: jest.fn(),
error: jest.fn(),
},
$t: jest.fn(),
$apollo: {
mutate: jest.fn().mockResolvedValue(),
mutate: jest
.fn()
.mockResolvedValueOnce({ enable: 'u4711' })
.mockRejectedValue({ message: 'Not Authorised!' }),
},
location: {
reload: jest.fn(),
@ -146,6 +149,10 @@ describe('ReleaseModal.vue', () => {
wrapper.find('button.confirm').trigger('click')
})
afterEach(() => {
jest.clearAllMocks()
})
it('calls mutation', () => {
expect(mocks.$apollo.mutate).toHaveBeenCalled()
})
@ -169,6 +176,18 @@ describe('ReleaseModal.vue', () => {
expect(wrapper.emitted().close).toBeTruthy()
})
})
describe('handles errors', () => {
beforeEach(() => {
wrapper = Wrapper()
// second submission causes mutation to reject
wrapper.find('button.confirm').trigger('click')
})
it('shows an error toaster when mutation rejects', async () => {
await expect(mocks.$toast.error).toHaveBeenCalledWith('Not Authorised!')
})
})
})
})
})

View File

@ -57,17 +57,9 @@ export default {
})
this.$toast.success(this.$t('release.success'))
this.isOpen = false
/*
setTimeout(() => {
location.reload()
}, 1500)
*/
setTimeout(() => {
this.$emit('close')
}, 1000)
setTimeout(() => {
location.reload()
}, 250)
} catch (err) {
this.$toast.error(err.message)
}