68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
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 App 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")
|
|
})
|
|
})
|
|
|
|
|