/* tslint:disable max-line-length */ import { vitest } from 'vitest'; import { type MountingOptions, shallowMount } from '@vue/test-utils'; import sinon, { type SinonStubbedInstance } from 'sinon'; import { type RouteLocation } from 'vue-router'; import UserAccountDetails from './user-account-details.vue'; import UserAccountService from './user-account.service'; import AlertService from '@/shared/alert/alert.service'; type UserAccountDetailsComponentType = InstanceType; let route: Partial; const routerGoMock = vitest.fn(); vitest.mock('vue-router', () => ({ useRoute: () => route, useRouter: () => ({ go: routerGoMock }), })); const userAccountSample = { id: 123 }; describe('Component Tests', () => { let alertService: AlertService; afterEach(() => { vitest.resetAllMocks(); }); describe('UserAccount Management Detail Component', () => { let userAccountServiceStub: SinonStubbedInstance; let mountOptions: MountingOptions['global']; beforeEach(() => { route = {}; userAccountServiceStub = sinon.createStubInstance(UserAccountService); alertService = new AlertService({ bvToast: { toast: vitest.fn(), } as any, }); mountOptions = { stubs: { 'font-awesome-icon': true, 'router-link': true, }, provide: { alertService, userAccountService: () => userAccountServiceStub, }, }; }); describe('Navigate to details', () => { it('Should call load all on init', async () => { // GIVEN userAccountServiceStub.find.resolves(userAccountSample); route = { params: { userAccountId: `${123}`, }, }; const wrapper = shallowMount(UserAccountDetails, { global: mountOptions }); const comp = wrapper.vm; // WHEN await comp.$nextTick(); // THEN expect(comp.userAccount).toMatchObject(userAccountSample); }); }); describe('Previous state', () => { it('Should go previous state', async () => { userAccountServiceStub.find.resolves(userAccountSample); const wrapper = shallowMount(UserAccountDetails, { global: mountOptions }); const comp = wrapper.vm; await comp.$nextTick(); comp.previousState(); await comp.$nextTick(); expect(routerGoMock).toHaveBeenCalledWith(-1); }); }); }); });