Skip to content

Commit

Permalink
Merge pull request #13187 from torchiaf/backport-13180
Browse files Browse the repository at this point in the history
[backport 2.10] Fix errors propagation in Settings edit page
  • Loading branch information
torchiaf authored Jan 23, 2025
2 parents 8a339a5 + 342a533 commit 125e7a6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
55 changes: 37 additions & 18 deletions shell/edit/__tests__/management.cattle.io.setting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ import { mount } from '@vue/test-utils';
import Settings from '@shell/edit/management.cattle.io.setting.vue';
import { SETTING } from '@shell/config/settings';

describe('view: management.cattle.io.setting should', () => {
const requiredSetup = () => ({
// Remove all these mocks after migration to Vue 2.7/3 due mixin logic
global: {
mocks: {
$store: {
getters: {
currentStore: () => 'current_store',
'current_store/schemaFor': jest.fn(),
'current_store/all': jest.fn(),
'i18n/t': jest.fn(),
'i18n/exists': jest.fn(),
},
dispatch: jest.fn(),
const requiredSetup = () => ({
// Remove all these mocks after migration to Vue 2.7/3 due mixin logic
global: {
mocks: {
$store: {
getters: {
currentStore: () => 'current_store',
'current_store/schemaFor': jest.fn(),
'current_store/all': jest.fn(),
'i18n/t': jest.fn(),
'i18n/exists': jest.fn(),
},
$route: { query: { AS: '' } },
$router: { applyQuery: jest.fn() },
}
dispatch: jest.fn(),
},
$route: { query: { AS: '' } },
$router: { applyQuery: jest.fn() },
}
});
}
});

describe('view: management.cattle.io.setting should', () => {
it('allowing to save if no rules in settings', () => {
const wrapper = mount(Settings, {
props: { value: { value: 'anything' } },
Expand Down Expand Up @@ -88,3 +88,22 @@ describe('view: management.cattle.io.setting should', () => {
});
});
});

describe('edit: management.cattle.io.setting should', () => {
it('display form errors', () => {
const wrapper = mount(Settings, {
props: {
value: { value: 'anything' },
mode: 'edit',
},
data: () => ({
setting: { },
errors: ['generic'] as any,
}),
...requiredSetup()
});
const errorBanner = wrapper.find('[data-testid="banner-content"]');

expect(errorBanner.element.textContent).toBe('generic');
});
});
2 changes: 2 additions & 0 deletions shell/edit/management.cattle.io.setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default {
Banner
},
inheritAttrs: false,
mixins: [CreateEditView, FormValidation],
data() {
Expand Down

0 comments on commit 125e7a6

Please sign in to comment.