Files
jiapu/tests/profile-pages.test.js
T
2026-07-24 18:11:32 +08:00

90 lines
3.0 KiB
JavaScript

const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const test = require('node:test');
const ProfilePages = require('../public/js/profile-pages.js');
const RegionPages = require('../public/js/region-pages.js');
const UploadPages = require('../public/js/upload-pages.js');
test('profile view reads only the documented profile fields', () => {
assert.deepEqual(ProfilePages.buildProfileView({
nickName: '小林',
phone: '13800000000',
birthday: '1990-01-01',
provinceCode: '11',
userName: '不应读取',
mobile: '不应读取'
}), {
displayName: '小林',
avatarText: '小',
phone: '13800000000',
sex: '待填写',
birthday: '1990-01-01',
regionText: '加载中...'
});
assert.deepEqual(ProfilePages.buildProfileView({
userName: '不应读取',
phonenumber: '不应读取',
mobile: '不应读取'
}), {
displayName: '未设置昵称',
avatarText: '家',
phone: '未绑定',
sex: '待填写',
birthday: '待填写',
regionText: '待填写'
});
});
test('profile update preserves int64 OSS IDs as text', () => {
assert.deepEqual(ProfilePages.buildProfileUpdateBody({
nickName: '小林',
avatarOssId: '2060000000000000000',
sex: '0',
birthday: '1990-01-01',
provinceCode: '11',
cityCode: '1101',
districtCode: '110101'
}), {
nickName: '小林',
avatarOssId: '2060000000000000000',
sex: '0',
birthday: '1990-01-01',
provinceCode: '11',
cityCode: '1101',
districtCode: '110101'
});
assert.equal(typeof ProfilePages.buildProfileUpdateBody({ avatarOssId: '2060000000000000000' }).avatarOssId, 'string');
assert.equal(UploadPages.normalizeUploadResult({ ossId: '2060000000000000000' }).ossId, '2060000000000000000');
});
test('region selector accepts only documented region fields and levels', () => {
assert.deepEqual(RegionPages.normalizeList({ data: [{ regionCode: '11' }] }), []);
assert.equal(RegionPages.getRegionCode({ value: '11' }), '');
assert.equal(RegionPages.getRegionName({ label: '北京市' }), '未命名地区');
assert.equal(RegionPages.getRegionLevel({ regionCode: '110101' }), 0);
assert.deepEqual(RegionPages.buildRegionSelection([
{ regionCode: '11', regionName: '北京市', regionLevel: 1 },
{ regionCode: '1101', regionName: '市辖区', regionLevel: 2 },
{ regionCode: '110101', regionName: '东城区', regionLevel: 3 }
]), {
provinceCode: '11',
cityCode: '1101',
districtCode: '110101'
});
});
test('profile data page contains PC profile, upload and region flow markers', () => {
const source = fs.readFileSync(path.join(__dirname, '..', 'profile-data.html'), 'utf8');
assert.match(source, /data-profile-form/);
assert.match(source, /name="avatarOssId"/);
assert.match(source, /data-region-profile-form/);
assert.match(source, /data-region-profile-status/);
assert.match(source, /src="public\/js\/upload-pages\.js"/);
assert.match(source, /src="public\/js\/region-pages\.js"/);
});