import {test, describe, expect} from 'vitest'
import Service from '@admin_pages/Services/ServicesServiceItem.vue'
import { globalServices } from '@store/modules/services/StaticData'
import { store as logger } from '@/store/modules/logger';
import { mount } from '@vue/test-utils'
import {createStore} from 'vuex'

const store = createStore({
  modules: {
    logger,
    services: globalServices,
  },
})

describe("6_admin_pages, ServicesServiceItem", () => {
  test("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)
  })

  test("renders Service with condition success", async () => {
    const wrapper = mount(Service, {
      global: {
        plugins: [store],
      },
      props: {
        name: '',
      },
    })

    await wrapper.setProps({ name: 'глобальное хранилище' })

    expect(wrapper.html()).toContain('доступен')
  })

  test("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('отключен')
  })

  test("renders Service if not service details", async () => {
    const wrapper = mount(Service, {
      global: {
        plugins: [store],
      },
      props: {
        service: {},
      },
    })

    expect(wrapper.html()).toContain('Сервис глобального хранилища применяется для условно постоянного хранения данных в кэше')
  })

  test("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('... нет описания')
  })

  test("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')
  })
})

