jsTest.onPage(function() {
     var wf = jsTest.requireSrcModule("model/workflow");
     var pipe = [        
       {
         "name" : "Prepare",
         "streams" : [
             {"name" : "Ruby", "steps" : [
               {"type": "sh", "name" : "Install Ruby", "command" : "/bin/ci/install_ruby version=2.0.1"},
               {"type": "stash", "name" : "Stash compiled app", "includes": "/app", "excludes" : ""} 
             ]},
             {"name" : "Python","steps" : [
               {"type": "sh", "name" : "Yeah", "command" : "exit()"},
               
             ]}
           ]
       }, 
       {
         "name" : "Do It",
         "steps" : [
           {"type": "git", "url" : "git@thing.com/yeah"}
         ]
       }
     ];  
     
     var editorModules = jsTest.requireSrcModule('steps');
     
     var script = wf.toWorkflow(pipe, editorModules);
     assert.notEqual(-1, script.indexOf("/app"));
     assert.notEqual(-1, script.indexOf("git 'git@thing.com/yeah'"));
     done();
 });        
 jsTest.onPage(function() {
   var e = jsTest.requireSrcModule("editor");
   var block = e.normalStageBlock("idvaluehere", {"name":"myname"});
   expect(block.indexOf("myname")).not.toBe(-1);
   expect(block.indexOf("idvaluehere")).not.toBe(-1);        
   done();
 });
Beispiel #3
0
        jsTest.onPage(function() {
            var configTabBarWidget = jsTest.requireSrcModule('widgets/config/tabbar');
            var configTabBar = configTabBarWidget.addTabsOnFirst();
            var jQD = require('jquery-detached');

            var $ = jQD.getJQuery();

            var tabBar = $('.tabBar');

            // Move the advanced stuff into the general section
            var general = configTabBar.getSection('config_general');
            general.adoptSection('config__advanced_project_options');

            // Only 3 tabs should be visible
            // (used to be 4 before the merge/adopt)...
            expect($('.tab', tabBar).size()).toBe(3);
            expect(textCleanup($('.tab', tabBar).text())).toBe('General|#Build Triggers|#Build');

            // And if we try to use the finder now to find something
            // that was in the advanced section, it should now appear in the
            // General section ...
            configTabBar.showSections('quiet period');
            expect($('.tab.hidden', tabBar).size()).toBe(2);
            expect(textCleanup($('.tab.hidden', tabBar).text())).toBe('#Build Triggers|#Build');

            var activeSection = configTabBar.activeSection();
            expect(textCleanup(activeSection.title)).toBe('General');

            done();
        }, 'widgets/config/freestyle-config-tabbed.html');
    jsTest.onPage(function() {
      var wf = jsTest.requireSrcModule("model/workflow");
      var pipeline = [
        {
        "name" : "Prepare",
        "steps" : [          
              {"type": "sh", "name" : "Install Ruby", "command" : "/bin/ci/install_ruby version=2.0.1"},          
              {"type": "git", "name" : "Another thing", "command" : "/bin/ci/install_ruby version=2.0.1"}
          ]    
        }
      ];
      
      wf.makeParallel(pipeline, "stage-0");
      
      var stage = pipeline[0];
      assert.equal(undefined, stage.steps);
      assert.equal(2, stage.streams.length);
      
      assert.equal("Install Ruby", stage.streams[0].name);
      assert.equal("Install Ruby", stage.streams[0].steps[0].name);

      wf.toggleParallel(pipeline, "stage-0");
      assert.equal(undefined, stage.streams);
      assert.equal(2, stage.steps.length);
      
      wf.toggleParallel(pipeline, "stage-0");
      assert.equal(undefined, stage.steps);
      assert.equal(2, stage.streams.length);

      
      done();
    });
 jsTest.onPage(function() {
     var wf = jsTest.requireSrcModule("model/workflow");
     assert.deepEqual([0,1,2], wf.actionIdToStep("stage-0-1-2"));        
     assert.deepEqual([0,1], wf.actionIdToStep("stage-0-1"));        
     assert.deepEqual([1,1], wf.actionIdToStep("stage-1-1"));
     done();
 });
 jsTest.onPage(function() {
     var wf = jsTest.requireSrcModule("model/workflow");
     var pipeline = [
     {
     "name" : "Checkout",
     "steps" : [
       {"name" : "Clone webapp"},
       {"name" : "Hair on fire"}  
     ]    
     },
     
     {
     "name" : "Prepare",
     "streams" : [
       {"name" : "Ruby", "steps" : [
           {"type": "sh", "name" : "Install Ruby", "command" : "/bin/ci/install_ruby version=2.0.1"}
         ]
       }            
     ]    
     }];
     var s1 = wf.fetchStep([0,0], pipeline);
     var s2 = wf.fetchStep([0,1], pipeline);  
     var s3 = wf.fetchStep([1,0,0], pipeline);
     assert.equal("Clone webapp", s1.name);  
     assert.equal("Hair on fire", s2.name);  
     assert.equal("Install Ruby", s3.name);
     done();
 });
