Files
MinigameTest/check_work.js

113 lines
3.0 KiB
JavaScript
Raw Normal View History

2023-03-07 10:52:05 +07:00
// Danh sách công việc
const checkList = [
{
id: 'form-thoi-gian-dem-nguoc',
label: 'Thời gian đếm ngược',
func: checkTimeDown,
},
{
id: 'form-dang-nhap',
label: 'Form đăng nhập thông tin',
func: checkFormLogin,
},
{
id: 'form-trang-thai-nguoi-choi',
label: 'Hiển thị trạng thái người chơi',
func: checkPlayerPresent,
},
{
id: 'form-danh-sach-giai-thuong',
label: 'Hiển thị danh sách giải thưởng',
func: checkRewardList,
},
{
id: 'form-danh-sach-nguoi-choi-trung-giai',
label: 'Hiển thị danh sách người chơi trúng giải',
func: checkWinerRecentList,
},
{
id: 'form-the-le-chuong-trinh',
label: 'Hiển thị thể lệ chương trình',
func: checkPolicyGame,
},
{
id: 'form-luot-choi-toi-da',
label: 'Số lượt chơi tối đa',
},
{
id: 'form-chon-giai-thuong',
label: 'Chọn giải thưởng',
},
]
// FUNCTION
// Hàm check PASSED/FAILED
function checkListForm(id, condition) {
switch (condition) {
case true:
$(`#js-${id}`).html("<span style='font-weight:700;color:green;'>PASSED</span>");
break;
case false:
$(`#js-${id}`).html("<span style='font-weight:700;color:red;'>FAILED</span>");
break;
default:
$(`#js-${id}`).html(`<span style='font-weight:700;color:green;'>${condition}</span>`);
break;
}
};
// Kiểm tra thời gian chơi game còn lại
function checkTimeDown() {
let check_id_time = $("#js-time-game-left")
return new Promise((resolve, reject) => {
let check_1 = check_id_time.html();
setTimeout(() => {
let check_2 = check_id_time.html();
resolve(check_2 !== check_1);
}, 2000);
});
}
// Kiểm tra các ô điền thông tin người chơi đã đủ chưa
function checkFormLogin() {
const game_info = Adman.MiniGame.getInfo();
const requireEmail = game_info.rules.require_email_before_play;
const requireTel = game_info.rules.require_mobile_before_play;
const requireName = game_info.rules.require_name_before_play;
const totalRequire = requireEmail + requireTel + requireName;
const totalRequireInput = $("#js-user-info input").length;
return totalRequire === totalRequireInput;
}
// Kiểm tra người chơi dang xem - dang choi - da choi
function checkPlayerPresent() {
const checkHtml = $(".js-users-status-online").html();
return checkHtml !== "999";
}
// Kiểm tra danh sách giải thưởng
function checkRewardList() {
const checkHtml = $("#js-reward-product-list").html();
return checkHtml !== "";
}
// Kiểm tra danh sách người chơi trúng giải
function checkWinerRecentList() {
const checkHtml = $("#js-recent-winners").html();
return checkHtml !== "";
}
// Kiểm tra danh sách người chơi trúng giải
function checkPolicyGame() {
const checkHtml = $("#js-game-policy").html();
return checkHtml !== "";
}
const check_work = {
checkList,
checkListForm
}
module.exports = check_work;