-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f4bf83
commit d728319
Showing
9 changed files
with
339 additions
and
616 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
61 changes: 61 additions & 0 deletions
61
spring-boot-admin-server-ui/src/main/frontend/views/instances/env/busrefresh.spec.ts
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,61 @@ | ||
import userEvent from '@testing-library/user-event'; | ||
import { screen } from '@testing-library/vue'; | ||
import { HttpResponse, http } from 'msw'; | ||
import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
||
import { server } from '@/mocks/server'; | ||
import Instance from '@/services/instance'; | ||
import { render } from '@/test-utils'; | ||
import Busrefresh from '@/views/instances/env/busrefresh.vue'; | ||
|
||
describe('Busrefresh', () => { | ||
const busRefreshInstanceContextMock = vi.fn(); | ||
let emitted; | ||
|
||
function createInstance() { | ||
const instance = new Instance({ id: 1233 }); | ||
instance.busRefreshContext = busRefreshInstanceContextMock; | ||
return instance; | ||
} | ||
|
||
beforeEach(async () => { | ||
server.use( | ||
http.post('/instances/:instanceId/actuator/busrefresh', () => { | ||
return HttpResponse.json({}); | ||
}), | ||
); | ||
const vm = render(Busrefresh, { | ||
props: { | ||
instance: createInstance(), | ||
}, | ||
}); | ||
emitted = vm.emitted; | ||
}); | ||
|
||
it('should trigger busrefresh on confirm', async () => { | ||
busRefreshInstanceContextMock.mockResolvedValue({}); | ||
const busRefreshButton = await screen.findByText( | ||
'instances.env.bus_refresh', | ||
); | ||
await userEvent.click(busRefreshButton); | ||
|
||
const confirmButton = await screen.findByText('Confirm'); | ||
await userEvent.click(confirmButton); | ||
|
||
expect(emitted().refresh[0][0]).toBe(true); | ||
}); | ||
|
||
it('should handle busrefresh failure gracefully', async () => { | ||
busRefreshInstanceContextMock.mockRejectedValueOnce(new Error()); | ||
|
||
const busRefreshButton = await screen.findByText( | ||
'instances.env.bus_refresh', | ||
); | ||
await userEvent.click(busRefreshButton); | ||
|
||
const confirmButton = await screen.findByText('Confirm'); | ||
await userEvent.click(confirmButton); | ||
|
||
expect(emitted().refresh).toBeUndefined(); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
spring-boot-admin-server-ui/src/main/frontend/views/instances/env/busrefresh.vue
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,52 @@ | ||
<template> | ||
<sba-confirm-button | ||
:title="$t('instances.env.bus_refresh_title')" | ||
class="inline-flex focus:z-10" | ||
@click="refreshInstance" | ||
> | ||
<span v-text="t('instances.env.bus_refresh')" /> | ||
</sba-confirm-button> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { useNotificationCenter } from '@stekoe/vue-toast-notificationcenter'; | ||
import { useI18n } from 'vue-i18n'; | ||
import SbaConfirmButton from '@/components/sba-confirm-button.vue'; | ||
import Instance from '@/services/instance'; | ||
const notificationCenter = useNotificationCenter({}); | ||
export default { | ||
components: { SbaConfirmButton }, | ||
props: { | ||
instance: { | ||
type: Instance, | ||
required: true, | ||
}, | ||
}, | ||
emits: ['refresh'], | ||
setup() { | ||
const i18n = useI18n(); | ||
return { | ||
t: i18n.t, | ||
}; | ||
}, | ||
methods: { | ||
async refreshInstance() { | ||
this.instance | ||
.busRefreshContext() | ||
.then(() => { | ||
notificationCenter.success( | ||
this.t('instances.env.bus_refresh_success'), | ||
); | ||
this.$emit('refresh', true); | ||
}) | ||
.catch(() => { | ||
notificationCenter.error(this.t('instances.env.bus_refresh_failure')); | ||
}); | ||
}, | ||
}, | ||
}; | ||
</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