forked from bleenco/ngx-uploader
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moca/chai tests and new NgUploaderService setContentTypes method
- Loading branch information
Showing
4 changed files
with
99 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -7,4 +7,4 @@ lib/ | |
*.ngfactory.ts | ||
*.d.ts | ||
yarn.lock | ||
.idea | ||
.idea/ |
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,78 @@ | ||
import { NgUploaderService } from './ngx-uploader.class'; | ||
import { expect } from 'chai'; | ||
import 'mocha'; | ||
import { describe } from 'selenium-webdriver/testing'; | ||
|
||
import rewire = require('rewire'); | ||
let rewiredNgUploaderService = rewire('./ngx-uploader.class'); | ||
|
||
describe('NgUploaderService constructor', () => { | ||
it('without parameters should return allowedContentTypes = [\'*\']', () => { | ||
let uploader = new NgUploaderService(); | ||
expect(uploader.contentTypes).to.have.lengthOf(1); | ||
expect(uploader.contentTypes).to.be.an('array').that.contain('*'); | ||
}); | ||
|
||
it('should return [\'image/jpeg\']', () => { | ||
let uploader = new NgUploaderService(1, ['image/jpeg']); | ||
expect(uploader.contentTypes).to.have.lengthOf(1); | ||
expect(uploader.contentTypes).to.be.an('array').that.not.contain('*'); | ||
expect(uploader.contentTypes).to.be.an('array').that.contains('image/jpeg'); | ||
}); | ||
}); | ||
|
||
describe('setContentTypes function', () => { | ||
let uploader = new NgUploaderService(); | ||
|
||
it('should return [\'*\']', () => { | ||
uploader.setContentTypes(['*']); | ||
expect(uploader.contentTypes).to.have.lengthOf(1); | ||
expect(uploader.contentTypes).to.be.an('array').that.contain('*'); | ||
}); | ||
|
||
it('should return [\'image/jpeg\']', () => { | ||
uploader.setContentTypes(['image/jpeg']); | ||
expect(uploader.contentTypes).to.have.lengthOf(1); | ||
expect(uploader.contentTypes).to.be.an('array').that.contain('image/jpeg'); | ||
}); | ||
}); | ||
|
||
describe('isContentTypeAllowed function', () => { | ||
var private_uploader = rewiredNgUploaderService.__get__('NgUploaderService'); | ||
|
||
it('should return true', () => { | ||
let uploader = new private_uploader(); | ||
expect(uploader.isContentTypeAllowed('all/you-can-eat')).is.true; | ||
}); | ||
|
||
it('should return true', () => { | ||
let uploader = new private_uploader(1, ['image/jpeg', 'image/png', 'image/gif']); | ||
expect(uploader.isContentTypeAllowed('image/jpeg')).is.true; | ||
expect(uploader.isContentTypeAllowed('image/gif')).is.true; | ||
expect(uploader.isContentTypeAllowed('image/png')).is.true; | ||
}); | ||
|
||
it('should return false', () => { | ||
let uploader = new private_uploader(1, ['image/jpeg', 'image/png', 'image/gif']); | ||
expect(uploader.isContentTypeAllowed('image/webm')).is.false; | ||
}); | ||
}); | ||
|
||
describe('allContentTypesAllowed function', () => { | ||
let rewiredUploader = rewiredNgUploaderService.__get__('NgUploaderService'); | ||
|
||
it('should return true', () => { | ||
let uploader = new rewiredUploader(); | ||
expect(uploader.allContentTypesAllowed()).is.true; | ||
}); | ||
|
||
it('should return false', () => { | ||
let uploader = new rewiredUploader(1, ['image/jpeg', 'image/png', 'image/gif']); | ||
expect(uploader.allContentTypesAllowed()).is.false; | ||
}); | ||
}); | ||
|
||
|
||
|
||
|
||
|