import React, { useEffect } from 'react';
import { teamixTest } from '@teamix/testing-capability';
import { requestList } from './data';

const InnerTest = () => {
  useEffect(() => {
    // 模拟真实环境
    window.postMessage(
      {
        source: 'teamix-test-devtools',
        url: window.location.href,
        event: 'getModuleInfo',
        moduleName: '@teamix/pro',
        moduleVersion: '1.33.14',
      },
      '*',
    );
  }, []);

  useEffect(() => {
    setTimeout(async () => {
      const result = await teamixTest({
        testItem: ['EXAMPLE'],
        element: '#example-1', // 可以用不同ID模拟测试不同页面
        requestList,
      });

      console.log('EXAMPLE 测试结果 => ', result);
    }, 1000);
  }, []);

  return (
    <section>
      <h2>开放能力示例</h2>
      <div id="example-1">
        <div className="teamix-123 abc">teamix前缀类名</div>
        <div className="next-123">next前缀类名</div>
        <div className="teamix-pro-table">类名为teamix-pro</div>
      </div>
      <div id="example-2">
        <div className="teamix-456 def">teamix前缀类名</div>
        <div className="teamix-pro-table">类名为teamix-pro</div>
        <div className="teamix-pro-table">类名为teamix-pro2</div>
      </div>
    </section>
  );
};

export default InnerTest;
