Updating Regexper class specs to match style used elsewhere
This commit is contained in:
parent
66836e0552
commit
e19dc6a294
@ -377,132 +377,198 @@ describe('regexper.js', function() {
|
|||||||
spyOn(this.regexper, '_trackEvent');
|
spyOn(this.regexper, '_trackEvent');
|
||||||
spyOn(this.regexper, 'updateLinks');
|
spyOn(this.regexper, 'updateLinks');
|
||||||
spyOn(this.regexper, 'displayWarnings');
|
spyOn(this.regexper, 'displayWarnings');
|
||||||
|
|
||||||
this.regexper.renderRegexp('example expression');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets the state to "is-loading"', function() {
|
it('sets the state to "is-loading"', function() {
|
||||||
|
this.regexper.renderRegexp('example expression');
|
||||||
expect(this.regexper.state).toEqual('is-loading');
|
expect(this.regexper.state).toEqual('is-loading');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tracks the beginning of the render', function() {
|
it('tracks the beginning of the render', function() {
|
||||||
|
this.regexper.renderRegexp('example expression');
|
||||||
expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'start');
|
expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'start');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('keeps a copy of the running parser', function() {
|
it('keeps a copy of the running parser', function() {
|
||||||
|
this.regexper.renderRegexp('example expression');
|
||||||
expect(this.regexper.runningParser).toBeTruthy();
|
expect(this.regexper.runningParser).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('parses the expression', function() {
|
it('parses the expression', function() {
|
||||||
|
this.regexper.renderRegexp('example expression');
|
||||||
expect(this.regexper.runningParser.parse).toHaveBeenCalledWith('example expression');
|
expect(this.regexper.runningParser.parse).toHaveBeenCalledWith('example expression');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when parsing fails', function() {
|
describe('when parsing fails', function() {
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function() {
|
||||||
this.parsePromise.reject('example parse error');
|
this.parsePromise.reject(new Error('example parse error'));
|
||||||
|
|
||||||
setTimeout(done, 10);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets the state to be "has-error"', function() {
|
it('sets the state to be "has-error"', function(done) {
|
||||||
|
this.regexper.renderRegexp('example expression')
|
||||||
|
.then(fail, () => {
|
||||||
expect(this.regexper.state).toEqual('has-error');
|
expect(this.regexper.state).toEqual('has-error');
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('displays the error message', function() {
|
it('displays the error message', function(done) {
|
||||||
expect(this.regexper.error.innerHTML).toEqual('example parse error');
|
this.regexper.renderRegexp('example expression')
|
||||||
|
.then(fail, () => {
|
||||||
|
expect(this.regexper.error.innerHTML).toEqual('Error: example parse error');
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tracks the parse error', function() {
|
it('tracks the parse error', function(done) {
|
||||||
|
this.regexper.renderRegexp('example expression')
|
||||||
|
.then(fail, () => {
|
||||||
expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'parse error');
|
expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'parse error');
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when parsing succeeds', function() {
|
describe('when parsing succeeds', function() {
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function() {
|
||||||
this.parser = this.regexper.runningParser;
|
this.parser = new Parser();
|
||||||
this.parsePromise.resolve(this.parser);
|
this.parsePromise.resolve(this.parser);
|
||||||
|
this.renderPromise.resolve();
|
||||||
setTimeout(done, 10);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders the expression', function() {
|
it('renders the expression', function(done) {
|
||||||
|
this.regexper.renderRegexp('example expression')
|
||||||
|
.then(() => {
|
||||||
expect(this.parser.render).toHaveBeenCalledWith(this.regexper.svgContainer, this.regexper.svgBase);
|
expect(this.parser.render).toHaveBeenCalledWith(this.regexper.svgContainer, this.regexper.svgBase);
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when rendering is complete', function() {
|
describe('when rendering is complete', function() {
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function() {
|
||||||
this.parsePromise.resolve(this.regexper.runningParser);
|
this.parser = new Parser();
|
||||||
|
this.parsePromise.resolve(this.parser);
|
||||||
this.renderPromise.resolve();
|
this.renderPromise.resolve();
|
||||||
|
|
||||||
setTimeout(done, 10);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets the state to "has-results"', function() {
|
it('sets the state to "has-results"', function(done) {
|
||||||
|
this.regexper.renderRegexp('example expression')
|
||||||
|
.then(() => {
|
||||||
expect(this.regexper.state).toEqual('has-results');
|
expect(this.regexper.state).toEqual('has-results');
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates the links', function() {
|
it('updates the links', function(done) {
|
||||||
|
this.regexper.renderRegexp('example expression')
|
||||||
|
.then(() => {
|
||||||
expect(this.regexper.updateLinks).toHaveBeenCalled();
|
expect(this.regexper.updateLinks).toHaveBeenCalled();
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('displays the warnings', function() {
|
it('displays the warnings', function(done) {
|
||||||
|
this.regexper.renderRegexp('example expression')
|
||||||
|
.then(() => {
|
||||||
expect(this.regexper.displayWarnings).toHaveBeenCalled();
|
expect(this.regexper.displayWarnings).toHaveBeenCalled();
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tracks the complete render', function() {
|
it('tracks the complete render', function(done) {
|
||||||
|
this.regexper.renderRegexp('example expression')
|
||||||
|
.then(() => {
|
||||||
expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'complete');
|
expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'complete');
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets the runningParser to false', function() {
|
it('sets the runningParser to false', function(done) {
|
||||||
|
this.regexper.renderRegexp('example expression')
|
||||||
|
.then(() => {
|
||||||
expect(this.regexper.runningParser).toBeFalsy();
|
expect(this.regexper.runningParser).toBeFalsy();
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when the rendering is cancelled', function() {
|
describe('when the rendering is cancelled', function() {
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function() {
|
||||||
this.parsePromise.resolve(this.regexper.runningParser);
|
this.parser = new Parser();
|
||||||
|
this.parsePromise.resolve(this.parser);
|
||||||
this.renderPromise.reject('Render cancelled');
|
this.renderPromise.reject('Render cancelled');
|
||||||
|
|
||||||
setTimeout(done, 10);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('clears the state', function() {
|
it('clears the state', function(done) {
|
||||||
|
this.regexper.renderRegexp('example expression')
|
||||||
|
.then(() => {
|
||||||
expect(this.regexper.state).toEqual('');
|
expect(this.regexper.state).toEqual('');
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tracks the cancelled render', function() {
|
it('tracks the cancelled render', function(done) {
|
||||||
|
this.regexper.renderRegexp('example expression')
|
||||||
|
.then(() => {
|
||||||
expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'cancelled');
|
expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'cancelled');
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets the runningParser to false', function() {
|
it('sets the runningParser to false', function(done) {
|
||||||
|
this.regexper.renderRegexp('example expression')
|
||||||
|
.then(() => {
|
||||||
expect(this.regexper.runningParser).toBeFalsy();
|
expect(this.regexper.runningParser).toBeFalsy();
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when the rendering fails', function() {
|
describe('when the rendering fails', function() {
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function() {
|
||||||
this.parsePromise.resolve(this.regexper.runningParser);
|
this.parser = new Parser();
|
||||||
|
this.parsePromise.resolve(this.parser);
|
||||||
this.renderPromise.reject('example render failure');
|
this.renderPromise.reject('example render failure');
|
||||||
|
|
||||||
setTimeout(done, 10);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tracks the failed render', function() {
|
it('tracks the failed render', function(done) {
|
||||||
|
this.regexper.renderRegexp('example expression')
|
||||||
|
.then(fail, () => {
|
||||||
expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'exception');
|
expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'exception');
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets the runningParser to false', function() {
|
it('sets the runningParser to false', function(done) {
|
||||||
|
this.regexper.renderRegexp('example expression')
|
||||||
|
.then(fail, () => {
|
||||||
expect(this.regexper.runningParser).toBeFalsy();
|
expect(this.regexper.runningParser).toBeFalsy();
|
||||||
|
})
|
||||||
|
.finally(done)
|
||||||
|
.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user