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