Przeglądaj źródła

fix: [AE-会员端] 修改bug

bill 2 tygodni temu
rodzic
commit
e66ea43565

+ 23 - 5
docs/refactor/signup-welcome-pack.md

@@ -1,12 +1,14 @@
 # 注册页 Welcome Pack 功能迁移
 
 创建日期:2026-10-09  
-更新日期:2026-10-28
+更新日期:2026-10-29
 
 状态:注册与会员报单已共用页面、表单、商品及支付弹窗,通过两条原路由指定模式;真实后端、订单确认和支付待联调。
 
 第 1~6 节描述当前源码,第 7 节保留最初迁移时的验证记录,第 8 节说明本次文档核对范围。早期会员报单、删除订单、成功倒计时等行为不能继续作为当前游客注册页的实现说明。
 
+最新推荐人国家绑定与分步展示规则、验证结果见第 11 节。
+
 ## 1. 授权与边界
 
 **初始授权**:用户要求将 `src/views/user/welcome-pack.vue` 的功能迁入新注册 UI,旧页不动、优先使用 Element UI。2026-10-28 按用户批准方案,两条入口已统一挂载 `src/ui-refactor/views/welcome-pack/MemberWelcomePack.vue`,共享视图仍位于 `src/ui-refactor/views/signup/SignupPage.vue`。
@@ -57,9 +59,9 @@
 
 以当前源码为准;旧计价与字段兼容规则继续保留,游客身份和支付按后续需求调整。
 
-1. 国家 / 语言来自页面私有固定选项,不请求 `getCountries` / `getLanguages`,不依赖 Vuex 列表缓存,不修改全局当前语言。
-2. 国家变化调用 `GET /v1/user/guest-dec?countryId=...`;读取 `data.draft`,会员编号来自 `draft.insertUserName`,币种优先 `draft.currency`,无值时回退首个商品的 `CODE`。支付方式优先 `payList`,兼容旧 `sellType[0].sell_type`。
-3. 推荐人使用 `GET /v1/user/guest-full-info`,参数 `userName`;实际推荐人使用 `GET /v1/user/guest-inspect-network`,参数 `recommenderName` / `recommenderActualName`;姓名读取 `data.REAL_NAME`。这些方法放在 `src/api/user.js`,不影响旧会员查询方法。
+1. 注册国家固定开放 Nigeria(`620699181539139625`)和 UAE(`620699181539139643`),均默认使用已有 English 选项;语言仍为原中文 / English。不请求 `getCountries` / `getLanguages`,不依赖 Vuex 列表缓存,不修改全局当前语言。
+2. 先查询 Referrer ID,按用户确认的返回字段 **`data.countryId`** 匹配上述固定国家 ID,自动选中且只读;不依据会员编号前缀推断。匹配后调用 `GET /v1/user/guest-dec?countryId=...`,读取 `data.draft`,会员编号来自 `draft.insertUserName`,币种优先 `draft.currency`,无值时回退首个商品的 `CODE`。支付方式优先 `payList`,兼容旧 `sellType[0].sell_type`。
+3. 推荐人使用 `GET /v1/user/guest-full-info`,参数 `userName`;实际推荐人使用 `GET /v1/user/guest-inspect-network`,参数 `recommenderName` / `recommenderActualName`;姓名读取 `data.REAL_NAME`。这些方法放在 `src/api/user.js`,不影响旧会员查询方法。国家缺失、非支持国家或推荐人查询失败时不初始化注册草稿、不允许提交。
 4. 商品提交仍使用 `goodsId` 与 `goodsNum` 数组,`decWay: '2'`、`decType: 'normal'`、`location: 1`。
 5. 汇总与余额校验使用 **MARKET_PRICE × 数量**;销售价仍展示。BV 与含税金额继续调用原算法,没有按截图改成销售价计价。
 6. 保留原等级、中心编号、商品和现金余额校验;根据用户明确需求新增推荐人 / 实际推荐人必填检查,空值和纯空格阻止创建订单。不从参考页面引入额外密码、邮箱或用户名规则,后端反馈继续使用既有请求及提示机制。
@@ -69,7 +71,9 @@
 10. 关闭弹窗仅隐藏,不删除订单。每次有效点击 Continue Payment 都重新校验当前表单并调用 `POST /v1/user/guest-dec`,成功后使用本次返回的支付信息打开弹窗;请求中阻止重复点击,失败或缺少交易标识时不打开旧支付信息。是否复用已有后台订单由接口决定。SDK 内仍防止重复打开,支付回调的 `reference` 必须与最新订单一致;随后显示 Payment Successful 弹窗,点击 Got it 后使用 `replace` 跳转 `/login`,保留原查询参数,没有自动跳转或倒计时。取消支付、请求失败或回调不匹配时不显示成功弹窗、不跳转。
 11. 按 2026-10-28 用户要求,成功弹窗中的 Member ID 使用本次 `POST /v1/user/guest-dec` 请求的 `insertUserName` 快照,不依赖成功响应或支付回调返回会员编号,也不读取之后被修改的表单。提供 Copy 按钮并复用既有剪贴板反馈,缺失编号显示 `—` 且禁用复制。弹窗不允许遮罩、Escape 或关闭按钮跳过确认;重复成功回调不重开弹窗、不重复导航。`paymentComplete` 后提交按钮显示 Registration Complete! 并禁用。成功触发点仍是匹配的前端支付回调,本次不新增服务端确认查询。
 
-邀请链接形如 `/#/login?ref=会员ID`,登录页 Register 已透传查询参数。注册页创建时读取单个字符串 `ref`,去掉首尾空格后同时作为 `form.recUserName` 和 `form.conUserName` 的默认值;没有有效 `ref` 时留空,不猜测推荐人。初始化不触发推荐人查询或其他接口,也不反复覆盖手动修改;两项始终可编辑。手动更改推荐人仍会清空实际推荐人,需要重新填写并确认关系。Save 和 Continue Payment 都传递用户当前填写的两项。
+邀请链接形如 `/#/login?ref=会员ID`,登录页 Register 已透传查询参数。注册页创建时读取单个字符串 `ref`,去掉首尾空格后同时作为 `form.recUserName` 和 `form.conUserName` 的默认值,并查询推荐人国家;此初始查询保留两项预填值。没有有效 `ref` 时留空,不猜测推荐人。手动更改推荐人仍会清空实际推荐人,需要重新填写并确认关系;输入新推荐人时立即清空旧国家、草稿、商品选择、地区 / 银行选项和旧支付信息。独立请求序号防止较早的推荐人或草稿响应覆盖新结果,销毁时忽略迟到响应。Save 和 Continue Payment 都再次检查当前推荐人及国家是否与已验证结果一致,再传递用户当前填写的两项。
+
+2026-10-29 按用户提供的新注册流程,未验证推荐人时只展示 Network Information、Save 和返回登录入口;查询失败在推荐人字段下显示错误,查询成功显示有效提示,再展开基础信息、商品及后续表单。Country 显示继承说明并禁用修改。会员报单模式继续按账户初始化国家、直接展示原表单,不套用游客推荐人验证门槛。
 
 ## 5. 新 UI 必需的适配
 
