-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
const sinon = require('sinon'); | ||
const plug = require('plug'); | ||
const logger = plug('logger'); | ||
const alpha = plug('util/alpha.js'); | ||
const config = plug('config'); | ||
const isWindows = plug('util/isWindows'); | ||
|
||
logger.setLogLevel('error'); | ||
|
||
describe('test tsw/util/alpha', () => { | ||
|
||
describe('#isAlpha', () => { | ||
it('#check a num in isWin32Like & skymode', () => { | ||
config.skyMode = true; | ||
const stub = sinon.stub(isWindows, 'isWin32Like').callsFake(() => { | ||
return true; | ||
}); | ||
const uid = 1; | ||
expect(alpha.isAlpha(uid)).to.be.equal(true); | ||
stub.restore(); | ||
}); | ||
|
||
it('#check a num not skymode', () => { | ||
config.skyMode = false; | ||
const uid = 1; | ||
expect(alpha.isAlpha(uid)).to.be.equal(undefined); | ||
}); | ||
|
||
it('#update', () => { | ||
alpha.update({ 1: true }); | ||
const uid = 1; | ||
expect(alpha.isAlpha(uid)).to.be.equal(true); | ||
}); | ||
|
||
it('#get From logger', () => { | ||
alpha.update({ 1: true }); | ||
|
||
const stub = sinon.stub(logger, 'getKey').callsFake(() => { | ||
return 1; | ||
}); | ||
|
||
expect(alpha.isAlpha()).to.be.equal(true); | ||
stub.restore(); | ||
}); | ||
|
||
it('#get From getUin', () => { | ||
alpha.update({ 1: true }); | ||
context.window = { | ||
request: {} | ||
}; | ||
config.extendMod = { | ||
getUid: (req) => { | ||
return 1; | ||
} | ||
}; | ||
|
||
expect(alpha.isAlpha()).to.be.equal(true); | ||
delete context.window; | ||
delete config.extendMod; | ||
}); | ||
}); | ||
|
||
describe('#getUin', () => { | ||
it('#without req', () => { | ||
expect(alpha.getUin()).to.be.equal(undefined); | ||
}); | ||
|
||
it('#with req', () => { | ||
expect(alpha.getUin({})).to.be.equal(undefined); | ||
}); | ||
|
||
it('#extendMod without req', () => { | ||
config.extendMod = { | ||
getUid: (req) => { | ||
return 1; | ||
} | ||
}; | ||
expect(alpha.getUin()).to.be.equal(undefined); | ||
}); | ||
|
||
it('#extendMod getUid with req', () => { | ||
config.extendMod = { | ||
getUid: (req) => { | ||
return 1; | ||
} | ||
}; | ||
expect(alpha.getUin({})).to.equal(1); | ||
}); | ||
|
||
it('#extendMod getUin with req', () => { | ||
config.extendMod = { | ||
getUin: (req) => { | ||
return 1; | ||
} | ||
}; | ||
expect(alpha.getUin({})).to.equal(1); | ||
}); | ||
|
||
it('#extendMod getUin with window.request', () => { | ||
context.window = { | ||
request: {} | ||
}; | ||
config.extendMod = { | ||
getUin: (req) => { | ||
return 1; | ||
} | ||
}; | ||
expect(alpha.getUin()).to.equal(1); | ||
}); | ||
}); | ||
|
||
}); |