Beispiel #7
0
        jsTest.onPage(function() {
            var tabbars = jsTest.requireSrcModule('config-tabbar.js');
            var firstTableMetadata = tabbars.tabs[0];

            // The first section ("General") should be active by default
            expect(firstTableMetadata.activeSection().id).toBe('config_general');
            expect(firstTableMetadata.activeSectionCount()).toBe(1);

            firstTableMetadata.onShowSection(function() {
                expect(this.id).toBe('config__build');

                expect(firstTableMetadata.activeSectionCount()).toBe(1);
                var activeSection = firstTableMetadata.activeSection();
                expect(activeSection.id).toBe('config__build');
                expect(activeSection.activeRowCount()).toBe(2);
                expect(firstTableMetadata.getTopRows().filter('.active').size()).toBe(1); // should be activeSection.activeRowCount() - 1

                done();
            });

            // Mimic the user clicking on one of the tabs. Should make that section active,
            // with all of the rows in that section having an "active" class.
            firstTableMetadata.activateSection('config__build');
            // above 'firstTableMetadata.onShowSection' handler should get called now

        }, 'widgets/config/freestyle-config-tabbed.html');
Beispiel #8
0
        jsTest.onPage(function() {
            var configTabBarWidget = jsTest.requireSrcModule('widgets/config/tabbar');
            var configTabBar = configTabBarWidget.addTabsOnFirst();
            var jQD = require('jquery-detached');

            var $ = jQD.getJQuery();

            var tabBar = $('.tabBar');

            // All tabs should be visible...
            expect($('.tab', tabBar).size()).toBe(4);
            expect($('.tab.hidden', tabBar).size()).toBe(0);

            var finder = configTabBar.findInput;
            expect(finder.size()).toBe(1);

            // Find sections that have the text "trigger" in them...
            keydowns('trigger', finder);

            // Need to wait for the change to happen ... there's a 300ms delay.
            // We could just call configTabBar.showSections(), but ...
            setTimeout(function() {
                expect($('.tab.hidden', tabBar).size()).toBe(3);
                expect(textCleanup($('.tab.hidden', tabBar).text())).toBe('General|#Advanced Project Options|#Build');

                var activeSection = configTabBar.activeSection();
                expect(textCleanup(activeSection.title)).toBe('#Build Triggers');

                expect($('.highlight-split .highlight').text()).toBe('Trigger');

                done();
            }, 600);
        }, 'widgets/config/freestyle-config-tabbed.html');
Beispiel #9
0
        jsTest.onPage(function() {
            var configTabBarWidget = jsTest.requireSrcModule('widgets/config/tabbar');
            var configTabBar = configTabBarWidget.addTabsOnFirst();

            // console.log('**** ' + configTabBar.sectionIds());
            // config_general,config__advanced_project_options,config__build_triggers,config__build

            var config_general = configTabBar.getSection('config_general');
            var config__advanced_project_options = configTabBar.getSection('config__advanced_project_options');
            var config__build_triggers = configTabBar.getSection('config__build_triggers');
            var config__build = configTabBar.getSection('config__build');

            expect(config_general.getSibling(-1)).toBeUndefined();
            expect(config_general.getSibling(0)).toBe(config_general);
            expect(config_general.getSibling(+1)).toBe(config__advanced_project_options);
            expect(config_general.getSibling(+2)).toBe(config__build_triggers);
            expect(config_general.getSibling(+3)).toBe(config__build);
            expect(config_general.getSibling(+4)).toBeUndefined();

            expect(config__advanced_project_options.getSibling(-2)).toBeUndefined();
            expect(config__advanced_project_options.getSibling(-1)).toBe(config_general);
            expect(config__advanced_project_options.getSibling(0)).toBe(config__advanced_project_options);
            expect(config__advanced_project_options.getSibling(+1)).toBe(config__build_triggers);
            expect(config__advanced_project_options.getSibling(+2)).toBe(config__build);
            expect(config__advanced_project_options.getSibling(+3)).toBeUndefined();

            done();
        }, 'widgets/config/freestyle-config-tabbed.html');
        jsTest.onPage(function() {
            // deps
            var jenkins = jsTest.requireSrcModule('./util/jenkins');

            var $ = getJQuery();
            $.ajax = ajaxMocks();

            var get = jenkins.get;
            try {
                // Respond with failure
            jenkins.get = function(url, cb) {
                if (debug) {
                        console.log('Jenkins.GET: ' + url);
                    }

                if(url === '/updateCenter/connectionStatus?siteId=default') {
                    cb({
                        status: 'ok',
                        data: {
                            updatesite: 'ERROR',
                            internet: 'ERROR'
                        }
                    });
                }
                else {
                    get(url, cb);
                }
                };

                // load the module
                var pluginSetupWizard = jsTest.requireSrcModule('pluginSetupWizardGui');

                // exported init
                pluginSetupWizard.init('body');

                expect($('.welcome-panel h1').text()).toBe('Offline');

            done();
            } finally {
            jenkins.get = get;
            }
        });
 jsTest.onPage(function() {
   var e = jsTest.requireSrcModule("editor");
   var stage = {"name" : "yeah", "steps" : [
       {"type": "git", "name" : "Clone webapp", "url" : "git@github.com/thing/awesome.git"},
       {"type": "git", "name" : "Clone webapp2", "url" : "git@github.com/thing/awesome.git"}  
     ]
     };        
   var block = e.normalStageBlock("ignore", stage);
   expect(block.indexOf("Clone webapp")).not.toBe(-1);
   expect(block.indexOf("Clone webapp2")).not.toBe(-1);      
   done();
 });
 jsTest.onPage(function() {
     var wf = jsTest.requireSrcModule("model/workflow");
     var stage = {"name": "yeah", "streams": [
         {"name": "Clone webapp"}
     ]
     };
     assert.equal(true, wf.isParallelStage(stage));
     stage = {"name": "yeah", "steps": [
         {"name": "Clone webapp"}
     ]
     };
     assert.equal(false, wf.isParallelStage(stage));
     done();
 });
    jsTest.onPage(function() {
        // deps
        var $ = getJQuery();

        // Respond to status request
        $.ajax = ajaxMocks(ajaxMappings);

        // load the module
        var pluginSetupWizard = jsTest.requireSrcModule('pluginSetupWizardGui');

        // exported init
        pluginSetupWizard.init('body');

        test($, pluginSetupWizard);
    });