@@ -132,3 +136,17 @@
 - 先运行新回归用例确认旧逻辑下 4 项失败,再修改实现;两份支付 / 注册测试合计 43 项通过,覆盖连续请求、最新表单、请求并发、失败、不完整响应和原表单校验。定向 lint 为 0 error / 0 warning。
 - Chromium 在本地开发服务验证两次 Continue Payment 均发送 POST、使用最新邮箱 / 商品数量并展示本次返回金额;第三次模拟失败时弹窗保持关闭。API 和 SDK 均拦截替换,没有创建真实订单或触发真实支付。
 - 本轮未运行生产构建或真实后端联调,后台订单复用策略仍由接口决定;未提交或推送 Git。
+
+## 11. 推荐人国家强绑定与分步展示(2026-10-29)
+
+- 用户要求注册开放 UAE,国家与 Referrer ID 查询结果强绑定,并确认国家字段为 `response.data.countryId`。仅匹配固定 Nigeria / UAE ID,不根据 `NG`、`AE` 等会员编号前缀推断;缺失或不支持的国家不会初始化草稿。
+- 初始只显示 Network Information、Save 和返回登录;推荐人失败信息在字段下展示,成功显示有效提示并展开基础信息、商品和后续表单。Country 禁止修改,保留已有 Element UI 控件及全局主题;新增反馈样式仅在共享字段组件内作用。
+- 邀请链接自动验证并保留两项推荐人预填值。编辑推荐人立即清空旧国家、草稿、商品、地区 / 银行选项与旧支付信息;推荐人查询和草稿请求各自使用序号,较旧或销毁后的响应不得覆盖新状态。个人资料输入保留。
+- 创建订单前检查推荐人和国家是否仍与已验证结果一致;请求和支付弹窗期间锁定表单,阻止中途改换推荐人。会员报单仍按账户国家初始化,API、价格计算、POST 字段及支付协议保持。
+- 基线 115 项注册 / 会员报单回归通过;实施后 134 项全部通过,其中新增 16 项国家绑定业务用例和 3 项界面状态用例。旧支付、市场价、成功弹窗和会员流程断言均保留,旧用例的前置数据按“已验证国家”更新。
+- 定向 lint(8 个 JS / Vue / CJS 文件)、生产构建、36 组隔离浏览器视口检查通过。覆盖初始、无效推荐人、Nigeria、UAE、邀请链接、会员报单六种状态,320 / 375 / 768 / 1024 / 1440px 及短视口;校验国家只读、实际国家请求、编辑后重置、页头 / 表单展示,无页面错误或未声明网络请求。已检查桌面 UAE 和移动端错误状态截图。
+- 测试使用隔离样例,没有真实注册、真实推荐关系或 UAE 支付联调;后端仍需在授权环境验证该国家的草稿、商品与支付支持。没有修改接口、依赖、配置、旧业务页或全局样式。
+
+证据目录:`C:/Users/Administrator/AppData/Local/Temp/ng-registration-country-20261029-160354`,包含基线与最终测试 JSON、构建日志、浏览器结果及状态截图。
+
+交付前对照任务开始时的 510 个项目文件哈希:仅 8 个本轮相关已有文件修改,新增 1 个国家绑定测试,无删除;另有 `.idea/workspace.xml` 的并发变化,本轮未写入或回滚。接口、Store、旧页面、全局样式、环境和依赖文件保持。未提交、推送或发布。

+ 12 - 1
src/ui-refactor/views/signup/SignupPage.vue

@@ -13,6 +13,9 @@
         :form="form"
         :guest="isGuest"
         :countries="countriesList"
+        :country-locked="isGuest"
+        :registration-ready="!isGuest || referrerCountryValid"
+        :referrer-error="isGuest ? referrerError : ''"
         :country-name="countryName"
         :languages="formLanguages"
         :levels="allDecLevel"
@@ -45,6 +48,7 @@
         </ui-section-card>
       </welcome-pack-fields>
       <payment-methods
+        v-if="!isGuest || referrerCountryValid"
         v-model="form.payType"
         :options="payList"
         :currency="currencyUnitCode"
@@ -123,7 +127,11 @@ export default {
       if (this.isGuest) return this.loading || this.submitButtonStat || this.visible || this.paymentComplete
       return this.loading || this.submitButtonStat || this.visible || this.payDialog || this.cancelLoading || this.orderListOpened
     },
