JSFiddle - React, Tailwind, and code Playground

by bryangrimes

HTML

<script src="http://code.angularjs.org/1.0.0rc2/angular-1.0.0rc2.js"></script> 
<script src="https://raw.github.com/pivotal/jasmine/master/lib/jasmine-core/jasmine.js"></script> 
<script src="https://raw.github.com/pivotal/jasmine/master/lib/jasmine-core/jasmine-html.js"></script>
<script src="http://code.angularjs.org/1.0.0rc2/angular-mocks-1.0.0rc2.js"></script>

CSS

body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }

#TrivialReporter { padding: 8px 13px; position: absolute; top: 0; bottom: 0; left: 0; right: 0; overflow-y: scroll; background-color: white; font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif; /*.resultMessage {*/ /*white-space: pre;*/ /*}*/ }
#TrivialReporter a:visited, #TrivialReporter a { color: #303; }
#TrivialReporter a:hover, #TrivialReporter a:active { color: blue; }
#TrivialReporter .run_spec { float: right; padding-right: 5px; font-size: .8em; text-decoration: none; }
#TrivialReporter .banner { color: #303; background-color: #fef; padding: 5px; }
#TrivialReporter .logo { float: left; font-size: 1.1em; padding-left: 5px; }
#TrivialReporter .logo .version { font-size: .6em; padding-left: 1em; }
#TrivialReporter .runner.running { background-color: yellow; }
#TrivialReporter .options { text-align: right; font-size: .8em; }
#TrivialReporter .suite { border: 1px outset gray; margin: 5px 0; padding-left: 1em; }
#TrivialReporter .suite .suite { margin: 5px; }
#TrivialReporter .suite.passed { background-color: #dfd; }
#TrivialReporter .suite.failed { background-color: #fdd; }
#TrivialReporter .spec { margin: 5px; padding-left: 1em; clear: both; }
#TrivialReporter .spec.failed, #TrivialReporter .spec.passed, #TrivialReporter .spec.skipped { padding-bottom: 5px; border: 1px solid gray; }
#TrivialReporter .spec.failed { background-color: #fbb; border-color: red; }
#TrivialReporter .spec.passed { background-color: #bfb; border-color: green; }
#TrivialReporter .spec.skipped { background-color: #bbb; }
#TrivialReporter .messages { border-left: 1px dashed gray; padding-left: 1em; padding-right: 1em; }
#TrivialReporter .passed { background-color: #cfc; display: none; }
#TrivialReporter .failed { background-color: #fbb; }
#TrivialReporter .skipped { color: #777; background-color: #eee; display: none; }
#TrivialReporter .resultMessage span.result { display:...

JavaScript

var apiUri = '/proxy/localhost/api/offer';

function HomeCtrl($scope, offerFactory) {
    offerFactory.getApi().then(function (offerApi) {
        if (offerApi.collection.template) {
            buildSortOrder(offerApi.collection.template.data);

            $scope.canCreateOffer = true;
        }
        else {
            $scope.canCreateOffer = false;
        }

        $scope.offerApi = offerApi;
    });
}

var offerModule = angular.module('offerServices', []);
offerModule.factory('offerFactory', function($http) {
    var service = {
        getApi: function() {     
            var promise = $http.get(apiUri, { cache: true }).error(function (data) {
                notification('error', data);
            }).then(function (response) {
                return response.data;
            });
          
          return promise;
        }
    };
    return service;
});

describe('HomeCtrl', function() {
        var scope, ctrl, $httpBackend;

        beforeEach(module('offerServices')); 

        beforeEach(inject(function($httpBackend, $rootScope, $controller) {
           // httpBackend = $httpBackend
            $httpBackend.whenGET(apiUri).respond(200, 'just some content', {header: 'one'});
          
            scope = $rootScope.$new();
            ctrl  = $controller(HomeCtrl, {$scope: scope});
        }));
  
        it('should get offer model with two offers', function() {
            //console.log(scope.offer);
            //$httpBackend.flush();

            //expect(scope.offer).toEqualData([{name: 'Custom Offer'}, {name: 'Standard Offer'}]);
            //console.log(scope);
          
            expect(scope).toBeDefined();
        });
    });


// KICK OFF JASMINE
var jasmineEnv = jasmine.getEnv();
var trivialReporter = new jasmine.TrivialReporter();

jasmineEnv.addReporter(trivialReporter);

jasmineEnv.specFilter = function(spec) {
    return trivialReporter.specFilter(spec);
};

jasmineEnv.execute();