Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/src/views/admin/GroupsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6087,7 +6087,7 @@ const handleCreateGroup = async () => {
}
} catch (error: any) {
appStore.showError(
error.response?.data?.detail || t("admin.groups.failedToCreate"),
extractApiErrorMessage(error, t("admin.groups.failedToCreate")),
);
console.error("Error creating group:", error);
// Don't advance tour on error
Expand Down Expand Up @@ -6358,7 +6358,7 @@ const handleUpdateGroup = async () => {
loadGroups();
} catch (error: any) {
appStore.showError(
error.response?.data?.detail || t("admin.groups.failedToUpdate"),
extractApiErrorMessage(error, t("admin.groups.failedToUpdate")),
);
console.error("Error updating group:", error);
} finally {
Expand Down
36 changes: 34 additions & 2 deletions frontend/src/views/admin/__tests__/GroupsView.duplicate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import GroupsView from '@/views/admin/GroupsView.vue'
const {
listGroups,
duplicateGroup,
updateGroup,
getModelsListCandidates,
getUsageSummary,
getCapacitySummary,
Expand All @@ -17,6 +18,7 @@ const {
} = vi.hoisted(() => ({
listGroups: vi.fn(),
duplicateGroup: vi.fn(),
updateGroup: vi.fn(),
getModelsListCandidates: vi.fn(),
getUsageSummary: vi.fn(),
getCapacitySummary: vi.fn(),
Expand All @@ -36,7 +38,7 @@ vi.mock('@/api/admin', () => ({
getLiveCapability,
getAll: vi.fn(),
create: vi.fn(),
update: vi.fn(),
update: updateGroup,
delete: vi.fn(),
updateSortOrder: vi.fn()
},
Expand Down Expand Up @@ -136,6 +138,13 @@ const DataTableStub = defineComponent({
template: '<div><div v-for="row in data" :key="row.id"><slot name="cell-actions" :row="row" /></div></div>'
})

const BaseDialogStub = defineComponent({
props: {
show: { type: Boolean, default: false }
},
template: '<div v-if="show"><slot /><slot name="footer" /></div>'
})

function mountView() {
return mount(GroupsView, {
global: {
Expand All @@ -144,7 +153,7 @@ function mountView() {
TablePageLayout: TablePageLayoutStub,
DataTable: DataTableStub,
Pagination: true,
BaseDialog: true,
BaseDialog: BaseDialogStub,
ConfirmDialog: true,
EmptyState: true,
Select: true,
Expand All @@ -166,6 +175,7 @@ describe('GroupsView duplicate action', () => {
for (const fn of [
listGroups,
duplicateGroup,
updateGroup,
getModelsListCandidates,
getUsageSummary,
getCapacitySummary,
Expand Down Expand Up @@ -270,4 +280,26 @@ describe('GroupsView duplicate action', () => {
expect(showError).not.toHaveBeenCalledWith('admin.groups.duplicateFailed')
wrapper.unmount()
})

it('shows the standardized API message when updating a group fails', async () => {
updateGroup.mockRejectedValueOnce({
status: 409,
code: 409,
message: 'group name already exists',
reason: 'GROUP_EXISTS'
})
const wrapper = mountView()
await flushPromises()

const editButton = wrapper.findAll('button').find((button) => button.text() === 'common.edit')
expect(editButton).toBeTruthy()
await editButton!.trigger('click')
await flushPromises()
await wrapper.get('#edit-group-form').trigger('submit')
await flushPromises()

expect(updateGroup).toHaveBeenCalledTimes(1)
expect(showError).toHaveBeenCalledWith('group name already exists')
wrapper.unmount()
})
})
Loading