mirror of https://github.com/rancher/dashboard.git
Fix unit tests
Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
This commit is contained in:
parent
68e046e5ed
commit
594570d37a
|
|
@ -68,7 +68,18 @@ jest.mock('@shell/composables/useI18n', () => ({ useI18n: () => (key) => key }))
|
|||
// eslint-disable-next-line no-console
|
||||
jest.spyOn(console, 'warn').mockImplementation((warning) => warning.includes('[Vue warn]') ? null : console.log(warning));
|
||||
|
||||
jest.mock('@shell/composables/useI18n', () => ({ useI18n: () => (key) => key }));
|
||||
// jest.mock('@shell/composables/useI18n', () => ({ useI18n: () => (key) => key }));
|
||||
jest.mock('@shell/composables/useI18n', () => {
|
||||
return {
|
||||
useI18n() {
|
||||
return {
|
||||
t(key) {
|
||||
return key;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
});
|
||||
// eslint-disable-next-line no-console
|
||||
jest.spyOn(console, 'warn').mockImplementation((warning) => warning.includes('[Vue warn]') ? null : console.log(warning));
|
||||
|
||||
|
|
|
|||
|
|
@ -306,7 +306,7 @@ export default {
|
|||
namespace.value = metadata?.namespace;
|
||||
}
|
||||
|
||||
if (!namespace.value && !this.noDefaultNamespace) {
|
||||
if (!namespace.value && !props.noDefaultNamespace) {
|
||||
namespace.value = store.getters['defaultNamespace'];
|
||||
if (metadata) {
|
||||
metadata.namespace = namespace;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
import { mount } from '@vue/test-utils';
|
||||
import NameNsDescription from '@shell/components/form/NameNsDescription.vue';
|
||||
import { createStore } from 'vuex';
|
||||
|
||||
describe('component: NameNsDescription', () => {
|
||||
// Accessing to computed value due code complexity
|
||||
it('should map namespaces to options', () => {
|
||||
const namespaceName = 'test';
|
||||
const store = createStore({
|
||||
getters: {
|
||||
allowedNamespaces: () => () => ({ [namespaceName]: true }),
|
||||
currentStore: () => () => 'cluster',
|
||||
'cluster/schemaFor': () => jest.fn()
|
||||
}
|
||||
});
|
||||
const result = [
|
||||
{
|
||||
label: namespaceName,
|
||||
|
|
@ -21,15 +29,13 @@ describe('component: NameNsDescription', () => {
|
|||
cluster: {},
|
||||
},
|
||||
global: {
|
||||
mocks: {
|
||||
provide: { store },
|
||||
mocks: {
|
||||
$store: {
|
||||
dispatch: jest.fn(),
|
||||
getters: {
|
||||
namespaces: jest.fn(),
|
||||
allowedNamespaces: () => ({ [namespaceName]: true }),
|
||||
currentStore: () => 'cluster',
|
||||
'cluster/schemaFor': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
namespaces: jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -41,6 +47,13 @@ describe('component: NameNsDescription', () => {
|
|||
|
||||
it('should emit in case of new namespace', () => {
|
||||
const namespaceName = 'test';
|
||||
const store = createStore({
|
||||
getters: {
|
||||
allowedNamespaces: () => () => ({ [namespaceName]: true }),
|
||||
currentStore: () => () => 'cluster',
|
||||
'cluster/schemaFor': () => jest.fn()
|
||||
}
|
||||
});
|
||||
const newNamespaceName = 'bananas';
|
||||
const wrapper = mount(NameNsDescription, {
|
||||
props: {
|
||||
|
|
@ -51,20 +64,18 @@ describe('component: NameNsDescription', () => {
|
|||
mode: 'create',
|
||||
},
|
||||
global: {
|
||||
mocks: {
|
||||
provide: { store },
|
||||
mocks: {
|
||||
$store: {
|
||||
dispatch: jest.fn(),
|
||||
getters: {
|
||||
namespaces: jest.fn(),
|
||||
allowedNamespaces: () => ({ [namespaceName]: true }),
|
||||
'customizations/getPreviewCluster': {
|
||||
ready: true,
|
||||
isLocal: false,
|
||||
badge: {},
|
||||
},
|
||||
currentStore: () => 'cluster',
|
||||
'cluster/schemaFor': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2,14 +2,23 @@ import { mount } from '@vue/test-utils';
|
|||
import FormValidation from '@shell/mixins/form-validation';
|
||||
import Monitoring from '@shell/edit/monitoring.coreos.com.prometheusrule/index.vue';
|
||||
import { _EDIT } from '@shell/config/query-params';
|
||||
import { createStore } from 'vuex';
|
||||
|
||||
describe('edit: management.cattle.io.setting should', () => {
|
||||
const MOCKED_ERRORS = ['error1', 'error2', 'error3', 'error4', 'error5'];
|
||||
const ERROR_BANNER_SELECTOR = '[data-testid="banner-close"]';
|
||||
const store = createStore({
|
||||
getters: {
|
||||
namespaces: () => () => ({}),
|
||||
currentStore: () => () => 'current_store',
|
||||
'current_store/schemaFor': () => jest.fn()
|
||||
}
|
||||
});
|
||||
const requiredSetup = () => ({
|
||||
// Remove all these mocks after migration to Vue 2.7/3 due mixin logic
|
||||
global: {
|
||||
mocks: {
|
||||
provide: { store },
|
||||
mocks: {
|
||||
$store: {
|
||||
dispatch: jest.fn(),
|
||||
getters: {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { mount } from '@vue/test-utils';
|
||||
import Banzai from '@shell/edit/logging.banzaicloud.io.output/index.vue';
|
||||
import { createStore } from 'vuex';
|
||||
|
||||
const outputSchema = {
|
||||
id: 'logging.banzaicloud.io.output',
|
||||
|
|
@ -109,6 +110,13 @@ describe('view: logging.banzaicloud.io.output', () => {
|
|||
['http://localhost:3100', []],
|
||||
['not a proper URL', ['logging.loki.urlInvalid']],
|
||||
])('should validate Loki URL on save', (url, expectation) => {
|
||||
const store = createStore({
|
||||
getters: {
|
||||
namespaces: () => () => ({}),
|
||||
currentStore: () => () => 'cluster',
|
||||
'cluster/schemaFor': () => jest.fn()
|
||||
}
|
||||
});
|
||||
const wrapper = mount(Banzai, {
|
||||
data: () => ({ selectedProvider: 'loki' }),
|
||||
props: {
|
||||
|
|
@ -120,7 +128,8 @@ describe('view: logging.banzaicloud.io.output', () => {
|
|||
}
|
||||
},
|
||||
global: {
|
||||
mocks: {
|
||||
provide: { store },
|
||||
mocks: {
|
||||
$fetchState: { pending: false },
|
||||
$store: {
|
||||
dispatch: jest.fn(),
|
||||
|
|
@ -151,6 +160,13 @@ describe('view: logging.banzaicloud.io.output', () => {
|
|||
});
|
||||
|
||||
it('should load the default YAML data for output buffer config (from schema) in a CREATE scenario', async() => {
|
||||
const store = createStore({
|
||||
getters: {
|
||||
namespaces: () => () => ({}),
|
||||
currentStore: () => () => 'cluster',
|
||||
'cluster/schemaFor': () => jest.fn()
|
||||
}
|
||||
});
|
||||
const wrapper = mount(Banzai, {
|
||||
data: () => ({ selectedProvider: 'awsElasticsearch' }),
|
||||
props: {
|
||||
|
|
@ -162,7 +178,8 @@ describe('view: logging.banzaicloud.io.output', () => {
|
|||
}
|
||||
},
|
||||
global: {
|
||||
mocks: {
|
||||
provide: { store },
|
||||
mocks: {
|
||||
$fetchState: { pending: false },
|
||||
$store: {
|
||||
dispatch(arg: any) {
|
||||
|
|
@ -234,6 +251,13 @@ describe('view: logging.banzaicloud.io.output', () => {
|
|||
});
|
||||
|
||||
it('should load current output buffer config in an EDIT scenario', async() => {
|
||||
const store = createStore({
|
||||
getters: {
|
||||
namespaces: () => () => ({}),
|
||||
currentStore: () => () => 'cluster',
|
||||
'cluster/schemaFor': () => jest.fn()
|
||||
}
|
||||
});
|
||||
const wrapper = mount(Banzai, {
|
||||
data: () => ({ selectedProvider: 'awsElasticsearch' }),
|
||||
props: {
|
||||
|
|
@ -245,7 +269,8 @@ describe('view: logging.banzaicloud.io.output', () => {
|
|||
}
|
||||
},
|
||||
global: {
|
||||
mocks: {
|
||||
provide: { store },
|
||||
mocks: {
|
||||
$fetchState: { pending: false },
|
||||
$store: {
|
||||
dispatch(arg: any) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue