|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var optimist = require('optimist'); |
| 4 | +var setup = require('../../lib/ionic/setup'); |
| 5 | +var IonicAppLib = require('ionic-app-lib'); |
| 6 | +var appLibUtils = IonicAppLib.utils; |
| 7 | +var appLibSetup = IonicAppLib.setup; |
| 8 | +var log = IonicAppLib.logging.logger; |
| 9 | +var Q = require('q'); |
| 10 | + |
| 11 | +describe('setup command', function() { |
| 12 | + describe('command settings', function() { |
| 13 | + it('should have a title', function() { |
| 14 | + expect(setup.title).toBeDefined(); |
| 15 | + expect(setup.title).not.toBeNull(); |
| 16 | + expect(setup.title.length).toBeGreaterThan(0); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should have a summary', function() { |
| 20 | + expect(setup.summary).toBeDefined(); |
| 21 | + expect(setup.summary).not.toBeNull(); |
| 22 | + expect(setup.summary.length).toBeGreaterThan(0); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should have a an option of sass', function() { |
| 26 | + expect(setup.args).toEqual(jasmine.any(Object)); |
| 27 | + expect(setup.args['[sass]']).toEqual(jasmine.any(String)); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + describe('run function', function() { |
| 32 | + it('should fail if a command is not passed', function(done) { |
| 33 | + var processArguments = ['node', 'ionic', 'setup']; |
| 34 | + var rawCliArguments = processArguments.slice(2); |
| 35 | + var argv = optimist(rawCliArguments).argv; |
| 36 | + |
| 37 | + spyOn(appLibUtils, 'fail'); |
| 38 | + |
| 39 | + // Expect failure |
| 40 | + setup.run(null, argv, rawCliArguments).then(function() { |
| 41 | + expect(appLibUtils.fail).toHaveBeenCalledWith('Missing setup task command.', 'setup'); |
| 42 | + done(); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should fail if a an invalid command passed', function(done) { |
| 47 | + var processArguments = ['node', 'ionic', 'setup', 'stuff']; |
| 48 | + var rawCliArguments = processArguments.slice(2); |
| 49 | + var argv = optimist(rawCliArguments).argv; |
| 50 | + |
| 51 | + spyOn(appLibUtils, 'fail'); |
| 52 | + |
| 53 | + // Expect failure |
| 54 | + setup.run(null, argv, rawCliArguments).then(function() { |
| 55 | + expect(appLibUtils.fail).toHaveBeenCalledWith('Invalid setup task command: stuff', 'setup'); |
| 56 | + done(); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should succeed if sass was passed and sassSetup returns success', function(done) { |
| 61 | + var processArguments = ['node', 'ionic', 'setup', 'sass']; |
| 62 | + var rawCliArguments = processArguments.slice(2); |
| 63 | + var argv = optimist(rawCliArguments).argv; |
| 64 | + var dir = '/project/dir/path'; |
| 65 | + |
| 66 | + spyOn(appLibUtils, 'fail'); |
| 67 | + spyOn(log, 'info'); |
| 68 | + spyOn(log, 'error'); |
| 69 | + spyOn(process, 'cwd').andReturn(dir); |
| 70 | + spyOn(appLibSetup, 'sassSetup').andReturn(Q(true)); |
| 71 | + |
| 72 | + // Expect success |
| 73 | + setup.run(null, argv, rawCliArguments).then(function() { |
| 74 | + expect(appLibSetup.sassSetup).toHaveBeenCalledWith(dir); |
| 75 | + expect(log.info).toHaveBeenCalled(); |
| 76 | + expect(log.error).not.toHaveBeenCalled(); |
| 77 | + done(); |
| 78 | + }); |
| 79 | + |
| 80 | + }); |
| 81 | + |
| 82 | + it('should fail if sass was passed and sassSetup returns an error', function(done) { |
| 83 | + var processArguments = ['node', 'ionic', 'setup', 'sass']; |
| 84 | + var rawCliArguments = processArguments.slice(2); |
| 85 | + var argv = optimist(rawCliArguments).argv; |
| 86 | + var dir = '/project/dir/path'; |
| 87 | + |
| 88 | + spyOn(appLibUtils, 'fail'); |
| 89 | + spyOn(log, 'info'); |
| 90 | + spyOn(log, 'error'); |
| 91 | + spyOn(process, 'cwd').andReturn(dir); |
| 92 | + spyOn(appLibSetup, 'sassSetup').andReturn(Q.reject('error occurred')); |
| 93 | + |
| 94 | + // Expect success |
| 95 | + setup.run(null, argv, rawCliArguments).then(function() { |
| 96 | + expect(appLibSetup.sassSetup).toHaveBeenCalledWith(dir); |
| 97 | + expect(log.info).not.toHaveBeenCalled(); |
| 98 | + expect(log.error).toHaveBeenCalled(); |
| 99 | + done(); |
| 100 | + }); |
| 101 | + }); |
| 102 | + }); |
| 103 | +}); |
0 commit comments