Initial commit

This commit is contained in:
2024-03-05 11:36:21 +03:00
commit bf2f060b94
212 changed files with 100448 additions and 0 deletions

View File

@@ -0,0 +1,126 @@
import { expect, test, describe, vi, beforeEach} from "vitest";
import { createStore } from 'vuex'
import {store as services} from "@/store/modules/services"
import axios from "axios";
vi.mock('axios')
describe("tests services store with vuex", () => {
const store = createStore({
plugins: [],
modules: {
services
},
})
beforeEach(() => {
store.dispatch('services/resetStore')
})
test('upload sites data', async () => {
const mockData = [
{
"id": 1,
"created_at": "2024-02-22T17:08:37.715772388+03:00",
"updated_at": "2024-02-26T14:11:38.64094899+03:00",
"deleted_at": null,
"name": "jsonplaceholder.typicode.com",
"port": 9965,
"proxy_ip": "172.25.78.153",
"site_ip": "172.25.78.153",
"internet_uri": "localhost",
"description": "localhost",
"is_online": true
}
]
const expectedData = [
{
"id": 1,
"created_at": "2024-02-22T17:08:37.715772388+03:00",
"updated_at": "2024-02-26T14:11:38.64094899+03:00",
"deleted_at": null,
"name": "jsonplaceholder.typicode.com",
"port": 9965,
"proxy_ip": "172.25.78.153",
"device_ip": "172.25.78.153",
"internet_uri": "localhost",
"description": "localhost",
"is_online": true
}
]
axios.get.mockResolvedValue({
data: mockData,
})
await store.dispatch('services/uploadSites')
const sites = store.getters['services/sites']
expect(sites).toEqual(expectedData)
})
test('test addNewSiteLayout function', async () => {
const expectedSiteData = {"port": "", "name": "", id: -1}
store.dispatch('services/addNewSiteLayout')
const selectedSite = store.getters['services/selectedSite']
const sites = store.getters['services/sites']
expect(
{
selectedSite,
sites
}
).toEqual({
selectedSite: expectedSiteData,
sites: [expectedSiteData]
})
})
test("test uploadAndSelectService function", async () => {
const mockData = [
{
"id": 1,
"created_at": "2024-02-22T17:08:37.715772388+03:00",
"updated_at": "2024-02-26T14:11:38.64094899+03:00",
"deleted_at": null,
"name": "jsonplaceholder.typicode.com",
"port": 9965,
"proxy_ip": "172.25.78.153",
"site_ip": "172.25.78.153",
"internet_uri": "localhost",
"description": "localhost",
"is_online": true
}
]
axios.get.mockResolvedValue({
data: mockData,
})
await store.dispatch('services/uploadSites')
store.dispatch('services/uploadAndSelectService', 1)
const selectedSite = store.getters['services/selectedSite']
const selectedSiteState = store.getters['services/selectedSiteState']
expect(selectedSite).toEqual({
"id": 1,
"created_at": "2024-02-22T17:08:37.715772388+03:00",
"updated_at": "2024-02-26T14:11:38.64094899+03:00",
"deleted_at": null,
"name": "jsonplaceholder.typicode.com",
"port": 9965,
"proxy_ip": "172.25.78.153",
"device_ip": "172.25.78.153",
"internet_uri": "localhost",
"description": "localhost",
"is_online": true
})
expect(selectedSiteState).toEqual('active')
})
})

View File

@@ -0,0 +1,56 @@
import { expect, test, describe, vi, beforeEach} from "vitest";
import { createStore } from 'vuex'
import {store as users} from "@/store/modules/users"
import axios from "axios";
vi.mock('axios')
describe("tests services store with vuex", () => {
const store = createStore({
plugins: [],
modules: {
users
},
})
beforeEach(() => {
store.dispatch('users/resetStore')
})
test('test fetchUsersList function', async () => {
const mockData = [
{
"id": 1,
"first_name": "Leanne",
"last_name": "Graham",
"email": "test@mail.ru",
"role": "admin",
"is_active": true
}
]
axios.get.mockResolvedValue({
data: mockData,
})
const expectedData = [
{
"id": 1,
"first_name": "Leanne",
"last_name": "Graham",
"email": "test@mail.ru",
"role": "admin",
"is_active": true
}
]
await store.dispatch('users/fetchUsersList', {siteId: 1, mode: "prod"})
const sites = store.getters['users/usersList']
expect(sites).toEqual(expectedData)
})
})

View File

