Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport 2.10] Fix errors propagation in Settings edit page #13187

Merged
merged 1 commit into from
Jan 23, 2025
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
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
Loading