|
|
@@ -219,7 +219,7 @@ describe('AreaSelectForm 集成测试', () => {
|
|
|
render(<TestForm />);
|
|
|
|
|
|
const provinceSelect = screen.getByTestId('test-area-province');
|
|
|
- // 等待省份数据加载
|
|
|
+ // 等待省份数据加载并启用
|
|
|
await waitFor(() => {
|
|
|
expect(provinceSelect).toBeInTheDocument();
|
|
|
expect(provinceSelect).not.toHaveAttribute('disabled');
|
|
|
@@ -246,12 +246,15 @@ describe('AreaSelectForm 集成测试', () => {
|
|
|
fireEvent.click(citySelect);
|
|
|
|
|
|
// 等待城市选项出现 - 城市数据应该是"北京市辖区"
|
|
|
- await waitFor(() => {
|
|
|
- expect(screen.getByText('北京市辖区')).toBeInTheDocument();
|
|
|
+ await waitFor(async () => {
|
|
|
+ const cityOptions = await screen.findAllByText('北京市辖区');
|
|
|
+ expect(cityOptions.length).toBeGreaterThanOrEqual(1);
|
|
|
});
|
|
|
|
|
|
- // 选择北京市辖区(城市)
|
|
|
- fireEvent.click(screen.getByText('北京市辖区'));
|
|
|
+ // 选择北京市辖区(城市)- 使用 findAllByText 获取所有匹配,点击第二个(显示的span)
|
|
|
+ const cityOptions = await screen.findAllByText('北京市辖区');
|
|
|
+ expect(cityOptions.length).toBeGreaterThanOrEqual(2);
|
|
|
+ fireEvent.click(cityOptions[1]);
|
|
|
|
|
|
// 提交表单
|
|
|
const submitButton = screen.getByTestId('submit-button');
|
|
|
@@ -369,13 +372,16 @@ describe('AreaSelectForm 集成测试', () => {
|
|
|
});
|
|
|
|
|
|
// 等待城市选项出现 - 城市数据应该是"北京市辖区"
|
|
|
- await waitFor(() => {
|
|
|
- expect(screen.getByText('北京市辖区')).toBeInTheDocument();
|
|
|
+ await waitFor(async () => {
|
|
|
+ const cityOptions = await screen.findAllByText('北京市辖区');
|
|
|
+ expect(cityOptions.length).toBeGreaterThanOrEqual(1);
|
|
|
});
|
|
|
|
|
|
- // 选择北京市辖区(城市)
|
|
|
+ // 选择北京市辖区(城市)- 使用 findAllByText 获取所有匹配,点击第二个(显示的span)
|
|
|
+ const cityOptions = await screen.findAllByText('北京市辖区');
|
|
|
+ expect(cityOptions.length).toBeGreaterThanOrEqual(2);
|
|
|
await act(async () => {
|
|
|
- fireEvent.click(screen.getByText('北京市辖区'));
|
|
|
+ fireEvent.click(cityOptions[1]);
|
|
|
});
|
|
|
|
|
|
// 等待区县选择启用
|
|
|
@@ -391,13 +397,16 @@ describe('AreaSelectForm 集成测试', () => {
|
|
|
});
|
|
|
|
|
|
// 等待区县选项出现
|
|
|
- await waitFor(() => {
|
|
|
- expect(screen.getByText('东城区')).toBeInTheDocument();
|
|
|
+ await waitFor(async () => {
|
|
|
+ const districtOptions = await screen.findAllByText('东城区');
|
|
|
+ expect(districtOptions.length).toBeGreaterThanOrEqual(1);
|
|
|
});
|
|
|
|
|
|
- // 选择东城区
|
|
|
+ // 选择东城区 - 使用 findAllByText 获取所有匹配,点击第二个(显示的span)
|
|
|
+ const districtOptions = await screen.findAllByText('东城区');
|
|
|
+ expect(districtOptions.length).toBeGreaterThanOrEqual(2);
|
|
|
await act(async () => {
|
|
|
- fireEvent.click(screen.getByText('东城区'));
|
|
|
+ fireEvent.click(districtOptions[1]);
|
|
|
});
|
|
|
|
|
|
// 提交表单
|