feat(tests): refactor

This commit is contained in:
2024-03-26 17:59:32 +03:00
parent f6ca446f92
commit 49626cb681
23 changed files with 128 additions and 136 deletions

View File

@@ -0,0 +1,10 @@
import {test, describe, expect} from 'vitest'
import { mount} from '@vue/test-utils'
import Accordion from '@atoms/Accordion.vue';
describe('Accordion', () => {
test('Accordion mounted', () => {
const wrapper = mount(Accordion)
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,10 @@
import {test, describe, expect} from 'vitest'
import { mount} from '@vue/test-utils'
import Button from '@atoms/Button.vue';
describe('Accordion', () => {
test('Accordion mounted', () => {
const wrapper = mount(Button)
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,10 @@
import {test, describe, expect} from 'vitest'
import { mount} from '@vue/test-utils'
import ButtonDiscard from '@atoms/ButtonDiscard.vue';
describe('ButtonDiscard', () => {
test('ButtonDiscard mounted', () => {
const wrapper = mount(ButtonDiscard)
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,10 @@
import {test, describe, expect} from 'vitest'
import { mount} from '@vue/test-utils'
import ButtonEdit from '@atoms/ButtonEdit.vue';
describe('ButtonEdit', () => {
test('ButtonEdit mounted', () => {
const wrapper = mount(ButtonEdit)
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,10 @@
import {test, describe, expect} from 'vitest'
import { mount} from '@vue/test-utils'
import ButtonSave from '@atoms/ButtonSave.vue';
describe('ButtonSave', () => {
test('ButtonSave mounted', () => {
const wrapper = mount(ButtonSave)
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,10 @@
import {test, describe, expect} from 'vitest'
import { mount} from '@vue/test-utils'
import DoubleSwitch from '@atoms/DoubleSwitch.vue';
describe('DoubleSwitch', () => {
test('DoubleSwitch mounted', () => {
const wrapper = mount(DoubleSwitch)
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,10 @@
import {test, describe, expect, vi} from 'vitest'
import { mount} from '@vue/test-utils'
import ButtonModal from '@molecules/ButtonModal/ButtonModal.vue';
describe('ButtonModal', () => {
test('ButtonModal mounted', () => {
const wrapper = mount(ButtonModal)
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,10 @@
import {test, describe, expect, vi} from 'vitest'
import { mount} from '@vue/test-utils'
import MachinesModal from '@molecules/MachinesModal/MachinesModal.vue';
describe('MachinesModal', () => {
test('MachinesModal mounted', () => {
const wrapper = mount(MachinesModal)
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,122 @@
import Service from '@admin_pages/Services/Service.vue'
import { globalServices } from '@store/modules/services/StaticData'
import { mount } from '@vue/test-utils'
import {createStore} from 'vuex'
const store = createStore({
state() {
return {
services: globalServices,
}
},
getters: {
services: (state) => state.services,
},
mutations: {
setServices: (state, updval) => state.services = updval,
},
})
describe("Service", () => {
it("renders Service, with set props value", async () => {
const wrapper = mount(Service, {
global: {
plugins: [store],
},
props: {
idx: 1,
},
})
await wrapper.setProps({ idx: 3 })
expect(wrapper.html()).toContain(3)
})
})
describe("Service", () => {
it("renders Service with condition success", async () => {
const wrapper = mount(Service, {
global: {
plugins: [store],
},
props: {
name: '',
},
})
await wrapper.setProps({ name: 'глобальное хранилище' })
expect(wrapper.html()).toContain('доступен')
})
})
describe("Service", () => {
it("renders Service with condition not success", async () => {
const wrapper = mount(Service, {
global: {
plugins: [store],
},
props: {
name: '',
},
})
await wrapper.setProps({ name: 'Test service name' })
expect(wrapper.html()).toContain('отключен')
})
})
describe("Service", () => {
it("renders Service if not service details", async () => {
const wrapper = mount(Service, {
global: {
plugins: [store],
},
props: {
service: {},
},
})
expect(wrapper.html()).toContain('Сервис глобального хранилища применяется для условно постоянного хранения данных в кэше')
})
})
describe("Service", () => {
it("renders Service with set service details", async () => {
const wrapper = mount(Service, {
global: {
plugins: [store],
},
props: {
service: {serviceIp: '192.168.1.1', serviceCode: '1234567890', serviceLink: 'http://test.com', is_online: false,
},
},
})
await wrapper.setProps({ service: {serviceIp: '192.168.1.7', serviceCode: '1234567897', is_online: true} }) // 1 раз, далее новый тест
expect(wrapper.html()).toContain('192.168.1.7')
expect(wrapper.html()).toContain('1234567897')
expect(wrapper.html()).toContain('доступен')
expect(wrapper.html()).toContain('... нет описания')
})
})
describe("Service", () => {
it("renders Service with alert copyText success after click", async () => {
const wrapper = mount(Service, {
global: {
plugins: [store],
},
props: {
copyed: '',
service: {init_params: {service: 'Test service', machine_addr: 'Test machine_addr'}},
},
})
await wrapper.get('.copyText').trigger('click')
expect(wrapper.html()).toContain('copyed')
})
})

View File

@@ -0,0 +1,74 @@
import Services from '@admin_pages/Services/index.vue'
import { globalServices } from '@store/modules/services/StaticData'
import { mount } from '@vue/test-utils'
import {createStore} from 'vuex'
const store = createStore({
state() {
return {
services: globalServices,
}
},
getters: {
services: (state) => state.services,
},
mutations: {
setServices: (state, updval) => state.services = updval,
},
})
describe("Services", () => {
it("renders Services, with custom button title", () => {
const wrapper = mount(Services, {
global: {
plugins: [store],
},
data () {
return {
titleServicesButton: 'Показать больше сервисов',
}
},
})
expect(wrapper.text()).toContain('Показать больше сервисов')
})
})
describe("Services", () => {
it("renders after click button, open full Services", async () => {
const wrapper = mount(Services, {
global: {
plugins: [store],
},
})
await wrapper.find('button').trigger('click')
expect(wrapper.find('button').text()).toContain('Скрыть')
})
})
describe("Services", () => {
it("renders Services with exists data", async () => {
const wrapper = mount(Services, {
global: {
plugins: [store],
},
})
expect(store.state.services.length).toBeGreaterThan(0)
})
})
describe("Services", () => {
it("renders Services maked empty data", async () => {
const wrapper = mount(Services, {
global: {
plugins: [store],
},
})
store.commit('setServices', [])
expect(store.state.services.length).toBe(0)
})
})