-    formDisabled() { return !this.isGuest && (this.busy || !this.initialized) },
+    formDisabled() {
+      return this.isGuest
+        ? this.submitButtonStat || this.visible || this.paymentComplete
+        : this.busy || !this.initialized
+    },
     paymentBalances() { return this.isGuest ? this.userBalance : { cash: this.userBalance.cash } },
     paymentSummary() {
       const balance = this.paymentBalances[this.form.payType]
@@ -141,6 +149,9 @@ export default {
   methods: {
     updateForm(patch) {
       if (this.formDisabled) return
+      if (this.isGuest && 'recUserName' in patch && patch.recUserName !== this.form.recUserName) {
+        this.invalidateReferrerCountry()
+      }
       Object.assign(this.form, patch)
       if ('way' in patch) this.wayChange()
     },

+ 88 - 26
src/ui-refactor/views/signup/components/welcomePackRegistration.js

@@ -15,6 +15,11 @@ export default {
       loading: false,
       loadingTimer: null,
       draft: {},
+      referrerCountryId: '',
+      checkedReferrer: '',
+      referrerError: '',
+      referrerRequestId: 0,
+      countryRequestId: 0,
 
       // 公开注册页使用固定选项,不依赖后台国家、语言列表请求或缓存。
       countriesList: [
@@ -22,6 +27,11 @@ export default {
           ID: '620699181539139625',
           NAME: 'Nigeria',
           DEFAULT_LANGUAGE_ID: '620713695651307520'
+        },
+        {
+          ID: '620699181539139643',
+          NAME: 'UAE',
+          DEFAULT_LANGUAGE_ID: '620713695651307520'
         }
       ],
       languageList: [
@@ -113,21 +123,29 @@ export default {
     }
   },
   computed: {
+    referrerCountryValid() {
+      return Boolean(this.checkedReferrer && this.checkedReferrer === this.form.recUserName.trim() &&
+        this.form.countryId === this.referrerCountryId &&
+        this.countriesList.some(country => country.ID === this.referrerCountryId))
+    },
     submitLabel() {
       if (this.paymentComplete) return 'Registration Complete!'
       return this.paymentOrder.accessCode ? 'Continue Payment' : 'Save'
     }
   },
   created() {
-    // 邀请链接只提供初始值,不覆盖用户后续编辑,也不触发推荐人变更时的清空逻辑。
+    // 邀请链接预填网络编号,再查询推荐人国家;初始查询保留实际推荐人。
     const ref = this.$route && this.$route.query.ref
     if (typeof ref === 'string') {
       this.form.recUserName = ref.trim()
       this.form.conUserName = ref.trim()
+      if (ref.trim()) this.handleChkRecUser(false)
     }
   },
   beforeDestroy() {
     clearTimeout(this.loadingTimer)
+    this.referrerRequestId++
+    this.countryRequestId++
   },
   watch: {
     isDec: {
@@ -139,13 +157,48 @@ export default {
     }
   },
   methods: {
+    invalidateReferrerCountry() {
+      this.referrerRequestId++
+      this.countryRequestId++
+      clearTimeout(this.loadingTimer)
+      this.loading = false
+      this.checkedReferrer = this.referrerCountryId = ''
+      this.referrerError = ''
+      this.recRealName = '-'
+      this.draft = {}
+      Object.assign(this.form, {
+        countryId: '', languageId: '', insertUserName: '', decLv: '', decUserName: '',
+        areaSelected: [], bankAreaSelected: [], openBank: '', payType: '',
+        goodsId: [], goodsNum: [], cityName: '', lgaName: ''
+      })
+      this.allGoods = []
+      this.tableData = []
+      this.regionData = []
+      this.allDecLevel = []
+      this.allOpenBank = []
+      this.storeNums = []
+      this.multipleSelection = []
+      this.payList = []
+      this.userBalance = { cash: 0 }
+      this.currencyUnitCode = ''
+      this.isDec = null
+      this.sellPriceSum = this.pricePvSum = this.taxSum = this.payAmount = 0
+      this.paymentOrder = { orderSn: '', amount: 0, currency: '', reference: '', accessCode: '' }
+    },
     countriesChange() {
-      const country = this.countriesList.find(item => item.ID === this.form.countryId)
-      if (country) this.form.languageId = country.DEFAULT_LANGUAGE_ID
+      const country = this.countriesList.find(item => item.ID === this.referrerCountryId)
+      if (!country || this.checkedReferrer !== this.form.recUserName.trim()) {
+        this.invalidateReferrerCountry()
+        return
+      }
+      this.form.countryId = country.ID
+      this.form.languageId = country.DEFAULT_LANGUAGE_ID
       this.fetchWelcomePack()
     },
     // 游客报单初始化;临时标识只保存在本页,不写入会员登录缓存。
     fetchWelcomePack() {
+      if (!this.referrerCountryValid) return
+      const requestId = ++this.countryRequestId
       clearTimeout(this.loadingTimer)
       this.loading = true
       this.draft = {}
@@ -153,7 +206,7 @@ export default {
       const countryId = this.form.countryId
       fetchGuestDec({ countryId })
         .then((response) => {
-          if (!this.active || countryId !== this.form.countryId) return
+          if (!this.active || requestId !== this.countryRequestId || countryId !== this.form.countryId) return
           this.draft = response.data.draft || {}
           this.form.insertUserName = this.draft.insertUserName
           this.allOpenBank = response.data.allOpenBank || []
@@ -191,31 +244,40 @@ export default {
             (Object.values(this.payList)[1] || Object.values(this.payList)[0] || {}).label || ''
 
           this.loadingTimer = setTimeout(() => {
-            if (this.active) this.loading = false
+            if (this.active && requestId === this.countryRequestId) this.loading = false
           }, 0.5 * 1000)
         })
         .catch((err) => {
-          if (!this.active || countryId !== this.form.countryId) return
+          if (!this.active || requestId !== this.countryRequestId || countryId !== this.form.countryId) return
           this.showLoadError(err)
           this.loading = false
         })
     },
     // 会员查询
-    handleChkRecUser() {
-      this.form.conUserName = ''
-      this.conRealName = '-'
-      this.form.autoPlace = ''
-      if (this.form.recUserName) {
-        this.loading = true
-        fetchGuestFullInfo({ userName: this.form.recUserName })
-          .then((response) => {
-            this.recRealName = response.data.REAL_NAME
-            this.loading = false
-          })
-          .catch(() => {
-            this.recRealName = '-'
-            this.loading = false
-          })
+    async handleChkRecUser(resetActualReferrer = true) {
+      if (resetActualReferrer) {
+        this.form.conUserName = ''
+        this.conRealName = '-'
+        this.form.autoPlace = ''
+      }
+      this.invalidateReferrerCountry()
+      const userName = this.form.recUserName.trim()
+      const requestId = this.referrerRequestId
+      if (!userName) return
+      this.loading = true
+      try {
+        const { data } = await fetchGuestFullInfo({ userName })
+        if (!this.active || requestId !== this.referrerRequestId || userName !== this.form.recUserName.trim()) return
+        const country = this.countriesList.find(item => item.ID === String(data && data.countryId || ''))
+        if (!country) throw new Error("The referrer's country is unavailable or is not supported for registration.")
+        this.checkedReferrer = userName
+        this.referrerCountryId = this.form.countryId = country.ID
+        this.recRealName = data.REAL_NAME
+        this.countriesChange()
+      } catch (error) {
+        if (!this.active || requestId !== this.referrerRequestId || userName !== this.form.recUserName.trim()) return
+        this.loading = false
+        this.referrerError = String(error && error.message || error || 'Unable to verify this referrer. Please try again.')
       }
     },
     // 自提仅禁用地址输入;是否提交配送方式仍遵循旧接口契约。
@@ -231,6 +293,10 @@ export default {
     // 游客报单
     onSubmit() {
       if (this.submitButtonStat || this.paymentComplete) return
+      if (!this.referrerCountryValid) {
+        this.$message.error('Please verify the referrer and use their country.')
+        return false
+      }
       if (!this.form.decLv) {
         this.$message({
           message: this.$t('profile.selectLevel'),
@@ -245,10 +311,6 @@ export default {
         })
         return false
       }
-      if (!this.form.recUserName.trim()) {
-        this.$message.error('Please enter the referrer ID.')
-        return false
-      }
       if (!this.form.conUserName.trim()) {
         this.$message.error('Please enter the actual referrer ID.')
         return false
@@ -277,7 +339,7 @@ export default {
       }
 
       if (!this.draft.draftId || !this.draft.accessToken) {
-        this.$message.error('Please select your country again to load the guest order details.')
+        this.$message.error('Registration details could not be loaded. Refresh the page and try again.')
         return false
       }
 

+ 34 - 7
src/ui-refactor/views/welcome-pack/WelcomePackFields.vue

@@ -1,6 +1,7 @@
 <template>
   <div class="ng-welcome-fields">
     <ui-section-card title="Network Information">
+      <p v-if="guest && countryLocked" class="ng-welcome-note ng-welcome-referral-note">Registration is referral-based. Your country is inherited from your referrer and cannot be changed.</p>
       <div class="ng-welcome-grid">
         <el-form-item label="Referrer ID" for="ng-welcome-referrer" :required="guest">
           <el-input
@@ -11,6 +12,8 @@
             @input="change('recUserName', $event)"
             @change="$emit('referrer-change')"
           />
+          <p v-if="guest && referrerError" class="ng-welcome-referrer-error" role="alert">{{ referrerError }}</p>
+          <p v-else-if="guest && countryLocked && registrationReady" class="ng-welcome-referrer-valid" role="status"><i class="el-icon-check" aria-hidden="true" /> Valid referrer: {{ form.recUserName }}</p>
         </el-form-item>
         <el-form-item label="Actual Referrer ID" for="ng-welcome-actual-referrer" :required="guest">
           <el-input
@@ -24,7 +27,7 @@
         </el-form-item>
       </div>
     </ui-section-card>
-    <ui-section-card title="Basic Information">
+    <ui-section-card v-if="registrationReady" title="Basic Information">
       <div class="ng-welcome-grid">
         <el-form-item label="Country" :for="idFor('country')">
           <!-- 保持只读下拉,避免浏览器对 Country 搜索框触发地址自动填充。 -->
@@ -33,7 +36,8 @@
             :id="idFor('country')"
             autocomplete="ng-registration"
             :value="form.countryId"
-            placeholder="Select country"
+            :disabled="countryLocked"
+            :placeholder="countryLocked && !form.countryId ? 'Enter referrer first' : 'Select country'"
             popper-class="ng-refactor-popper"
             @input="change('countryId', $event)"
             @change="$emit('country-change')"
@@ -44,6 +48,7 @@
             <el-input id="ng-welcome-country" :value="countryName" autocomplete="ng-registration" readonly />
             <p class="ng-welcome-note">Set by your account, read-only.</p>
           </template>
+          <p v-if="guest && countryLocked" class="ng-welcome-note">Inherited from your referrer — read-only.</p>
         </el-form-item>
         <el-form-item label="Language" :for="idFor('language')">
           <el-select
@@ -105,8 +110,8 @@
         </el-form-item>
       </div>
     </ui-section-card>
-    <slot />
-    <ui-section-card title="Personal Information">
+    <slot v-if="registrationReady" />
+    <ui-section-card v-if="registrationReady" title="Personal Information">
       <div class="ng-welcome-grid">
         <el-form-item
           v-for="field in personalFields"
@@ -126,7 +131,7 @@
         </el-form-item>
       </div>
     </ui-section-card>
-    <ui-section-card title="Delivery Method">
+    <ui-section-card v-if="registrationReady" title="Delivery Method">
       <el-form-item label="Delivery Method">
         <el-radio-group
           :value="form.way"
@@ -138,7 +143,7 @@
         </el-radio-group>
       </el-form-item>
     </ui-section-card>
-    <ui-section-card v-if="form.way !== 'pickup'" title="Address Details">
+    <ui-section-card v-if="registrationReady && form.way !== 'pickup'" title="Address Details">
       <div class="ng-welcome-grid">
         <el-form-item label="Region / State" for="ng-welcome-region">
           <el-cascader
@@ -181,7 +186,7 @@
         </el-form-item>
       </div>
     </ui-section-card>
-    <ui-section-card title="Bank Information">
+    <ui-section-card v-if="registrationReady" title="Bank Information">
       <div class="ng-welcome-grid">
         <el-form-item label="Bank Name" :for="idFor('bank')">
           <el-select
@@ -232,6 +237,9 @@ export default {
     form: { type: Object, required: true },
     guest: { type: Boolean, default: false },
     countries: { type: Array, default: () => [] },
+    countryLocked: { type: Boolean, default: false },
+    registrationReady: { type: Boolean, default: true },
+    referrerError: { type: String, default: '' },
     memberReadOnly: { type: Boolean, default: true },
     countryName: { type: String, default: '' },
     languages: { type: Array, required: true },
@@ -293,6 +301,25 @@ export default {
   line-height: 1.5;
 }
 
+.ng-welcome-referral-note {
+  margin: 0 0 16px;
+}
+
+.ng-welcome-referrer-error,
+.ng-welcome-referrer-valid {
+  margin: 6px 0 0;
+  font-size: 12px;
+  line-height: 1.5;
+}
+
+.ng-welcome-referrer-error {
+  color: #c93030;
+}
+
+.ng-welcome-referrer-valid {
+  color: #007f87;
+}
+
 .ng-welcome-fields ::v-deep .el-select,
 .ng-welcome-fields ::v-deep .el-cascader {
   width: 100%;

+ 54 - 19
src/ui-refactor/views/welcome-pack/__tests__/SharedWelcomePack.spec.js

@@ -50,11 +50,15 @@ async function mount(location) {
   await settle()
   return { root, router, entry: root.$children[0] }
 }
-async function chooseGuestCountry(root, flushLoading = true) {
-  root.$el.querySelector('#ng-signup-SignupPagevue-0').click()
-  await settle()
-  Array.from(document.body.querySelectorAll('.el-select-dropdown__item')).find(item => item.textContent.trim() === 'Nigeria').click()
-  await settle()
+async function verifyGuestReferrer(root, flushLoading = true) {
+  const flow = descendants(root).find(vm => vm.$options.name === 'GuestWelcomePack')
+  if (!flow.referrerCountryValid) {
+    const input = root.$el.querySelector('#ng-welcome-referrer')
+    input.value = input.value || 'INVITER'
+    input.dispatchEvent(new Event('input', { bubbles: true }))
+    input.dispatchEvent(new Event('change', { bubbles: true }))
+    await settle()
+  }
   if (flushLoading) jest.runOnlyPendingTimers()
   await settle()
 }
@@ -68,7 +72,7 @@ beforeEach(() => {
   user.fetchGuestDec.mockImplementation(async() => ({ data: { ...settings(), draft: { draftId: 'guest-draft', accessToken: 'fixture-only-token', insertUserName: 'GUEST-NEW', currency: 'NGN' }, payList: [{ label: 'pay_stack', name: 'Paystack' }] }}))
   user.createGuestDec.mockResolvedValue({ data: { accessCode: 'guest-access', reference: 'guest-reference', amount: 299900, currency: 'NGN' }})
   user.createWelcomePack.mockResolvedValue({ data: { SN: 'MEMBER-ORDER', ORDER_AMOUNT: 299900, EMAIL: 'member@example.test' }})
-  user.fetchGuestFullInfo.mockResolvedValue({ data: { REAL_NAME: 'Referrer' }})
+  user.fetchGuestFullInfo.mockResolvedValue({ data: { REAL_NAME: 'Referrer', countryId: '620699181539139625' }})
   user.fetchGuestInspectNetwork.mockResolvedValue({ data: { REAL_NAME: 'Actual referrer' }})
   deleteApproachOrder.mockResolvedValue({})
 })
@@ -96,12 +100,12 @@ it('wires both production routes to the same entry with fixed modes and unchange
 it('opens guest mode without member initialization and keeps invitation defaults and password controls', async() => {
   const { root, entry } = await mount('/signup?mode=member&ref=INVITER')
   expect(user.fetchWelcomePack).not.toHaveBeenCalled()
-  expect(user.fetchGuestDec).not.toHaveBeenCalled()
+  expect(user.fetchGuestDec).toHaveBeenCalledWith({ countryId: '620699181539139625' })
   const flow = entry.$refs.flow
   expect(flow.form.recUserName).toBe('INVITER')
   expect(flow.form.conUserName).toBe('INVITER')
   expect(root.$el.querySelector('#ng-welcome-password').type).toBe('password')
-  await chooseGuestCountry(root)
+  await verifyGuestReferrer(root)
   expect(user.fetchGuestDec).toHaveBeenCalledWith({ countryId: '620699181539139625' })
   expect(flow.form.languageId).toBe('620713695651307520')
   const input = root.$el.querySelector('#ng-welcome-referrer')
@@ -115,7 +119,7 @@ it('opens guest mode without member initialization and keeps invitation defaults
 
 it.each([['guest', '/signup', 299900, 20923.26], ['member', '/dashboard/member-welcome-pack', 299900, 20923.26]])('uses one view with the correct %s prices, quantities and details', async(mode, route, amount, tax) => {
   const { root, entry } = await mount(route)
-  if (mode === 'guest') await chooseGuestCountry(root)
+  if (mode === 'guest') await verifyGuestReferrer(root)
   const flow = entry.$refs.flow
   root.$el.querySelector('.ng-signup-product-add').click()
   await settle()
@@ -131,22 +135,53 @@ it.each([['guest', '/signup', 299900, 20923.26], ['member', '/dashboard/member-w
   expect(flow.product.taxAmount).toBe(tax)
 })
 
-it('keeps the country selector read-only while open and still selects the country', async() => {
+it('inherits the verified referrer country and keeps its selector disabled', async() => {
   const { root, entry } = await mount('/signup')
+  await verifyGuestReferrer(root)
   const input = root.$el.querySelector('#ng-signup-SignupPagevue-0')
-  input.click()
-  await settle()
   expect(input.readOnly).toBe(true)
+  expect(input.disabled).toBe(true)
   expect(input.getAttribute('autocomplete')).toBe('ng-registration')
-  Array.from(document.body.querySelectorAll('.el-select-dropdown__item')).find(item => item.textContent.trim() === 'Nigeria').click()
-  await settle()
   expect(entry.$refs.flow.form.countryId).toBe('620699181539139625')
   expect(user.fetchGuestDec).toHaveBeenCalledWith({ countryId: '620699181539139625' })
 })
 
+it('shows only network information before verifying a referrer', async() => {
+  const { root } = await mount('/signup')
+  expect(root.$el.textContent).toContain('Registration is referral-based')
+  expect(root.$el.querySelector('#ng-welcome-referrer')).not.toBeNull()
+  expect(root.$el.querySelector('#ng-welcome-actual-referrer')).not.toBeNull()
+  expect(root.$el.querySelector('#ng-signup-SignupPagevue-0')).toBeNull()
+  expect(root.$el.textContent).not.toContain('Basic Information')
+  expect(root.$el.querySelector('.ng-signup-products')).toBeNull()
+  expect(root.$el.querySelector('.ng-payment-methods')).toBeNull()
+})
+
+it('keeps later sections hidden and shows an inline error for an invalid referrer', async() => {
+  user.fetchGuestFullInfo.mockRejectedValueOnce(new Error('Referrer not found. Please check the member ID with your referrer.'))
+  const { root } = await mount('/signup')
+  await verifyGuestReferrer(root)
+  expect(root.$el.querySelector('.ng-welcome-referrer-error').textContent).toContain('Referrer not found')
+  expect(root.$el.textContent).not.toContain('Basic Information')
+  expect(user.fetchGuestDec).not.toHaveBeenCalled()
+})
+
+it('expands the form with a read-only UAE country after successful referral verification', async() => {
+  user.fetchGuestFullInfo.mockResolvedValueOnce({ data: { REAL_NAME: 'UAE referrer', countryId: '620699181539139643' }})
+  const { root, entry } = await mount('/signup?ref=UAE-INVITER')
+  expect(root.$el.querySelector('.ng-welcome-referrer-valid').textContent).toContain('Valid referrer: UAE-INVITER')
+  const country = root.$el.querySelector('#ng-signup-SignupPagevue-0')
+  expect(country.disabled).toBe(true)
+  expect(country.value).toBe('UAE')
+  expect(entry.$refs.flow.form.countryId).toBe('620699181539139643')
+  expect(root.$el.textContent).toContain('Basic Information')
+  expect(root.$el.textContent).toContain('Products')
+  expect(user.fetchGuestDec).toHaveBeenCalledWith({ countryId: '620699181539139643' })
+})
+
 it.each(['/signup', '/dashboard/member-welcome-pack'])('suppresses saved-person autofill throughout %s while retaining new-password semantics and editing', async route => {
   const { root, entry } = await mount(route)
-  if (route === '/signup') await chooseGuestCountry(root)
+  if (route === '/signup') await verifyGuestReferrer(root)
   expect(root.$el.querySelector('form').getAttribute('autocomplete')).toBe('off')
   const fields = root.$el.querySelector('.ng-welcome-fields')
   for (const input of fields.querySelectorAll('input:not([type="radio"]), textarea')) {
@@ -177,7 +212,7 @@ it.each(['/signup', '/dashboard/member-welcome-pack'])('suppresses saved-person
 
 it('recreates the flow when changing modes and ignores a late guest payment callback', async() => {
   const { root, router, entry } = await mount('/signup?ref=INVITER')
-  await chooseGuestCountry(root)
+  await verifyGuestReferrer(root)
   const guest = entry.$refs.flow
   guest.form.realName = 'Guest draft'
   guest.paymentOrder = { reference: 'old-reference' }
@@ -198,7 +233,7 @@ it('clears the guest loading timer when switching to member mode', async() => {
   const scheduled = jest.spyOn(global, 'setTimeout')
   const cleared = jest.spyOn(global, 'clearTimeout')
   const { root, router } = await mount('/signup')
-  await chooseGuestCountry(root, false)
+  await verifyGuestReferrer(root, false)
   const index = scheduled.mock.calls.findIndex(call => call[1] === 500)
   expect(index).toBeGreaterThanOrEqual(0)
   const timer = scheduled.mock.results[index].value
@@ -239,7 +274,7 @@ it('keeps member navigation blocked while payment is active and uses the shared
 
 it('shows the submitted Member ID after guest payment, copies it and returns to login on confirmation', async() => {
   const { root, router, entry } = await mount('/signup?ref=INVITER&redirect=/dashboard/repeat-purchase')
-  await chooseGuestCountry(root)
+  await verifyGuestReferrer(root)
   const flow = entry.$refs.flow
   Object.assign(flow.form, { decLv: 'L1', decUserName: 'CENTER', email: 'guest@example.test' })
   flow.toggleProduct(flow.tableData[0])
@@ -282,7 +317,7 @@ it('shows the submitted Member ID after guest payment, copies it and returns to
 
 it.each(['/signup', '/dashboard/member-welcome-pack'])('round-trips shared personal fields, password visibility and pickup on %s', async route => {
   const { root, entry } = await mount(route)
-  if (route === '/signup') await chooseGuestCountry(root)
+  if (route === '/signup') await verifyGuestReferrer(root)
   const flow = entry.$refs.flow
   const name = root.$el.querySelector('#ng-welcome-realName')
   name.value = 'Shared form member'

+ 2 - 1
src/ui-refactor/views/welcome-pack/__tests__/preview.cjs

@@ -22,7 +22,8 @@ const products = ${JSON.stringify(products)};
 const amount = (params, field) => params.goodsId.reduce((sum, id, index) => sum + products.find(item => item.ID === id)[field] * params.goodsNum[index], 0);
 export const createWelcomePack = async params => ({ data: { SN: 'ISOLATED-MEMBER-ORDER', ORDER_AMOUNT: amount(params, 'MARKET_PRICE'), EMAIL: params.email } });
 export const createGuestDec = async params => ({ data: { accessCode: 'isolated-access', reference: 'isolated-reference', amount: amount(params, 'MARKET_PRICE'), currency: 'NGN' } });
-${['fetchFullInfo', 'fetchInspectNetwork', 'fetchAutoPlace', 'fetchBrandAmbassadorInfo', 'fetchGuestFullInfo', 'fetchGuestInspectNetwork'].map(name => 'export const ' + name + ' = async () => ({ data: { REAL_NAME: "Isolated member" } });').join('\n')}
+${['fetchFullInfo', 'fetchInspectNetwork', 'fetchAutoPlace', 'fetchBrandAmbassadorInfo', 'fetchGuestInspectNetwork'].map(name => 'export const ' + name + ' = async () => ({ data: { REAL_NAME: "Isolated member" } });').join('\n')}
+export const fetchGuestFullInfo = async () => ({ data: { REAL_NAME: "Isolated referrer", countryId: "620699181539139625" } });
 `)
 fs.writeFileSync(local('shop.js'), 'export const deleteApproachOrder = async () => ({});')
 fs.writeFileSync(local('setting.js'), 'export const getLanguages = async () => ' + JSON.stringify(languages) + ';')

+ 31 - 19
tests/unit/ui-refactor/signup.spec.js

@@ -15,8 +15,10 @@ Vue.use(ElementUI)
 const PaymentMethods = load(path.resolve('src/ui-refactor/components/PaymentMethods.vue'))
 const SignupPage = load(path.resolve('src/ui-refactor/views/welcome-pack/welcomePackModes.js')).default.guest
 const instances = []
+const NG = '620699181539139625'
+const AE = '620699181539139643'
 
-function instance() {
+function instance(referrer = 'test-referrer') {
   const vm = new Vue({
     ...SignupPage,
     beforeCreate() {
@@ -27,12 +29,16 @@ function instance() {
     }
   })
   instances.push(vm)
+  // 既有报单用例以已验证的推荐人/国家为前置条件;查询及绑定规则由 signupCountry 用例覆盖。
+  vm.checkedReferrer = referrer
+  vm.referrerCountryId = NG
+  vm.form.countryId = NG
+  vm.form.recUserName = referrer
   return vm
 }
 
 async function settle() {
-  await Promise.resolve()
-  await Promise.resolve()
+  for (let i = 0; i < 8; i++) { await Promise.resolve(); await Vue.nextTick() }
 }
 
 describe('Signup welcome-pack compatibility', () => {
@@ -55,12 +61,14 @@ describe('Signup welcome-pack compatibility', () => {
     [{ ref: '' }, ''],
     [{ ref: '   ' }, ''],
     [{ ref: ['first', 'second'] }, '']
-  ])('defaults both network IDs from the invitation query %j without making requests', (query, expected) => {
+  ])('prefills both network IDs from the invitation query %j and starts country verification', (query, expected) => {
+    const verify = jest.fn()
     const vm = new Vue({
       mixins: [registration],
       beforeCreate() {
         this.$route = { query }
-      }
+      },
+      methods: { handleChkRecUser: verify }
     })
     expect(vm.form.recUserName).toBe(expected)
     expect(vm.form.conUserName).toBe(expected)
@@ -68,17 +76,18 @@ describe('Signup welcome-pack compatibility', () => {
     vm.form.conUserName = 'edited-actual-referrer'
     expect(vm.form.recUserName).toBe('edited-referrer')
     expect(vm.form.conUserName).toBe('edited-actual-referrer')
-    expect(request).not.toHaveBeenCalled()
+    if (expected) expect(verify).toHaveBeenCalledWith(false)
+    else expect(verify).not.toHaveBeenCalled()
     vm.$destroy()
   })
 
   it.each([
-    ['', 'actual-referrer', 'Please enter the referrer ID.'],
-    ['   ', 'actual-referrer', 'Please enter the referrer ID.'],
+    ['', 'actual-referrer', 'Please verify the referrer and use their country.'],
+    ['   ', 'actual-referrer', 'Please verify the referrer and use their country.'],
     ['referrer', '', 'Please enter the actual referrer ID.'],
     ['referrer', '   ', 'Please enter the actual referrer ID.']
   ])('requires both network IDs before creating an order: %j / %j', (referrer, actualReferrer, message) => {
-    const vm = instance()
+    const vm = instance(referrer.trim())
     Object.assign(vm.form, { decLv: 'level', decUserName: 'center', recUserName: referrer, conUserName: actualReferrer })
     vm.isDec = '0'
     vm.draft = { draftId: 'test-draft', accessToken: 'test-only-guest-token' }
@@ -96,7 +105,7 @@ describe('Signup welcome-pack compatibility', () => {
     vm.form.conUserName = 'previous-referrer'
     vm.form.autoPlace = 'previous-placement'
     vm.conRealName = 'Previous name'
-    request.mockResolvedValue({ data: { REAL_NAME: 'Test referrer' }})
+    request.mockResolvedValue({ data: { REAL_NAME: 'Test referrer', countryId: NG, allGoods: [], region: [], decLevel: [], payList: [] }})
     vm.handleChkRecUser()
     expect(request).toHaveBeenCalledWith({
       url: '/v1/user/guest-full-info', method: 'get', params: { userName: 'test-referrer' }
@@ -106,6 +115,7 @@ describe('Signup welcome-pack compatibility', () => {
     expect(vm.conRealName).toBe('-')
     expect(vm.loading).toBe(true)
     await settle()
+    jest.runOnlyPendingTimers()
     expect(vm.recRealName).toBe('Test referrer')
     expect(vm.loading).toBe(false)
   })
@@ -143,6 +153,7 @@ describe('Signup welcome-pack compatibility', () => {
 
   it('does not query guest network information for empty referrer IDs', () => {
     const vm = instance()
+    vm.form.recUserName = ''
     vm.handleChkRecUser()
     vm.handleChkRecommenderActualName()
     expect(request).not.toHaveBeenCalled()
@@ -158,7 +169,8 @@ describe('Signup welcome-pack compatibility', () => {
       }
     })
     expect(vm.countriesList).toEqual([
-      { ID: '620699181539139625', NAME: 'Nigeria', DEFAULT_LANGUAGE_ID: '620713695651307520' }
+      { ID: '620699181539139625', NAME: 'Nigeria', DEFAULT_LANGUAGE_ID: '620713695651307520' },
+      { ID: '620699181539139643', NAME: 'UAE', DEFAULT_LANGUAGE_ID: '620713695651307520' }
     ])
     expect(vm.languageList).toEqual([
       { ID: '620713695718416384', NAME: '中文' },
@@ -191,7 +203,7 @@ describe('Signup welcome-pack compatibility', () => {
 
   it('loads guest identity, member ID, currency and payment methods from the selected country', async() => {
     const vm = instance()
-    vm.form.countryId = 'country'
+    vm.form.countryId = NG
     const draft = {
       draftId: '90071992547409931234', accessToken: 'test-only-guest-token',
       insertUserName: 'test-guest', currency: 'NGN', expiresAt: 2000000000
@@ -201,7 +213,7 @@ describe('Signup welcome-pack compatibility', () => {
 
     vm.fetchWelcomePack()
     expect(request).toHaveBeenCalledWith({
-      url: '/v1/user/guest-dec', method: 'get', params: { countryId: 'country' }
+      url: '/v1/user/guest-dec', method: 'get', params: { countryId: NG }
     })
     await settle()
     jest.runOnlyPendingTimers()
@@ -220,7 +232,7 @@ describe('Signup welcome-pack compatibility', () => {
     [undefined, ['cash', 'pay_stack']]
   ])('keeps country payment methods selectable for response format %#', async(payList, labels) => {
     const vm = instance()
-    vm.form.countryId = 'country'
+    vm.form.countryId = NG
     const original = JSON.stringify(payList)
     request.mockResolvedValue({ data: {
       draft: { insertUserName: 'test-guest', currency: 'NGN' },
@@ -287,9 +299,9 @@ describe('Signup welcome-pack compatibility', () => {
       draft, allGoods: [], region: [], decLevel: [],
       sellType: [{ sell_type: [{ label: 'pay_stack', name: 'Paystack' }] }]
     }})
-    vm.form.countryId = 'previous'
+    vm.form.countryId = NG
     vm.countriesChange()
-    vm.form.countryId = 'current'
+    vm.referrerCountryId = vm.form.countryId = AE
     vm.countriesChange()
     await settle()
     resolvePrevious({ data: { draft: { draftId: 'previous-draft' }}})
@@ -336,10 +348,10 @@ describe('Signup welcome-pack compatibility', () => {
     ['pay_stack', true],
     ['paystack', false]
   ])('preserves order fields and opens the existing payment dialog for %s', async(payType, wrapped) => {
-    const vm = instance()
+    const vm = instance('edited-referrer')
     vm.draft = { draftId: '90071992547409931234', accessToken: 'test-only-guest-token' }
     Object.assign(vm.form, {
-      decLv: 'level', decUserName: 'center', countryId: 'country', languageId: 'language',
+      decLv: 'level', decUserName: 'center', countryId: NG, languageId: 'language',
       recUserName: 'edited-referrer', conUserName: 'edited-actual-referrer',
       areaSelected: ['province', 'city', 'county'], openBank: 'bank', bankNo: 'account',
       bankAddress: 'account name', payType, password: 'test-only', payPassword: 'test-only'
@@ -354,7 +366,7 @@ describe('Signup welcome-pack compatibility', () => {
     expect(request).toHaveBeenCalledWith({
       url: '/v1/user/guest-dec', method: 'post', data: expect.objectContaining({
         draftId: '90071992547409931234', accessToken: 'test-only-guest-token',
-        countryId: 'country', languageId: 'language', province: 'province', city: 'city', county: 'county',
+        countryId: NG, languageId: 'language', province: 'province', city: 'city', county: 'county',
         openBank: 'bank', bankNo: 'account', bankAddress: 'account name',
         recUserName: 'edited-referrer', conUserName: 'edited-actual-referrer',
         goodsId: ['goods'], goodsNum: [2], decType: 'normal', decWay: '2', location: 1, payType

+ 163 - 0
tests/unit/ui-refactor/signupCountry.spec.js

@@ -0,0 +1,163 @@
+/* eslint-env jest */
+import Vue from 'vue'
+import path from 'path'
+import { load } from '@/ui-refactor/views/purchase/__tests__/loadComponent'
+import * as user from '@/api/user'
+
+jest.mock('@/api/user', () => Object.fromEntries(['fetchGuestFullInfo', 'fetchGuestDec', 'createGuestDec', 'fetchWelcomePack', 'fetchFullInfo', 'fetchGuestInspectNetwork', 'fetchBrandAmbassadorInfo'].map(name => [name, jest.fn()])))
+jest.mock('@/api/shop', () => ({ deleteApproachOrder: jest.fn() }))
+jest.mock('@/api/setting', () => ({ getLanguages: jest.fn() }))
+jest.mock('@/utils/usersInfo', () => ({ userName: () => null }))
+jest.mock('vue-paystack', () => ({ render: h => h('button') }))
+const Guest = load(path.resolve('src/ui-refactor/views/welcome-pack/welcomePackModes.js')).default.guest
+const NG = '620699181539139625'
+const AE = '620699181539139643'
+const EN = '620713695651307520'
+const instances = []
+async function settle() { for (let i = 0; i < 12; i++) { await Promise.resolve(); await Vue.nextTick() } }
+function instance(ref) {
+  const vm = new (Vue.extend(Guest))({ beforeCreate() {
+    this.$route = { query: ref ? { ref } : {}}
+    this.$message = Object.assign(jest.fn(), { error: jest.fn() })
+    this.$t = key => key
+  } })
+  instances.push(vm)
+  return vm
+}
+function ready(vm) {
+  Object.assign(vm.form, { decLv: 'L1', decUserName: 'CENTER', conUserName: 'ACTUAL', payType: 'pay_stack' })
+  vm.multipleSelection = [{ ID: 'P1', goodsNum: 1, MARKET_PRICE: 120 }]
+}
+beforeEach(() => {
+  jest.resetAllMocks()
+  jest.useFakeTimers()
+  user.fetchGuestFullInfo.mockResolvedValue({ data: { REAL_NAME: 'Referrer', countryId: AE }})
+  user.fetchGuestDec.mockImplementation(({ countryId }) => Promise.resolve({ data: {
+    draft: { draftId: 'draft-' + countryId, accessToken: 'fixture-only', insertUserName: 'NEW', currency: countryId === AE ? 'AED' : 'NGN' },
+    allGoods: [], region: [], decLevel: [], payList: [{ label: 'pay_stack' }]
+  }}))
+  user.createGuestDec.mockResolvedValue({ data: { accessCode: 'fixture-access', reference: 'fixture-reference' }})
+})
+afterEach(() => { instances.splice(0).forEach(vm => vm.$destroy()); jest.clearAllTimers(); jest.useRealTimers() })
+
+it('offers both fixed countries and keeps the existing English default', () => {
+  expect(instance().countriesList).toEqual([
+    { ID: NG, NAME: 'Nigeria', DEFAULT_LANGUAGE_ID: EN },
+    { ID: AE, NAME: 'UAE', DEFAULT_LANGUAGE_ID: EN }
+  ])
+})
+it('verifies an invitation referrer and automatically loads the matching UAE registration', async() => {
+  const vm = instance('INVITER')
+  await settle()
+  expect(user.fetchGuestFullInfo).toHaveBeenCalledWith({ userName: 'INVITER' })
+  expect(vm.form.recUserName).toBe('INVITER')
+  expect(vm.form.conUserName).toBe('INVITER')
+  expect(vm.form.countryId).toBe(AE)
+  expect(vm.form.languageId).toBe(EN)
+  expect(user.fetchGuestDec).toHaveBeenCalledWith({ countryId: AE })
+  expect(vm.draft.draftId).toBe('draft-' + AE)
+})
+it.each([['NG-PREFIX', AE], ['AE-PREFIX', NG]])('binds %s to the returned countryId rather than the member ID prefix', async(name, countryId) => {
+  user.fetchGuestFullInfo.mockResolvedValue({ data: { REAL_NAME: 'Referrer', countryId }})
+  const vm = instance()
+  vm.updateForm({ recUserName: name })
+  await vm.handleChkRecUser()
+  await settle()
+  expect(vm.form.countryId).toBe(countryId)
+  expect(user.fetchGuestDec).toHaveBeenCalledWith({ countryId })
+})
+it.each([undefined, '', 'unsupported'])('does not initialize registration for an unsupported referrer country %s', async countryId => {
+  user.fetchGuestFullInfo.mockResolvedValue({ data: { REAL_NAME: 'Referrer', countryId }})
+  const vm = instance('INVITER')
+  await settle()
+  expect(vm.form.countryId).toBe('')
+  expect(vm.draft).toEqual({})
+  expect(user.fetchGuestDec).not.toHaveBeenCalled()
+  expect(vm.referrerError).toContain('country')
+})
+it('restores the verified country if a country change attempts to select another market', async() => {
+  const vm = instance('INVITER')
+  await settle()
+  vm.form.countryId = NG
+  vm.countriesChange()
+  expect(vm.form.countryId).toBe(AE)
+  expect(user.fetchGuestDec.mock.calls.every(([params]) => params.countryId === AE)).toBe(true)
+})
+it('clears old country data as soon as the referrer is edited', async() => {
+  const vm = instance('INVITER')
+  await settle()
+  ready(vm)
+  vm.tableData = [{ ID: 'P1' }]
+  vm.paymentOrder = { accessCode: 'old-access', reference: 'old-reference' }
+  vm.updateForm({ recUserName: 'NEW-REFERRER' })
+  expect(vm.form.countryId).toBe('')
+  expect(vm.form.insertUserName).toBe('')
+  expect(vm.draft).toEqual({})
+  expect(vm.tableData).toEqual([])
+  expect(vm.multipleSelection).toEqual([])
+  expect(vm.paymentOrder.accessCode).toBe('')
+  ready(vm)
+  vm.onSubmit()
+  expect(user.createGuestDec).not.toHaveBeenCalled()
+})
+it('ignores a slower response for an earlier referrer', async() => {
+  let finish
+  user.fetchGuestFullInfo.mockImplementationOnce(() => new Promise(resolve => { finish = resolve }))
+  const vm = instance('FIRST')
+  vm.updateForm({ recUserName: 'SECOND' })
+  await vm.handleChkRecUser()
+  await settle()
+  finish({ data: { REAL_NAME: 'Earlier referrer', countryId: NG }})
+  await settle()
+  expect(vm.form.countryId).toBe(AE)
+  expect(vm.recRealName).toBe('Referrer')
+  expect(user.fetchGuestDec).toHaveBeenCalledTimes(1)
+})
+it('ignores an old country draft after changing referrers within the same country', async() => {
+  let finish
+  user.fetchGuestDec.mockImplementationOnce(() => new Promise(resolve => { finish = resolve }))
+  const vm = instance('FIRST')
+  await settle()
+  vm.updateForm({ recUserName: 'SECOND' })
+  await vm.handleChkRecUser()
+  await settle()
+  finish({ data: { draft: { draftId: 'old-draft' }, allGoods: [] }})
+  await settle()
+  expect(vm.draft.draftId).toBe('draft-' + AE)
+})
+it.each(['unverified', 'edited', 'wrong-country'])('prevents submitting a %s country/referrer binding', async scenario => {
+  const vm = instance('INVITER')
+  await settle()
+  ready(vm)
+  if (scenario === 'unverified') vm.checkedReferrer = ''
+  if (scenario === 'edited') vm.form.recUserName = 'ANOTHER'
+  if (scenario === 'wrong-country') vm.form.countryId = NG
+  vm.onSubmit()
+  expect(user.createGuestDec).not.toHaveBeenCalled()
+  expect(vm.$message.error).toHaveBeenCalledWith('Please verify the referrer and use their country.')
+})
+it('submits the verified UAE country through the original guest registration API', async() => {
+  let finish
+  user.createGuestDec.mockImplementationOnce(() => new Promise(resolve => { finish = resolve }))
+  const vm = instance('INVITER')
+  await settle()
+  ready(vm)
+  vm.onSubmit()
+  expect(vm.formDisabled).toBe(true)
+  vm.updateForm({ recUserName: 'DIFFERENT-REFERRER' })
+  expect(vm.form.recUserName).toBe('INVITER')
+  expect(vm.form.countryId).toBe(AE)
+  finish({ data: { accessCode: 'fixture-access', reference: 'fixture-reference' }})
+  await settle()
+  expect(user.createGuestDec).toHaveBeenCalledWith(expect.objectContaining({ countryId: AE, recUserName: 'INVITER', conUserName: 'ACTUAL', draftId: 'draft-' + AE }))
+})
+it('ignores a referrer response after the registration page is destroyed', async() => {
+  let finish
+  user.fetchGuestFullInfo.mockImplementationOnce(() => new Promise(resolve => { finish = resolve }))
+  const vm = instance('INVITER')
+  vm.$destroy()
+  finish({ data: { REAL_NAME: 'Referrer', countryId: AE }})
+  await settle()
+  expect(user.fetchGuestDec).not.toHaveBeenCalled()
+  expect(vm.form.countryId).toBe('')
+})

+ 2 - 0
tests/unit/ui-refactor/signupProducts.spec.js

@@ -40,6 +40,8 @@ it('keeps registration cards, totals and product details on market price', async
   }).$mount()
   document.body.appendChild(vm.$el)
   try {
+    vm.checkedReferrer = vm.form.recUserName = 'VERIFIED-REFERRER'
+    vm.referrerCountryId = vm.form.countryId = '620699181539139625'
     vm.tableData = [{ ID: 'sample', GOODS_NAME: 'Sample product', GOODS_NO: 'SKU1', CODE: 'NGN', SELL_PRICE: 27000, MARKET_PRICE: 32400, TAX_RATE: 7.5, PRICE_PV: 10, STORE_NUMS: 5 }]
     vm.storeNums = [1]
     vm.currencyUnitCode = 'NGN'