feat: 增强地址处理逻辑,支持日本地区并优化相关测试用例
This commit is contained in:
@@ -9,6 +9,7 @@ test('address sources normalize supported countries and return local seeds', ()
|
||||
|
||||
assert.equal(api.normalizeCountryCode('Deutschland'), 'DE');
|
||||
assert.equal(api.normalizeCountryCode('澳大利亚'), 'AU');
|
||||
assert.equal(api.normalizeCountryCode('日本'), 'JP');
|
||||
assert.equal(api.normalizeCountryCode('unknown'), '');
|
||||
|
||||
const deSeed = api.getAddressSeedForCountry('DE');
|
||||
@@ -20,4 +21,8 @@ test('address sources normalize supported countries and return local seeds', ()
|
||||
const fallbackSeed = api.getAddressSeedForCountry('unknown', { fallbackCountry: 'AU' });
|
||||
assert.equal(fallbackSeed.countryCode, 'AU');
|
||||
assert.equal(fallbackSeed.fallback.region, 'New South Wales');
|
||||
|
||||
const jpSeed = api.getAddressSeedForCountry('日本');
|
||||
assert.equal(jpSeed.countryCode, 'JP');
|
||||
assert.equal(jpSeed.fallback.region, 'Tokyo');
|
||||
});
|
||||
|
||||
@@ -253,3 +253,89 @@ return { selectRegionDropdown };
|
||||
|
||||
assert.deepEqual(clicks, [stateDropdown, options[1]]);
|
||||
});
|
||||
|
||||
test('country and region helpers recognize the dropdown-style localized address form', () => {
|
||||
const bundle = [
|
||||
extractFunction('isVisibleElement'),
|
||||
extractFunction('normalizeText'),
|
||||
extractFunction('getActionText'),
|
||||
extractFunction('getFieldText'),
|
||||
extractFunction('getVisibleControls'),
|
||||
extractFunction('isEnabledControl'),
|
||||
extractFunction('isDocumentLevelContainer'),
|
||||
extractFunction('getCountryCandidates'),
|
||||
extractFunction('matchesCountryOption'),
|
||||
extractFunction('findCountryDropdown'),
|
||||
extractFunction('getRegionCandidates'),
|
||||
extractFunction('matchesRegionOption'),
|
||||
extractFunction('findRegionDropdown'),
|
||||
].join('\n');
|
||||
|
||||
const countryDropdown = createElement({
|
||||
tagName: 'DIV',
|
||||
text: '国家或地区 日本',
|
||||
attrs: {
|
||||
role: 'combobox',
|
||||
'aria-haspopup': 'listbox',
|
||||
},
|
||||
});
|
||||
const regionDropdown = createElement({
|
||||
tagName: 'DIV',
|
||||
text: '辖区 选择',
|
||||
attrs: {
|
||||
role: 'combobox',
|
||||
'aria-haspopup': 'listbox',
|
||||
},
|
||||
});
|
||||
const elements = [countryDropdown, regionDropdown];
|
||||
const documentMock = {
|
||||
documentElement: {},
|
||||
body: {},
|
||||
querySelectorAll: (selector) => {
|
||||
if (String(selector || '').includes('label[for=')) return [];
|
||||
if (String(selector || '').includes('combobox') || String(selector || '').includes('button') || String(selector || '').includes('select')) {
|
||||
return elements;
|
||||
}
|
||||
return [];
|
||||
},
|
||||
};
|
||||
const windowMock = {
|
||||
getComputedStyle: () => ({ display: 'block', visibility: 'visible' }),
|
||||
};
|
||||
const cssMock = {
|
||||
escape: (value) => String(value),
|
||||
};
|
||||
|
||||
const api = new Function('window', 'document', 'CSS', `
|
||||
${bundle}
|
||||
return { findCountryDropdown, findRegionDropdown, matchesCountryOption, matchesRegionOption };
|
||||
`)(windowMock, documentMock, cssMock);
|
||||
|
||||
assert.equal(api.findCountryDropdown(), countryDropdown);
|
||||
assert.equal(api.findRegionDropdown(), regionDropdown);
|
||||
assert.equal(api.matchesCountryOption('日本', 'JP'), true);
|
||||
assert.equal(api.matchesCountryOption('德国', 'DE'), true);
|
||||
assert.equal(api.matchesRegionOption('東京都', 'Tokyo'), true);
|
||||
});
|
||||
|
||||
test('fillIfEmpty can overwrite invalid structured address values in the dropdown branch', () => {
|
||||
const bundle = [
|
||||
extractFunction('fillIfEmpty'),
|
||||
].join('\n');
|
||||
const input = { value: '77022' };
|
||||
const writes = [];
|
||||
const api = new Function('input', 'writes', `
|
||||
function fillInput(el, value) {
|
||||
writes.push(value);
|
||||
el.value = value;
|
||||
}
|
||||
${bundle}
|
||||
return { fillIfEmpty };
|
||||
`)(input, writes);
|
||||
|
||||
assert.equal(api.fillIfEmpty(input, '100-0005'), false);
|
||||
assert.equal(input.value, '77022');
|
||||
assert.equal(api.fillIfEmpty(input, '100-0005', { overwrite: true }), true);
|
||||
assert.equal(input.value, '100-0005');
|
||||
assert.deepEqual(writes, ['100-0005']);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user