Skip to content

Commit aa55ba0

Browse files
committed
test(alpha): add test cases
1 parent 1e629a9 commit aa55ba0

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

test/bin/tsw/util/alpha.test.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
const chai = require('chai');
2+
const expect = chai.expect;
3+
const sinon = require('sinon');
4+
const plug = require('plug');
5+
const logger = plug('logger');
6+
const alpha = plug('util/alpha.js');
7+
const config = plug('config');
8+
const isWindows = plug('util/isWindows');
9+
10+
logger.setLogLevel('error');
11+
12+
describe('test tsw/util/alpha', () => {
13+
14+
describe('#isAlpha', () => {
15+
it('#check a num in isWin32Like & skymode', () => {
16+
config.skyMode = true;
17+
const stub = sinon.stub(isWindows, 'isWin32Like').callsFake(() => {
18+
return true;
19+
});
20+
const uid = 1;
21+
expect(alpha.isAlpha(uid)).to.be.equal(true);
22+
stub.restore();
23+
});
24+
25+
it('#check a num not skymode', () => {
26+
config.skyMode = false;
27+
const uid = 1;
28+
expect(alpha.isAlpha(uid)).to.be.equal(undefined);
29+
});
30+
31+
it('#update', () => {
32+
alpha.update({ 1: true });
33+
const uid = 1;
34+
expect(alpha.isAlpha(uid)).to.be.equal(true);
35+
});
36+
37+
it('#get From logger', () => {
38+
alpha.update({ 1: true });
39+
40+
const stub = sinon.stub(logger, 'getKey').callsFake(() => {
41+
return 1;
42+
});
43+
44+
expect(alpha.isAlpha()).to.be.equal(true);
45+
stub.restore();
46+
});
47+
48+
it('#get From getUin', () => {
49+
alpha.update({ 1: true });
50+
context.window = {
51+
request: {}
52+
};
53+
config.extendMod = {
54+
getUid: (req) => {
55+
return 1;
56+
}
57+
};
58+
59+
expect(alpha.isAlpha()).to.be.equal(true);
60+
delete context.window;
61+
delete config.extendMod;
62+
});
63+
});
64+
65+
describe('#getUin', () => {
66+
it('#without req', () => {
67+
expect(alpha.getUin()).to.be.equal(undefined);
68+
});
69+
70+
it('#with req', () => {
71+
expect(alpha.getUin({})).to.be.equal(undefined);
72+
});
73+
74+
it('#extendMod without req', () => {
75+
config.extendMod = {
76+
getUid: (req) => {
77+
return 1;
78+
}
79+
};
80+
expect(alpha.getUin()).to.be.equal(undefined);
81+
});
82+
83+
it('#extendMod getUid with req', () => {
84+
config.extendMod = {
85+
getUid: (req) => {
86+
return 1;
87+
}
88+
};
89+
expect(alpha.getUin({})).to.equal(1);
90+
});
91+
92+
it('#extendMod getUin with req', () => {
93+
config.extendMod = {
94+
getUin: (req) => {
95+
return 1;
96+
}
97+
};
98+
expect(alpha.getUin({})).to.equal(1);
99+
});
100+
101+
it('#extendMod getUin with window.request', () => {
102+
context.window = {
103+
request: {}
104+
};
105+
config.extendMod = {
106+
getUin: (req) => {
107+
return 1;
108+
}
109+
};
110+
expect(alpha.getUin()).to.equal(1);
111+
});
112+
});
113+
114+
});

0 commit comments

Comments
 (0)