@@ -0,0 +1,16 @@
import {test, describe, expect} from 'vitest'
import { mount} from '@vue/test-utils'
import AppPageHeader from '@atoms/VButton.vue';
describe("tests AppPageHeader component", () => {
test('mount test of AppPageHeader', async () => {
const wrapper = mount(AppPageHeader, {
shallow: true,
})
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,16 @@
import {test, describe, expect} from 'vitest'
import { mount} from '@vue/test-utils'
import NewSiteButton from '@atoms/VButton.vue';
describe("tests NewSiteButton component", () => {
test('mount test of NewSiteButton', async () => {
const wrapper = mount(NewSiteButton, {
shallow: true,
})
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,16 @@
import {test, describe, expect} from 'vitest'
import { mount} from '@vue/test-utils'
import VButton from '@atoms/VButton.vue';
describe("tests VButton component", () => {
test('mount test of VButton', async () => {
const wrapper = mount(VButton, {
shallow: true,
})
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,16 @@
import {test, describe, expect} from 'vitest'
import { mount} from '@vue/test-utils'
import VDoubleSwitch from '@atoms/VDoubleSwitch.vue';
describe("tests VDoubleSwitch component", () => {
test('exist test of VDoubleSwitch', async () => {
const wrapper = mount(VDoubleSwitch, {
shallow: true,
})
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,16 @@
import {test, describe, expect} from 'vitest'
import { mount} from '@vue/test-utils'
import VInput from '@atoms/VInput.vue';
describe("tests VInput component", () => {
test('exist test of VInput', async () => {
const wrapper = mount(VInput, {
shallow: true,
})
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,14 @@
import {test, describe, expect} from 'vitest'
import { mount} from '@vue/test-utils'
import VTextarea from '@atoms/VTextarea.vue';
describe("tests VTextarea component", () => {
test('exist test of VTextarea', async () => {
const wrapper = mount(VTextarea, {
shallow: true,
})
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,32 @@
import {test, describe, expect, vi } from 'vitest'
import { mount} from '@vue/test-utils'
import VTabulator from '@molecules/Tabulator/VTabulator.vue';
describe("tests VTabulator component", () => {
vi.mock('tabulator-tables', () => {
const Tabulator = vi.fn(() => {
return {
getHtml: () => {
return '<div>test</div>'
}
}
})
return {
__esModule: true,
TabulatorFull: Tabulator
}
})
test('exist test of VTabulator', async () => {
const wrapper = mount(VTabulator, {
shallow: true,
})
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,4 @@
class Tabulator {
}
export default Tabulator;

View File

@@ -0,0 +1,114 @@
import { mount} from '@vue/test-utils'
import { expect, test, describe, vi, beforeEach } from 'vitest'
import UsersManager from '@organisms/UsersManager/UsersManager.vue';
import { createStore } from 'vuex'
import {store as services} from '@/store/modules/services';
import {store as users} from '@/store/modules/users';
import axios from "axios";
vi.mock('axios')
describe("tests SitesManagerPage component mounted with vuex", () => {
const store = createStore({
plugins: [],
modules: {
services,
users
},
})
beforeEach(async () => {
store.dispatch('users/resetStore')
store.dispatch('services/resetStore')
const mockData = [
{
"id": 1,
"created_at": "2024-02-22T17:08:37.715772388+03:00",
"updated_at": "2024-02-26T14:11:38.64094899+03:00",
"deleted_at": null,
"name": "jsonplaceholder.typicode.com",
"port": 9965,
"proxy_ip": "172.25.78.153",
"site_ip": "172.25.78.153",
"internet_uri": "localhost",
"description": "localhost",
"is_online": true
}
]
axios.get.mockResolvedValue({
data: mockData,
})
await store.dispatch('services/uploadSites')
store.dispatch('services/uploadAndSelectService', 1)
})
test('test UsersManager mounted with vuex', async () => {
const wrapper = mount(UsersManager, {
shallow: true,
global: {
plugins: [store]
}
})
const componentState = wrapper.vm.componentState
const gridCols = wrapper.vm.gridCols
expect(componentState).toBe('view')
expect(gridCols).toBe('grid-cols-1')
})
test('test UsersManager create user button', async () => {
const wrapper = mount(UsersManager, {
global: {
plugins: [store]
}
})
await wrapper.vm.openUserPanelOfCreate()
let componentState = wrapper.vm.componentState
let gridCols = wrapper.vm.gridCols
let wrapperHtml = wrapper.html()
expect(componentState).toBe('create')
expect(gridCols).toBe('grid-cols-2')
expect(wrapperHtml).toContain("Создать пользователя")
await wrapper.vm.openUserPanelOfSelect()
wrapperHtml = wrapper.html()
componentState = wrapper.vm.componentState
gridCols = wrapper.vm.gridCols
expect(componentState).toBe('select')
expect(gridCols).toBe('grid-cols-2')
expect(wrapperHtml).toContain("Выбрать пользователя")
expect(wrapperHtml).toContain("Выбрать пользователя")
await wrapper.vm.closeUserPanel()
wrapperHtml = wrapper.html()
componentState = wrapper.vm.componentState
gridCols = wrapper.vm.gridCols
expect(componentState).toBe('view')
expect(gridCols).toBe('grid-cols-1')
expect(wrapperHtml).not.toContain("Выбрать пользователя")
expect(wrapperHtml).not.toContain("Создать пользователя")
})
test('test UsersManager select user button', async () => {
const wrapper = mount(UsersManager, {
shallow: true,
global: {
plugins: [store]
}
})
wrapper.vm.openUserPanelOfSelect()
const componentState = wrapper.vm.componentState
const gridCols = wrapper.vm.gridCols
expect(componentState).toBe('select')
expect(gridCols).toBe('grid-cols-2')
})
})

View File

@@ -0,0 +1,16 @@
import {test, describe, expect} from 'vitest'
import { mount} from '@vue/test-utils'
import UsersManagerContainer from '@organisms/UsersManager/UsersManagerContainer.vue';
describe("tests UsersManagerContainer component", () => {
test('mount test of UsersManagerContainer', async () => {
const wrapper = mount(UsersManagerContainer, {
shallow: true,
})
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,16 @@
import {test, describe, expect} from 'vitest'
import { mount} from '@vue/test-utils'
import UsersManagerUsersTable from '@organisms/UsersManager/UsersManagerUsersTable.vue';
describe("tests UsersManagerUsersTable component", () => {
test('mount test of UsersManagerUsersTable', async () => {
const wrapper = mount(UsersManagerUsersTable, {
shallow: true,
})
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,16 @@
import {test, describe, expect} from 'vitest'
import { mount} from '@vue/test-utils'
import UsersManagerTitle from '@organisms/UsersManager/UsersManagerTitle.vue';
describe("tests UsersManagerTitle component", () => {
test('mount test of UsersManagerTitle', async () => {
const wrapper = mount(UsersManagerTitle, {
shallow: true,
})
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,56 @@
import { mount} from '@vue/test-utils'
import { expect, test, describe, vi, beforeEach } from 'vitest'
import UsersManagerUserEditor from '@organisms/UsersManager/UsersManagerUserEditor.vue';
import { createStore } from 'vuex'
import {store as users} from '@/store/modules/users';
import axios from "axios";
vi.mock('axios')
describe("tests UsersManagerUserEditor component mounted with vuex", () => {
const store = createStore({
plugins: [],
modules: {
users
},
})
beforeEach( async () => {
store.dispatch('users/resetStore')
const mockData = [
{
"id": 1,
"created_at": "2024-02-22T17:08:37.715772388+03:00",
"updated_at": "2024-02-26T14:11:38.64094899+03:00",
"deleted_at": null,
"name": "jsonplaceholder.typicode.com",
"port": 9965,
"proxy_ip": "172.25.78.153",
"site_ip": "172.25.78.153",
"internet_uri": "localhost",
"description": "localhost",
"is_online": true
}
]
axios.get.mockResolvedValue({
data: mockData,
})
await store.dispatch('services/uploadSites')
store.dispatch('services/uploadAndSelectService', 1)
})
test('tests UsersManager mounted with vuex', async () => {
const wrapper = mount(UsersManagerUserEditor, {
shallow: true,
global: {
plugins: [store]
}
})
expect(wrapper.exists()).toBe(true)
})
})

View File

@@ -0,0 +1,65 @@
import { mount} from '@vue/test-utils'
import { expect, test, describe, vi } from 'vitest'
import Sites from '@pages/SitesManagerPage/SitesManagerPage.vue';
import { createStore } from 'vuex'
import {store as services} from '@/store/modules/services';
import {store as users} from '@/store/modules/users';
import axios from "axios";
vi.mock('axios')
describe("tests SitesManagerPage component mounted with vuex", () => {
const store = createStore({
plugins: [],
modules: {
services,
users
},
})
const mockData = [
{
"id": 1,
"first_name": "Leanne",
"last_name": "Graham",
"email": "test@mail.ru",
"role": "admin",
"is_active": true
}
]
axios.get.mockResolvedValue({
data: mockData,
})
test('tests App mounted with vuex', async () => {
const wrapper = mount(Sites, {
shallow: true,
global: {
plugins: [store]
}
})
const siteId = 1
const answer = await wrapper.vm.selectSite(siteId, "production")
const usersList = store.getters['users/usersList']
const componentState = store.getters['users/componentState']
const selectedService = store.getters['services/selectedService']
expect(usersList).toEqual([{
"id": 1,
"first_name": "Leanne",
"last_name": "Graham",
"email": "test@mail.ru",
"role": "admin",
"is_active": true
}])
expect(componentState).toEqual('active')
expect(selectedService).not.toBe(null)
expect(answer).toBe("ok")
})
})