import { mount } from '@vue/test-utils';

import { describe, expect, it, vi } from 'vitest';

import ExecResult from '../ExecResult.vue';

vi.mock('#/locales', () => ({
  $t: (key: string) => key,
}));

describe('execResult', () => {
  it('结束节点执行失败时展示工作流错误信息', async () => {
    const wrapper = mount(ExecResult, {
      props: {
        initSignal: false,
        nodeJson: [
          {
            original: {
              data: {
                outputDefs: [],
              },
              type: 'endNode',
            },
          },
        ],
        pollingData: undefined,
        workflowId: 'workflow-1',
      },
      global: {
        stubs: {
          ShowJson: {
            props: ['value'],
            template: '<div data-test="show-json">{{ value }}</div>',
          },
        },
      },
    });

    await wrapper.setProps({
      pollingData: {
        message: 'JavaScript 执行失败（第 3 行，第 5 列）：boom',
        status: 21,
      },
    });

    expect(wrapper.get('[data-test="show-json"]').text()).toContain(
      'JavaScript 执行失败（第 3 行，第 5 列）：boom',
    );
  });
});