Beispiel #14
0
        jsTest.onPage(function() {
            var tabbars = jsTest.requireSrcModule('config-tabbar.js');
            var firstTableMetadata = tabbars.tabs[0];

            var jQD = require('jquery-detached');
            var $ = jQD.getJQuery();

            expect($('.section-header-row', firstTableMetadata.configTable).size()).toBe(4);
            expect(firstTableMetadata.sectionCount()).toBe(4);
            expect($('.tabBar .tab').size()).toBe(4);

            expect(firstTableMetadata.sectionIds().toString())
                .toBe('config_general,config__advanced_project_options,config__build_triggers,config__build');

            done();
        }, 'widgets/config/freestyle-config-tabbed.html');
    it("restart required", function (done) {
        var jenkins = jsTest.requireSrcModule('util/jenkins');
        if(jenkins.originalPost) {
            jenkins.post = jenkins.originalPost;
        }

        var ajaxMappings = {
            '/jenkins/updateCenter/installStatus': new LastResponse([{
                status: 'ok',
                data: { // first, return nothing by default, no ongoing install
                    state: 'NEW',
                    jobs: []
                }
            },
            {
                status: 'ok',
                data: {
                    state: 'INSTALLING_PLUGINS',
                    jobs: [
                      {
                          name: 'subversion',
                          type: 'InstallJob',
                          installStatus: 'Success',
                          requiresRestart: 'true' // a string...
                      }
                  ]
                }
            }])
        };
        test(function($) {
            var goButton = $('.install-recommended');
            expect(goButton.size()).toBe(1);

            // validate a call to installPlugins with our defaults
        setTimeout(function() {
                expect($('.install-done').is(':visible')).toBe(false);

                expect($('.save-first-user').is(':visible')).toBe(true);

                done();
        }, 500);

            goButton.click();
        }, ajaxMappings);
    });
 jsTest.onPage(function() {
     var wf = jsTest.requireSrcModule("model/workflow");
     var pipe = [        
       {
         "name" : "Do It",
         "steps" : []
       }
     ];  
     assert.equal(0, pipe[0].steps.length);
     var newStep = {"type" : "sh", "command" :"x", "name": "foo"};
     var insertResult = wf.insertStep(pipe, "stage-0", newStep);
     assert.equal("stage-0-0", insertResult.actionId);
     assert.equal(1, pipe[0].steps.length);
     assert.deepEqual(newStep, pipe[0].steps[0]); 
     
     assert.equal("stage-0-1", wf.insertStep(pipe, "stage-0", newStep).actionId);
     done();
 });
Beispiel #17
0
        jsTest.onPage(function() {
            var configTabBarWidget = jsTest.requireSrcModule('widgets/config/tabbar');
            var configTabBar = configTabBarWidget.addTabsOnFirst();
            var jQD = require('jquery-detached');

            var $ = jQD.getJQuery();

            var tabBar = $('.tabBar');

            configTabBar.showSections('Strategy');
            expect($('.tab.hidden', tabBar).size()).toBe(3);
            expect(textCleanup($('.tab.hidden', tabBar).text())).toBe('#Advanced Project Options|#Build Triggers|#Build');

            var activeSection = configTabBar.activeSection();
            expect(textCleanup(activeSection.title)).toBe('General');

            done();
        }, 'widgets/config/freestyle-config-tabbed.html');
