<%_
const tsKeyId = user.primaryKey.tsSampleValues[0];
_%>
import { beforeEach, describe, expect, it, vitest } from 'vitest';
import { shallowMount } from '@vue/test-utils';
import axios from 'axios';
import sinon from 'sinon';
import { type RouteLocation } from 'vue-router';

import AlertService from '@/shared/alert/alert.service';
import UserManagementView from './user-management-view.vue';
import { Authority } from '@/shared/jhipster/constants';

let route: Partial<RouteLocation>;

vitest.mock('vue-router', () => ({
  useRoute: () => route,
}));

const axiosStub = {
  get: sinon.stub(axios, 'get'),
};

describe('UserManagementView Component', () => {
  let alertService: AlertService;

  beforeEach(() => {
    route = {};
    alertService = new AlertService({
<%_ if (enableTranslation) { _%>
      i18n: { t: vitest.fn() } as any,
<%_ } _%>
      toast: {
        show: vitest.fn(),
      } as any,
    });
  });

  describe('OnInit', () => {
    it('Should call load all on init', async () => {
      // GIVEN
      const userData = {
        id: 1,
        login: 'user',
        firstName: 'first',
        lastName: 'last',
        email: 'first@last.com',
        activated: true,
        langKey: 'en',
        authorities: [Authority.USER],
        createdBy: 'admin',
        createdDate: null,
        lastModifiedBy: null,
        lastModifiedDate: null,
        password: null,
      };
      axiosStub.get.resolves({ data: userData });

      route = {
        params: {
          userId: '' + <%- tsKeyId %>,
        },
      };

      const wrapper = shallowMount(UserManagementView, {
        global: {
          stubs: {
            'b-badge': true,
            'router-link': true,
            'font-awesome-icon': true,
          },
          provide: {
            alertService,
          },
        },
      });
      const userManagementView = wrapper.vm;

      // WHEN
      await userManagementView.$nextTick();

      // THEN
      expect(axiosStub.get.calledWith('api/admin/users/' + <%- tsKeyId %>)).toBeTruthy();
      expect(userManagementView.user).toEqual(userData);
    });
  });
});
