Skip to content

Commit

Permalink
CB-11982 : added jasmine tests to test config get, set and delete
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyso authored and stevengill committed Apr 19, 2017
1 parent dba7c9a commit 8956c75
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 49 deletions.
153 changes: 105 additions & 48 deletions spec/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,60 +400,117 @@ describe("cordova cli", function () {
});
});

describe("platform", function () {
beforeEach(function () {
spyOn(cordova.raw, "platform").and.returnValue(Q());
describe("platform", function () {
beforeEach(function () {
spyOn(cordova.raw, "platform").and.returnValue(Q());
});

it("Test #030 : autosave is the default setting for platform add", function (done) {
cli(["node", "cordova", "platform", "add", "ios"], function () {
expect(cordova.raw.platform).toHaveBeenCalledWith(
"add",
["ios"],
jasmine.any(Object)
);
var opts = cordova.raw.platform.calls.argsFor(0)[2];
expect(opts.save).toBe(true);
done();
});
});

it("Test #030 : autosave is the default setting for platform add", function (done) {
cli(["node", "cordova", "platform", "add", "ios"], function () {
expect(cordova.raw.platform).toHaveBeenCalledWith(
"add",
["ios"],
jasmine.any(Object)
);
var opts = cordova.raw.platform.calls.argsFor(0)[2];
expect(opts.save).toBe(true);
done();
});
it("Test #031 : platform is not saved when --nosave is passed in", function (done) {
cli(["node", "cordova", "platform", "add", "ios", "--nosave"], function () {
expect(cordova.raw.platform).toHaveBeenCalledWith(
"add",
["ios"],
jasmine.any(Object)
);
var opts = cordova.raw.platform.calls.argsFor(0)[2];
expect(opts.save).toBe(false);
done();
});
});

it("Test #031 : platform is not saved when --nosave is passed in", function (done) {
cli(["node", "cordova", "platform", "add", "ios", "--nosave"], function () {
expect(cordova.raw.platform).toHaveBeenCalledWith(
"add",
["ios"],
jasmine.any(Object)
);
var opts = cordova.raw.platform.calls.argsFor(0)[2];
expect(opts.save).toBe(false);
done();
});
it("Test #032 : autosave is the default setting for platform remove", function (done) {
cli(["node", "cordova", "platform", "remove", "ios"], function () {
expect(cordova.raw.platform).toHaveBeenCalledWith(
"remove",
["ios"],
jasmine.any(Object)
);
var opts = cordova.raw.platform.calls.argsFor(0)[2];
expect(opts.save).toBe(true);
done();
});
});

it("Test #032 : autosave is the default setting for platform remove", function (done) {
cli(["node", "cordova", "platform", "remove", "ios"], function () {
expect(cordova.raw.platform).toHaveBeenCalledWith(
"remove",
["ios"],
jasmine.any(Object)
);
var opts = cordova.raw.platform.calls.argsFor(0)[2];
expect(opts.save).toBe(true);
done();
});
it("Test #033 : platform is not removed when --nosave is passed in", function (done) {
cli(["node", "cordova", "platform", "remove", "ios", "--nosave"], function () {
expect(cordova.raw.platform).toHaveBeenCalledWith(
"remove",
["ios"],
jasmine.any(Object)
);
var opts = cordova.raw.platform.calls.argsFor(0)[2];
expect(opts.save).toBe(false);
done();
});
});
});

it("Test #033 : platform is not removed when --nosave is passed in", function (done) {
cli(["node", "cordova", "platform", "remove", "ios", "--nosave"], function () {
expect(cordova.raw.platform).toHaveBeenCalledWith(
"remove",
["ios"],
jasmine.any(Object)
);
var opts = cordova.raw.platform.calls.argsFor(0)[2];
expect(opts.save).toBe(false);
done();
});
describe("config", function () {
beforeEach(function () {
spyOn(cordova.raw, "config").and.returnValue(Q());
});

it("Test#040 : config set is called with true and config delete is called", function (done) {
cli(["node", "cordova", "config", "set", "autosave", "true"], function () {
expect(cordova.raw.config).toHaveBeenCalledWith(
'set',
[ 'autosave', 'true' ],
jasmine.any(Object)
);
done();
});
});
cordova.raw.config('delete', 'autosave')
.then(function () {
expect(cordova.raw.config).toHaveBeenCalledWith(
'delete', 'autosave'
);
done();
});
});

it("Test#041 : config set is called with false", function (done) {
cli(["node", "cordova", "config", "set", "autosave", "false"], function () {
expect(cordova.raw.config).toHaveBeenCalledWith(
'set',
[ 'autosave', 'false' ],
jasmine.any(Object)
);
done();
});
});

it("Test#042 : config set is called even without true or false", function (done) {
cli(["node", "cordova", "config", "set", "autosave"], function () {
expect(cordova.raw.config).toHaveBeenCalledWith(
'set',
[ 'autosave' ],
jasmine.any(Object)
);
done();
});
});

it("Test #043 : config get is called", function (done) {
cli(["node", "cordova", "config", "get", "autosave"], function () {
expect(cordova.raw.config).toHaveBeenCalledWith(
'get',
[ 'autosave' ],
jasmine.any(Object)
);
done();
});
});
});
3 changes: 2 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ module.exports = function (inputArgs, cb) {
if (isConfigCmd && inputArgs[3] === 'get') {
conf.get(inputArgs[4]);
}

// If set is called
if (isConfigCmd && inputArgs[3] === 'set') {
if (inputArgs[5] === undefined) {
conf.set(inputArgs[4], null);
conf.set(inputArgs[4], true);
}

if(inputArgs[5]) {
Expand Down

0 comments on commit 8956c75

Please sign in to comment.