-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from yandex-ui/errors.handling
ns.update и ns.view: отображение ошибок
- Loading branch information
Showing
13 changed files
with
234 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
dist | ||
node_modules | ||
*.yate.obj | ||
test/tests.yate.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
NPM_BIN=$(CURDIR)/node_modules/.bin | ||
export NPM_BIN | ||
|
||
yate: test/tests.yate.js | ||
|
||
test/tests.yate.js: test/tests.yate | ||
node_modules/.bin/yate test/tests.yate > test/tests.yate.js | ||
|
||
node_modules: package.json | ||
npm install | ||
touch node_modules | ||
|
||
clean-node_modules: | ||
rm -rf node_modules | ||
|
||
grunt: node_modules | ||
grunt: node_modules yate | ||
$(NPM_BIN)/grunt | ||
|
||
.PHONY: clean-node_modules grunt | ||
.PHONY: clean-node_modules grunt yate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
describe('ns.View error handling', function() { | ||
describe('ns.Update.handleError', function() { | ||
|
||
beforeEach(function() { | ||
ns.Model.define('letter', { params: { id: null } }); | ||
|
||
ns.View.define('app'); | ||
ns.View.define('letter', { models: [ 'letter' ] }); | ||
|
||
ns.layout.define('app', { | ||
'app': 'letter' | ||
}); | ||
|
||
this.APP = ns.View.create('app'); | ||
this.update = new ns.Update( | ||
this.APP, | ||
ns.layout.page('app', {}), | ||
{} | ||
); | ||
|
||
// Fake http server. | ||
this.server = sinon.fakeServer.create(); | ||
this.server.autoRespond = true; | ||
this.server.respondWith(/.*/, function(xhr, id) { | ||
xhr.respond( | ||
200, | ||
{ "Content-Type": "application/json" }, | ||
JSON.stringify({ models: [ { error: 'letter not found' } ] }) | ||
); | ||
}); | ||
}); | ||
|
||
afterEach(function() { | ||
ns.clean(); | ||
this.server.restore(); | ||
delete this.APP; | ||
delete this.update; | ||
}); | ||
|
||
it('render .ns-view-error-content template', function(finish) { | ||
var that = this; | ||
var update = this.update; | ||
ns.Update.handleError = function(_error, _update) { | ||
expect(_update).to.be(update); | ||
expect(_error.error).to.be('models'); | ||
return true; | ||
}; | ||
this.update.start().done(function() { | ||
expect($('.ns-view-letter', that.APP.node).html()).to.be('view-error-content'); | ||
finish(); | ||
}); | ||
}); | ||
|
||
it('pass error objects while rendering html', function(finish) { | ||
ns.Update.handleError = function(_error, _update) { | ||
return true; | ||
}; | ||
this.update.start().done(function() { | ||
var renderJSON = { | ||
'views': { | ||
'app': { | ||
'is_models_valid': true, | ||
'models': {}, | ||
'errors': {}, | ||
'views': { | ||
'letter': { | ||
'is_models_valid': false, | ||
'models': {}, | ||
'errors': { | ||
'letter': 'letter not found' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
expect(ns.tmpl.calledWithMatch(renderJSON)).to.be.ok(); | ||
finish(); | ||
}); | ||
}); | ||
|
||
it('if ns.Update.handleError() returns `false` update is rejected', function(finish) { | ||
ns.Update.handleError = function(_error, _update) { | ||
return false; | ||
}; | ||
this.update.start().fail(function() { | ||
finish(); | ||
}); | ||
}) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
it('Check yate templates are ready [run `make yate` if it fails]', function() { | ||
expect(yr.run('main', {}, 'check-yate-is-ready')).to.be('Ready'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module "main" | ||
|
||
include "../yate/noscript.yate" | ||
|
||
external scalar rand() | ||
|
||
match .* ns-view-add-attrs { | ||
@data-random="{ rand() }" | ||
} | ||
|
||
match .* ns-view-desc { | ||
@data-random="{ rand() }" | ||
apply /.views.* ns-view | ||
} | ||
|
||
match .* ns-view-async-content { | ||
@class += ' ns-async' | ||
"async-view-content" | ||
} | ||
|
||
// Это шаблон для проверки того, что yate сбилжен для тестов. | ||
match / check-yate-is-ready { | ||
"Ready" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var externals = yr.externals = yr.externals || {}; | ||
|
||
externals.rand = function() { | ||
return Math.random(); | ||
}; |
Oops, something went wrong.