Beispiel #18
0
        jsTest.onPage(function() {
            var configTabBar = jsTest.requireSrcModule('widgets/config/tabbar');
            var firstTableMetadata = configTabBar.addTabsOnFirst();

            var generalSection = firstTableMetadata.activeSection();
            expect(generalSection.id).toBe('config_general');

            var sectionRowGroups = generalSection.rowGroups;

            expect(sectionRowGroups.length).toBe(1);
            expect(sectionRowGroups[0].getRowCount(false)).toBe(0); // zero because it does not have any non row-group rows nested immediately inside i.e. does not have any "normal" rows
            expect(sectionRowGroups[0].getRowCount(true)).toBe(4); // there are some nested down in the children. see below
            expect(sectionRowGroups[0].rowGroups.length).toBe(1);
            expect(sectionRowGroups[0].rowGroups[0].getRowCount(false)).toBe(4); // The inner grouping has rows
            expect(sectionRowGroups[0].rowGroups[0].getRowCount()).toBe(4); // Same as above ... just making sure they're direct child rows and not nested below
            expect(generalSection.getRowGroupLabels().toString()).toBe('Discard Old Builds');

            done();
        }, 'widgets/config/freestyle-config-tabbed.html');
 jsTest.onPage(function() {
   var wf = jsTest.requireSrcModule("model/workflow");
   var pipeline = [
     {
     "name" : "Prepare",
     "steps" : [          
           {"type": "sh", "name" : "Install Ruby", "command" : "/bin/ci/install_ruby version=2.0.1"},          
           {"type": "git", "name" : "Another thing", "command" : "/bin/ci/install_ruby version=2.0.1"}
       ]    
     }
   ];
   assert.equal(2, pipeline[0].steps.length);
   wf.removeActionId(pipeline, "stage-0-0"); 
   assert.equal(1, pipeline[0].steps.length);     
   var expect = {"type": "git", "name" : "Another thing", "command" : "/bin/ci/install_ruby version=2.0.1"};
   assert.deepEqual([expect], pipeline[0].steps);
   
   pipeline = [
     {
     "name" : "Prepare",
     "streams" : [
       {"name" : "Ruby", "steps" : [
           {"type": "sh", "name" : "Install Ruby", "command" : "/bin/ci/install_ruby version=2.0.1"}
         ]
       },            
       {"name" : "Ruby", "steps" : [
           {"type": "git", "name" : "Another thing", "command" : "/bin/ci/install_ruby version=2.0.1"}
         ]
       }           
      ]    
     }
   ];
   
   assert.equal(1, pipeline[0].streams[0].steps.length);       
   wf.removeActionId(pipeline, "stage-0-0-0"); 
   assert.equal(0, pipeline[0].streams[0].steps.length);     
   
   
   done();
 });
 jsTest.onPage(function() {
     var wf = jsTest.requireSrcModule("model/workflow");
     var pipe = [        
       {
         "name" : "first stage"          
       },
       {
         "name" : "Do It",
         "streams" : [
           {"name" : "Unit", "steps" : [
               {"type": "sh", "name" : "Run unit test suit", "command" : "/bin/ci/test"},                
             ]
           }
         ]    
       }
     ];  
     assert.equal(1, pipe[1].streams[0].steps.length);
     var newStep = {"type" : "sh", "command" :"x", "name": "foo"};
     var insertResult = wf.insertStep(pipe, "stage-1-0", newStep);
     assert.equal("stage-1-0-1", insertResult.actionId);
     assert.equal(2, pipe[1].streams[0].steps.length);
     done();
 });
var validatePlugins = function(plugins, complete) {
    var jenkins = jsTest.requireSrcModule('util/jenkins');
    if(!jenkins.originalPost) {
    jenkins.originalPost = jenkins.post;
    }
    jenkins.post = function(url, data, cb) {
        expect(url).toBe('/pluginManager/installPlugins');
        var allMatch = true;
        for(var i = 0; i < plugins.length; i++) {
        if(data.plugins.indexOf(plugins[i]) < 0) {
            allMatch = false;
            break;
        }
        }
        if(!allMatch) {
            expect(JSON.stringify(plugins)).toBe('In: ' + JSON.stringify(data.plugins));
        }
        // return status
        cb({status:'ok',data:{correlationId:1}});
        if(complete) {
        complete();
        }
    };
};
var jsTest = require('jenkins-js-test');
var storage = jsTest.requireSrcModule("model/json");
var assert = require("assert");


describe('json storage basics', function() {  
      it('should default pipeline', function () {
          assert.deepEqual(storage.simpleSample, storage.loadModelOrUseDefault(""));
          assert.deepEqual(storage.simpleSample, storage.loadModelOrUseDefault(null));
       }); 
       it('should load the pipeline', function () {
           assert.deepEqual([], storage.loadModelOrUseDefault("[]"));           
        });        
      }      
    );   
 jsTest.onPage(function() {
     var wf = jsTest.requireSrcModule("model/workflow");
     assert.deepEqual([0], wf.stageIdToCoordinates("stage-0"));
     assert.deepEqual([1,0], wf.stageIdToCoordinates("stage-1-0"));
     done();
 });
var jsTest = require("jenkins-js-test");
var jquery = require('jquery-detached');

var debug = false;

var getJQuery = function() {
    var $ = jquery.getJQuery();
    $.fx.off = true;
    return $;
};

var pluginList = jsTest.requireSrcModule('api/plugins');

pluginList.recommendedPlugins = ['subversion'];

// Iterates through all responses until the end and returns the last response repeatedly
var LastResponse = function(responses) {
    var counter = 0;
    this.next = function() {
        if(counter < responses.length) {
            try {
                return responses[counter];
            } finally {
                counter++;
            }
        }
        if(responses.length > 0) {
            return responses[counter-1];
        }
        return { status: 'fail' };
    };