const fs = require('fs')
const path = require('path')
const assert = require('assert')

const loginViewSource = fs.readFileSync(
  path.join(__dirname, '../src/views/login.vue'),
  'utf8'
)

assert(
  /loginForm:\s*\{[\s\S]*username:\s*""/.test(loginViewSource),
  '登录页默认用户名应为空字符串'
)

assert(
  /loginForm:\s*\{[\s\S]*password:\s*""/.test(loginViewSource),
  '登录页默认密码应为空字符串'
)

assert(
  /username:\s*username === undefined \? this\.loginForm\.username : username/.test(loginViewSource),
  '登录页应继续支持从 cookie 回填用户名'
)

assert(
  /password:\s*password === undefined \? this\.loginForm\.password : decrypt\(password\)/.test(loginViewSource),
  '登录页应继续支持从 cookie 回填密码'
)

console.log('login default credentials assertions passed')
