Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing the loading... indicator when we have an error #269

Merged
merged 4 commits into from
Sep 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/oc-client/src/oc-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ var oc = oc || {};

oc.renderByHref($component.attr('href'), function(err, data){
if(err || !data){
$component.html('');
logger.error(err);
return callback();
}
Expand Down
12 changes: 6 additions & 6 deletions test/front-end/build-href.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

var nav = window.navigator.userAgent,
isIe8 = !!(nav.match(/MSIE 8/));
describe('oc-client : build', function(){

var execute = function(parameters){
return oc.build(parameters);
};
var nav = window.navigator.userAgent,
isIe8 = !!(nav.match(/MSIE 8/));

describe('oc-client : build', function(){
var execute = function(parameters){
return oc.build(parameters);
};

describe('when not providing the mandatory parameters', function(){

Expand Down
81 changes: 81 additions & 0 deletions test/front-end/render-nested-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
'use strict';

describe('oc-client : renderNestedComponent', function(){

var originalConsoleLog = console.log,
originalRenderByHref = oc.renderByHref,
htmlBeforeRendering,
nav = window.navigator.userAgent,
isIe8 = !!(nav.match(/MSIE 8/)),
componentHref = '//oc-registry.com/my-component/';

var componentContainer = isIe8 ?
'<div data-oc-component="true" href="' + componentHref + '"></div>' :
'<oc-component href="' + componentHref + '"></oc-component>';

var initialise = function($component, fail){
htmlBeforeRendering = '';

console.log = function(){};

oc.renderByHref = function(href, cb){
htmlBeforeRendering = $component.html();
cb(fail, {
html: '<div>this is the component content</div>',
version: '1.0.0',
name: 'my-component',
key: '12345678901234567890'
});
};
};

var cleanup = function(){
oc.renderByHref = originalRenderByHref;
console.log = originalConsoleLog;
delete oc.components;
oc.renderedComponents = {};
oc.events.reset();
};

describe('when rendering component successfully', function(){

var $component;

beforeEach(function(done){
$component = $(componentContainer);
initialise($component);
oc.renderNestedComponent($component, done);
});

afterEach(cleanup);

it('should show loading message first', function(){
expect(htmlBeforeRendering).toContain('Loading...');
});

it('should inject component html when rendering is done', function(){
expect($component.html()).toContain('this is the component content');
});
});

describe('when rendering component does not succeed', function(){

var $component;

beforeEach(function(done){
$component = $(componentContainer);
initialise($component, 'An error!');
oc.renderNestedComponent($component, done);
});

afterEach(cleanup);

it('should show loading message first', function(){
expect(htmlBeforeRendering).toContain('Loading...');
});

it('should remove loading message then', function(){
expect($component.html()).toEqual('');
});
});
});
9 changes: 7 additions & 2 deletions test/front-end/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,22 @@ describe('oc-client : render', function(){

describe('when handlebars runtime loaded and rendering a handlebars3 component', function(){

var callback;
var callback, originalConsolelog = console.log;
beforeEach(function(){
console.log = function(){};
callback = sinon.spy();
eval(handlebars3CompiledView);
eval(handlebars3CompiledView);
oc.render({
src: 'https://my-cdn.com/components/a-component/1.2.123/template.js',
type: 'handlebars',
key: '46ee85c314b371cac60471cef5b2e2e6c443dccf'
}, {}, callback);
});

afterEach(function(){
console.log = originalConsolelog;
});

it('should return the error', function(){ console.log(callback.args);
expect(callback.called).toBe(true);
expect(callback.args[0][0]).toContain('Template was precompiled with an older version of Handlebars than the current runtime');
Expand Down