Skip to content

Commit

Permalink
MTP-4377: Refactor to support file uploading progress
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmars committed Oct 25, 2016
1 parent b5e40bb commit d49c39d
Show file tree
Hide file tree
Showing 79 changed files with 423 additions and 499 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": [ "es2015" ]
"plugins": [ "transform-es2015-modules-commonjs" ]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ __coverage-*__/
.idea
.DS_Store
npm-debug.log
yarn.lock
32 changes: 3 additions & 29 deletions __mocks__/mindtouch-http.js → __mocks__/plug.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
class Response {
json() {
return Promise.resolve({});
}
text() {
return Promise.resolve('');
}
get headers() {
return this._get_headers();
}

// eslint-disable-next-line camelcase
_get_headers() {
return {
get: () => {
return '';
}
};
}
}
class Uri {
constructor(url) {
this.url = url;
}
get origin() {
return this.url;
}
}
/* eslint-env node */
const Response = require.requireActual('./response.js');
class Plug {
get url() {
return '';
Expand Down Expand Up @@ -58,4 +32,4 @@ class Plug {
return Promise.resolve(new Response());
}
}
export { Plug, Response, Uri };
module.exports = { Plug };
2 changes: 2 additions & 0 deletions __mocks__/progressPlugFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* eslint-env node */
module.exports = {};
22 changes: 22 additions & 0 deletions __mocks__/response.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-env node */
class Response {
json() {
return Promise.resolve({});
}
text() {
return Promise.resolve('');
}
get headers() {
return this._get_headers();
}

// eslint-disable-next-line camelcase
_get_headers() {
return {
get: () => {
return '';
}
};
}
}
module.exports = Response;
10 changes: 10 additions & 0 deletions __mocks__/uri.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-env node */
class Uri {
constructor(url) {
this.url = url;
}
get origin() {
return this.url;
}
}
module.exports = { Uri };
2 changes: 2 additions & 0 deletions __mocks__/uriParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* eslint-env node */
module.exports = {};
4 changes: 2 additions & 2 deletions __tests__/api.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env jasmine, jest */
jest.unmock('../api');
import { Api } from '../api';
jest.unmock('../api.js');
import { Api } from '../api.js';

describe('API Module', () => {
let api = null;
Expand Down
47 changes: 26 additions & 21 deletions __tests__/contextId.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
* limitations under the License.
*/
/* eslint-env jasmine, jest */
jest.unmock('../contextId');
import { ContextIdManager, ContextDefinition, ContextMap } from '../contextId';
jest.unmock('../contextId.js');
import { ContextIdManager, ContextDefinition, ContextMap } from '../contextId.js';

describe('Context ID', () => {
describe('Manager', () => {
let cm = null;
Expand All @@ -28,22 +29,22 @@ describe('Context ID', () => {
afterEach(() => {
cm = null;
});
pit('can fetch all context maps', () => {
it('can fetch all context maps', () => {
return cm.getMaps();
});
pit('can fetch the list of all context definitions', () => {
it('can fetch the list of all context definitions', () => {
return cm.getDefinitions();
});
pit('can fetch the list of all context definitions (empty response)', () => {
it('can fetch the list of all context definitions (empty response)', () => {
return cm.getDefinitions();
});
pit('can add a context ID definition', () => {
it('can add a context ID definition', () => {
return cm.addDefinition('foo');
});
pit('can add a context ID definition with a description', () => {
it('can add a context ID definition with a description', () => {
return cm.addDefinition('foo', 'Foo description');
});
pit('can fail if an ID is not supplied when trying to add a definition', () => {
it('can fail if an ID is not supplied when trying to add a definition', () => {
return cm.addDefinition().then((r) => {
expect(r).not.toBeDefined();
}).catch(() => {});
Expand Down Expand Up @@ -73,22 +74,21 @@ describe('Context ID', () => {
afterEach(() => {
def = null;
});
pit('can get the definition info', () => {
it('can get the definition info', () => {
return def.getInfo();
});
pit('can update the description of a definintion', () => {
it('can update the description of a definintion', () => {
return def.updateDescription('New Description');
});
pit('can implicitly clear the description of a definintion', () => {
it('can implicitly clear the description of a definintion', () => {
return def.updateDescription();
});
pit('can delete a definition', () => {
it('can delete a definition', () => {
return def.delete();
});
});
describe('Context Map constructor', () => {
it('can construct a new Context Map', () => {
expect(() => ContextMap()).toThrow();
expect(() => new ContextMap()).toThrow();
expect(() => new ContextMap('foo')).toThrow();
let cm = new ContextMap('en-us', 'foo');
Expand All @@ -103,18 +103,23 @@ describe('Context ID', () => {
afterEach(() => {
map = null;
});
pit('can get the info of a map', () => {
it('can get the info of a map', () => {
return map.getInfo();
});
pit('can update an existing map', () => {
it('can update an existing map', () => {
return map.update(123);
});
pit('can fail if an ID is not supplied when updating a map', () => {
return map.update().then((r) => {
expect(r).not.toBeDefined();
}).catch(() => {});
});
pit('can clear a mapping', () => {
it('can fail if an ID is not supplied when updating a map', () => {
const success = jest.fn();
return map.update().then(() => {
success();
throw new Error();
}).catch((e) => {
expect(success).not.toHaveBeenCalled();
expect(e).toBeDefined();
});
});
it('can clear a mapping', () => {
return map.remove();
});
});
Expand Down
6 changes: 3 additions & 3 deletions __tests__/draft.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* limitations under the License.
*/
/* eslint-env jasmine, jest */
jest.unmock('../draft');
jest.unmock('../pageBase');
import { DraftManager, Draft } from '../draft';
jest.unmock('../pageBase.js');
jest.unmock('../draft.js');
import { DraftManager, Draft } from '../draft.js';

describe('Draft', () => {
describe('draft manager', () => {
Expand Down
7 changes: 4 additions & 3 deletions __tests__/draftFile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
* limitations under the License.
*/
/* eslint-env jasmine, jest */
jest.unmock('../draftFile');
jest.unmock('../pageFileBase');
import { DraftFile } from '../draftFile';
jest.unmock('../pageFileBase.js');
jest.unmock('../draftFile.js');
import { DraftFile } from '../draftFile.js';

describe('Draft files', () => {
describe('constructor', () => {
it('can construct a new Draft File', () => {
Expand Down
12 changes: 6 additions & 6 deletions __tests__/file.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* limitations under the License.
*/
/* eslint-env jasmine, jest */
jest.unmock('../file');
import { File } from '../file';
jest.unmock('../file.js');
import { File } from '../file.js';

describe('File API', () => {
describe('constructor', () => {
Expand All @@ -36,16 +36,16 @@ describe('File API', () => {
afterEach(() => {
file = null;
});
pit('can fetch file info', () => {
it('can fetch file info', () => {
return file.getInfo();
});
pit('can fetch file revisions', () => {
it('can fetch file revisions', () => {
return file.getRevisions();
});
pit('can set the file description', () => {
it('can set the file description', () => {
return file.setDescription('This is the description');
});
pit('can delete a file', () => {
it('can delete a file', () => {
return file.delete();
});
});
Expand Down
5 changes: 3 additions & 2 deletions __tests__/groups.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
* limitations under the License.
*/
/* eslint-env jasmine, jest */
jest.unmock('../group');
import { GroupManager, Group } from '../group';
jest.unmock('../group.js');
import { GroupManager, Group } from '../group.js';

describe('Group API', () => {
let gm = null;
beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/learningPath.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* limitations under the License.
*/
/* eslint-env jasmine, jest */
jest.unmock('../learningPath');
import { LearningPathManager, LearningPath } from '../learningPath';
jest.unmock('../learningPath.js');
import { LearningPathManager, LearningPath } from '../learningPath.js';

describe('Learning Path API', () => {
let lpm = null;
Expand Down
23 changes: 12 additions & 11 deletions __tests__/page.custom.test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
/* eslint-env jasmine, jest */
jest.unmock('../pageBase');
jest.unmock('../page');
jest.unmock('../contextId');
jest.unmock('../lib/modelParser');
import { Plug, Response } from 'mindtouch-http';
import { Page } from '../page';
import { ContextIdManager } from '../contextId';
const Response = require.requireActual('../__mocks__/response.js');
const Plug = require.requireActual('../__mocks__/plug.js').Plug;

jest.unmock('../page.js');
jest.unmock('../pageBase.js');
jest.unmock('../contextId.js');
import { Page } from '../page.js';
import { ContextIdManager } from '../contextId.js';

describe('Special page Tests', () => {
beforeEach(() => {
Response.prototype.json = jest.fn(() => Promise.resolve({}));
Response.prototype.text = jest.fn(() => Promise.resolve(''));
Plug.prototype.get = jest.fn(() => Promise.resolve(new Response()));
});
pit('can fail on overview fetching', () => {
it('can fail on overview fetching', () => {
Response.prototype.json = jest.fn(() => Promise.reject());
let p = new Page();
return p.getOverview().then((r) => {
expect(r).not.toBeDefined();
}).catch(() => {});
});
pit('can fetch a virtual page', () => {
it('can fetch a virtual page', () => {
Plug.prototype.get = jest.fn(() => {
return Promise.reject({
message: 'Not found',
Expand All @@ -30,7 +31,7 @@ describe('Special page Tests', () => {
let p = new Page(123);
return p.getFullInfo();
});
pit('can get through virtual page checking when there is another failure', () => {
it('can get through virtual page checking when there is another failure', () => {
Plug.prototype.get = jest.fn(() => {
return Promise.reject({
message: 'Not found',
Expand Down
9 changes: 5 additions & 4 deletions __tests__/page.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
* limitations under the License.
*/
/* eslint-env jasmine, jest */
jest.unmock('../page');
jest.unmock('../pageBase');
import { Page, PageManager } from '../page';
jest.unmock('../pageBase.js');
jest.unmock('../page.js');
import { Page, PageManager } from '../page.js';

describe('Page', () => {
describe('constructor tests', () => {
it('can construct a new Page object using page ID', () => {
Expand Down Expand Up @@ -161,7 +162,7 @@ describe('Page', () => {
it('can delete pages recursively', () => {
return page.delete(true);
});
it('can attach a file to a page', () => {
xit('can attach a file to a page', () => {
const f = new File([], 'test.jpg');
return page.attachFile(f);
});
Expand Down
5 changes: 3 additions & 2 deletions __tests__/pageBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
* limitations under the License.
*/
/* eslint-env jasmine, jest */
jest.unmock('../pageBase');
import { PageBase } from '../pageBase';
jest.unmock('../pageBase.js');
import { PageBase } from '../pageBase.js';

describe('Page Base', () => {
it('can not construct a PageBase object directly', () => {
expect(() => new PageBase()).toThrowError(TypeError);
Expand Down
Loading

0 comments on commit d49c39d

Please sign in to comment.