-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix(ts): changed
file.types
type to work with both ts 2.0 and 2.…
…1. (closes #236) (#241) * fix file.types type to work with both ts 2.0 and 2.1 * unit tests for file-drop.directive * initial unit testing for file-select.directive * fix tslint errors * upgrade depdencies to @angular@2.4.2 and [email protected] * added unit tests for file-upload.component * upgrade tslint and codelyzer for 2.1.4 support * moved some rules into the tsconfig.json * fix linting issues with upgraded tslint
- Loading branch information
1 parent
b297746
commit 48cdbca
Showing
22 changed files
with
543 additions
and
146 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 |
---|---|---|
|
@@ -51,16 +51,16 @@ | |
"Ilsun Park <[email protected]>" | ||
], | ||
"dependencies": { | ||
"@angular/common": "^2.4.1", | ||
"@angular/compiler": "^2.4.1", | ||
"@angular/core": "^2.4.1", | ||
"@angular/forms": "^2.4.1", | ||
"@angular/http": "^2.4.1", | ||
"@angular/common": "^2.4.2", | ||
"@angular/compiler": "^2.4.2", | ||
"@angular/core": "^2.4.2", | ||
"@angular/forms": "^2.4.2", | ||
"@angular/http": "^2.4.2", | ||
"@angular/material": "2.0.0-beta.1", | ||
"@angular/platform-browser": "^2.4.1", | ||
"@angular/platform-browser-dynamic": "^2.4.1", | ||
"@angular/platform-server": "^2.4.1", | ||
"@angular/router": "^3.4.1", | ||
"@angular/platform-browser": "^2.4.2", | ||
"@angular/platform-browser-dynamic": "^2.4.2", | ||
"@angular/platform-server": "^2.4.2", | ||
"@angular/router": "^3.4.2", | ||
"core-js": "^2.4.1", | ||
"hammerjs": "^2.0.8", | ||
"highlight.js": "9.6.0", | ||
|
@@ -70,14 +70,14 @@ | |
"d3": "^4.2.1" | ||
}, | ||
"devDependencies": { | ||
"@angular/compiler-cli": "^2.4.1", | ||
"@angular/compiler-cli": "^2.4.2", | ||
"@types/hammerjs": "^2.0.30", | ||
"@types/jasmine": "^2.2.31", | ||
"@types/node": "^6.0.34", | ||
"@types/selenium-webdriver": "^2.52.0", | ||
"angular-cli": "1.0.0-beta.24", | ||
"awesome-typescript-loader": "^2.2.4", | ||
"codelyzer": "~0.0.26", | ||
"codelyzer": "2.0.0-beta.4", | ||
"coveralls": "^2.11.15", | ||
"ember-cli-inject-live-reload": "1.4.0", | ||
"glob": "^6.0.4", | ||
|
@@ -87,7 +87,7 @@ | |
"gulp-if": "2.0.1", | ||
"gulp-sass": "2.3.2", | ||
"gulp-sourcemaps": "1.6.0", | ||
"gulp-typescript": "3.0.1", | ||
"gulp-typescript": "3.1.4", | ||
"gulp-util": "3.0.7", | ||
"jasmine-core": "^2.4.1", | ||
"jasmine-spec-reporter": "2.5.0", | ||
|
@@ -109,7 +109,7 @@ | |
"sass-loader": "^4.0.2", | ||
"semver": "5.2.0", | ||
"ts-node": "1.2.1", | ||
"tslint": "^3.15.1", | ||
"typescript": "2.0.10" | ||
"tslint": "^4.1.1", | ||
"typescript": "2.1.4" | ||
} | ||
} |
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
231 changes: 231 additions & 0 deletions
231
src/platform/core/file/directives/file-drop.directive.spec.ts
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,231 @@ | ||
import { | ||
TestBed, | ||
inject, | ||
async, | ||
ComponentFixture, | ||
} from '@angular/core/testing'; | ||
import { Component, DebugElement } from '@angular/core'; | ||
import { CovalentFileModule, TdFileDropDirective } from '../file.module'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
describe('Directive: FileDrop', () => { | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ | ||
TdFileDropBasicTestComponent, | ||
], | ||
imports: [ | ||
CovalentFileModule.forRoot(), | ||
], | ||
}); | ||
TestBed.compileComponents(); | ||
})); | ||
|
||
it('should add/remove class on dragenter and dragleave', | ||
async(inject([], () => { | ||
let fixture: ComponentFixture<any> = TestBed.createComponent(TdFileDropBasicTestComponent); | ||
let component: TdFileDropBasicTestComponent = fixture.debugElement.componentInstance; | ||
component.multiple = false; | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
let directive: DebugElement = fixture.debugElement.query(By.directive(TdFileDropDirective)); | ||
directive.triggerEventHandler('dragenter', new Event('dragenter')); | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
expect(directive.classes['drop-zone']).toBeTruthy(); | ||
directive.triggerEventHandler('dragleave', new Event('dragleave')); | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
expect(directive.classes['drop-zone']).toBeFalsy(); | ||
}); | ||
}); | ||
}); | ||
}))); | ||
|
||
it('should disable element and not add class on dragenter', | ||
async(inject([], () => { | ||
let fixture: ComponentFixture<any> = TestBed.createComponent(TdFileDropBasicTestComponent); | ||
let component: TdFileDropBasicTestComponent = fixture.debugElement.componentInstance; | ||
component.disabled = true; | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
let directive: DebugElement = fixture.debugElement.query(By.directive(TdFileDropDirective)); | ||
directive.triggerEventHandler('dragenter', new Event('dragenter')); | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
expect(directive.classes['drop-zone']).toBeFalsy(); | ||
}); | ||
}); | ||
}))); | ||
|
||
it('should throw dragover event and add copy dropEffect for a single file', | ||
async(inject([], () => { | ||
let fixture: ComponentFixture<any> = TestBed.createComponent(TdFileDropBasicTestComponent); | ||
let component: TdFileDropBasicTestComponent = fixture.debugElement.componentInstance; | ||
component.multiple = false; | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
let directive: DebugElement = fixture.debugElement.query(By.directive(TdFileDropDirective)); | ||
let event: any = <DragEvent>new Event('dragover'); | ||
event.dataTransfer = { | ||
dropEffect: 'none', | ||
types: ['Files'], | ||
items: ['file-name.txt'], | ||
}; | ||
directive.triggerEventHandler('dragover', event); | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
expect(event.dataTransfer.dropEffect).toBe('copy'); | ||
}); | ||
}); | ||
}))); | ||
|
||
it('should throw dragover event and not add copy dropEffect for a multiple file', | ||
async(inject([], () => { | ||
let fixture: ComponentFixture<any> = TestBed.createComponent(TdFileDropBasicTestComponent); | ||
let component: TdFileDropBasicTestComponent = fixture.debugElement.componentInstance; | ||
component.multiple = false; | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
let directive: DebugElement = fixture.debugElement.query(By.directive(TdFileDropDirective)); | ||
let event: any = <DragEvent>new Event('dragover'); | ||
event.dataTransfer = { | ||
dropEffect: 'none', | ||
types: ['Files'], | ||
items: ['file-name.txt', 'file-name1.txt'], | ||
}; | ||
directive.triggerEventHandler('dragover', event); | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
expect(event.dataTransfer.dropEffect).toBe('none'); | ||
}); | ||
}); | ||
}))); | ||
|
||
it('should throw dragover event and add copy dropEffect for a multiple file', | ||
async(inject([], () => { | ||
let fixture: ComponentFixture<any> = TestBed.createComponent(TdFileDropBasicTestComponent); | ||
let component: TdFileDropBasicTestComponent = fixture.debugElement.componentInstance; | ||
component.multiple = true; | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
let directive: DebugElement = fixture.debugElement.query(By.directive(TdFileDropDirective)); | ||
let event: any = <DragEvent>new Event('dragover'); | ||
event.dataTransfer = { | ||
dropEffect: 'none', | ||
types: ['Files'], | ||
items: ['file-name.txt', 'file-name1.txt'], | ||
}; | ||
directive.triggerEventHandler('dragover', event); | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
expect(event.dataTransfer.dropEffect).toBe('copy'); | ||
}); | ||
}); | ||
}))); | ||
|
||
it('should throw dragover event and not add copy dropEffect on disabled state', | ||
async(inject([], () => { | ||
let fixture: ComponentFixture<any> = TestBed.createComponent(TdFileDropBasicTestComponent); | ||
let component: TdFileDropBasicTestComponent = fixture.debugElement.componentInstance; | ||
component.multiple = false; | ||
component.disabled = true; | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
let directive: DebugElement = fixture.debugElement.query(By.directive(TdFileDropDirective)); | ||
let event: any = <DragEvent>new Event('dragover'); | ||
event.dataTransfer = { | ||
dropEffect: 'none', | ||
types: ['Files'], | ||
items: ['file-name.txt'], | ||
}; | ||
directive.triggerEventHandler('dragover', event); | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
expect(event.dataTransfer.dropEffect).toBe('none'); | ||
}); | ||
}); | ||
}))); | ||
|
||
it('should throw ondrop event for a single file', | ||
async(inject([], () => { | ||
let fixture: ComponentFixture<any> = TestBed.createComponent(TdFileDropBasicTestComponent); | ||
let component: TdFileDropBasicTestComponent = fixture.debugElement.componentInstance; | ||
component.multiple = false; | ||
expect(component.files).toBeFalsy(); | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
let directive: DebugElement = fixture.debugElement.query(By.directive(TdFileDropDirective)); | ||
let event: any = <DragEvent>new Event('drop'); | ||
event.dataTransfer = { | ||
files: [{}], | ||
}; | ||
directive.triggerEventHandler('drop', event); | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
expect(component.files).toBeTruthy(); | ||
}); | ||
}); | ||
}))); | ||
|
||
it('should throw ondrop event for a multiple files', | ||
async(inject([], () => { | ||
let fixture: ComponentFixture<any> = TestBed.createComponent(TdFileDropBasicTestComponent); | ||
let component: TdFileDropBasicTestComponent = fixture.debugElement.componentInstance; | ||
component.multiple = true; | ||
expect(component.files).toBeFalsy(); | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
let directive: DebugElement = fixture.debugElement.query(By.directive(TdFileDropDirective)); | ||
let event: any = <DragEvent>new Event('drop'); | ||
event.dataTransfer = { | ||
files: [{}, {}], | ||
}; | ||
directive.triggerEventHandler('drop', event); | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
expect((<FileList>component.files).length).toBe(2); | ||
}); | ||
}); | ||
}))); | ||
|
||
it('should not throw ondrop event for disabled state', | ||
async(inject([], () => { | ||
let fixture: ComponentFixture<any> = TestBed.createComponent(TdFileDropBasicTestComponent); | ||
let component: TdFileDropBasicTestComponent = fixture.debugElement.componentInstance; | ||
component.disabled = true; | ||
expect(component.files).toBeFalsy(); | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
let directive: DebugElement = fixture.debugElement.query(By.directive(TdFileDropDirective)); | ||
let event: any = <DragEvent>new Event('drop'); | ||
event.dataTransfer = { | ||
files: [{}], | ||
}; | ||
directive.triggerEventHandler('drop', event); | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { | ||
expect(component.files).toBeFalsy(); | ||
}); | ||
}); | ||
}))); | ||
|
||
}); | ||
|
||
@Component({ | ||
selector: 'td-file-drop-basic-test', | ||
template: ` | ||
<div tdFileDrop | ||
[multiple]="multiple" | ||
[disabled]="disabled" | ||
(fileDrop)="files = $event"> | ||
</div> | ||
`, | ||
}) | ||
class TdFileDropBasicTestComponent { | ||
multiple: boolean; | ||
disabled: boolean; | ||
files: FileList | File; | ||
} |
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
Oops, something went wrong.