Skip to content

Commit

Permalink
test(alpha): add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinzZH committed Jun 14, 2018
1 parent 1e629a9 commit aa55ba0
Showing 1 changed file with 114 additions and 0 deletions.
114 changes: 114 additions & 0 deletions test/bin/tsw/util/alpha.test.js
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);
});
});

});

0 comments on commit aa55ba0

Please sign in to comment.