修改底层请求逻辑,封装请求方法
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const CaptchaPages = require('../public/js/captcha-pages.js');
|
||||
|
||||
const fakeApi = {
|
||||
@@ -7,6 +9,14 @@ const fakeApi = {
|
||||
};
|
||||
|
||||
function run() {
|
||||
const captchaSource = fs.readFileSync(path.join(__dirname, '..', 'public', 'js', 'captcha-pages.js'), 'utf8');
|
||||
|
||||
assert.strictEqual(captchaSource.includes('auth-captcha-modal'), false, '验证码适配层不应控制自定义弹窗样式');
|
||||
assert.strictEqual(captchaSource.includes('bgUrl:'), false, '验证码适配层不应覆盖 TAC 背景样式');
|
||||
assert.strictEqual(captchaSource.includes('logoUrl:'), false, '验证码适配层不应覆盖 TAC Logo 样式');
|
||||
assert.strictEqual(captchaSource.includes('root.layui.layer.open'), true, '验证码适配层应使用 Layui 默认弹层承载 TAC');
|
||||
assert.strictEqual(captchaSource.includes('root.layui.layer.close'), true, '验证码结束时应关闭对应 Layui 弹层');
|
||||
|
||||
assert.deepStrictEqual(CaptchaPages.buildChallengeBody({
|
||||
sceneCode: 'WEB_H5_LOGIN',
|
||||
subject: '13800000000'
|
||||
@@ -81,23 +91,49 @@ function run() {
|
||||
required: true
|
||||
}), true);
|
||||
|
||||
const modalBox = { nodeName: 'modal' };
|
||||
const formBox = { nodeName: 'form-box' };
|
||||
const originalDocument = global.document;
|
||||
const originalLayui = global.layui;
|
||||
const mountedBox = {
|
||||
innerHTML: '<div class="tianai-captcha-parent"></div>'
|
||||
};
|
||||
let layerOptions;
|
||||
let closedLayerIndex;
|
||||
|
||||
global.document = {
|
||||
querySelector(selector) {
|
||||
return selector === '.auth-captcha-modal[data-captcha-box]' ? modalBox : null;
|
||||
assert.strictEqual(selector, '[data-captcha-layer-box="captcha-layer-1"]');
|
||||
return mountedBox;
|
||||
}
|
||||
};
|
||||
global.layui = {
|
||||
layer: {
|
||||
open(options) {
|
||||
layerOptions = options;
|
||||
return 7;
|
||||
},
|
||||
close(index) {
|
||||
closedLayerIndex = index;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
assert.strictEqual(CaptchaPages.getCaptchaBox({
|
||||
querySelector(selector) {
|
||||
return selector === '[data-captcha-box]' ? formBox : null;
|
||||
}
|
||||
}), modalBox);
|
||||
const captchaLayer = CaptchaPages.createCaptchaLayer();
|
||||
assert.strictEqual(captchaLayer.box, mountedBox);
|
||||
assert.strictEqual(captchaLayer.layerIndex, 7);
|
||||
assert.strictEqual(layerOptions.type, 1);
|
||||
assert.strictEqual(layerOptions.title, false);
|
||||
assert.strictEqual(layerOptions.closeBtn, 0);
|
||||
assert.deepStrictEqual(layerOptions.area, ['318px', '318px']);
|
||||
assert.strictEqual(layerOptions.offset, 'auto');
|
||||
assert.strictEqual(typeof layerOptions.content, 'string');
|
||||
assert.strictEqual(layerOptions.content.includes('data-captcha-layer-box="captcha-layer-1"'), true);
|
||||
|
||||
CaptchaPages.closeCaptchaLayer(captchaLayer);
|
||||
assert.strictEqual(mountedBox.innerHTML, '');
|
||||
assert.strictEqual(closedLayerIndex, 7);
|
||||
|
||||
global.document = originalDocument;
|
||||
global.layui = originalLayui;
|
||||
|
||||
console.log('captcha-pages tests passed');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user