fix(T2387): Use better file icons from SDW

Summary:
fix misc spec failure by making event store fetch immediately on setup

add specs for displayExtension, displayName

Test Plan: Run new tests

Reviewers: evan

Maniphest Tasks: T2387

Differential Revision: https://phab.nylas.com/D1821
This commit is contained in:
Ben Gotow 2015-07-31 12:34:24 -07:00
parent bf89ea8c64
commit 73ae6ea6f3
15 changed files with 51 additions and 5 deletions

View file

@ -28,7 +28,7 @@ class AttachmentComponent extends React.Component
<Flexbox direction="row" style={alignItems: 'center'}>
<RetinaImg className="file-icon"
fallback="file-fallback.png"
name="file-#{@_extension()}.png"/>
name="file-#{@props.file.displayExtension()}.png"/>
<span className="file-name">{@props.file.displayName()}</span>
{@_renderFileActions()}
</Flexbox>
@ -89,7 +89,5 @@ class AttachmentComponent extends React.Component
Actions.abortFetchFile(@props.file)
event.stopPropagation() # Prevent 'onClickView'
_extension: -> @props.file.filename.split('.').pop()
module.exports = AttachmentComponent

View file

@ -43,6 +43,7 @@ class FileUpload extends React.Component
_basename: =>
path.basename(@props.uploadData.filePath)
_extension: -> path.extname(@_basename()).split('.').pop()
_extension: =>
path.extname(@_basename())[1..-1]
module.exports = FileUpload

View file

@ -1,6 +1,43 @@
File = require '../../src/flux/models/file'
test_file_path = "/path/to/file.jpg"
describe "File", ->
it "attempts to generate a new file upload task on creation", ->
# File.create(test_file_path)
describe "displayName", ->
it "should return the filename if populated", ->
f = new File(filename: 'Hello world.jpg', contentType: 'image/jpg')
expect(f.displayName()).toBe('Hello world.jpg')
f = new File(filename: 'a', contentType: 'image/jpg')
expect(f.displayName()).toBe('a')
it "should return a good default name if a content type is populated", ->
f = new File(filename: '', contentType: 'image/jpg')
expect(f.displayName()).toBe('Unnamed Image.jpg')
f = new File(filename: null, contentType: 'image/jpg')
expect(f.displayName()).toBe('Unnamed Image.jpg')
f = new File(filename: null, contentType: 'text/calendar')
expect(f.displayName()).toBe('Event.ics')
it "should return Unnamed Attachment otherwise", ->
f = new File(filename: '', contentType: null)
expect(f.displayName()).toBe('Unnamed Attachment')
f = new File(filename: null, contentType: '')
expect(f.displayName()).toBe('Unnamed Attachment')
f = new File(filename: null, contentType: null)
expect(f.displayName()).toBe('Unnamed Attachment')
describe "displayExtension", ->
it "should return an extension based on the filename when populated", ->
f = new File(filename: 'Hello world.jpg', contentType: 'image/jpg')
expect(f.displayExtension()).toBe('jpg')
f = new File(filename: 'a', contentType: 'image/jpg')
expect(f.displayExtension()).toBe('')
it "should return an extension based on the default filename otherwise", ->
f = new File(filename: '', contentType: 'image/jpg')
expect(f.displayExtension()).toBe('jpg')
f = new File(filename: null, contentType: 'text/calendar')
expect(f.displayExtension()).toBe('ics')

View file

@ -62,4 +62,4 @@ describe "EventStore", ->
third = EventStore.getEvent(3)
expect(third.title).toBe 'Test3'
fourth = EventStore.getEvent(4)
expect(fourth.title).toBe 'Test4'
expect(fourth.title).toBe 'Test4'

View file

@ -1,3 +1,4 @@
path = require 'path'
Model = require './model'
Actions = require '../actions'
Attributes = require '../attributes'
@ -66,4 +67,13 @@ class File extends Model
else
return "Unnamed Attachment"
# Public: Returns the file extension that should be used for this file.
# Note that asking for the displayExtension is more accurate than trying to read
# the extension directly off the filename, and may be based on contentType.
#
# Returns the extension without the leading '.' (ex: 'png', 'pdf')
#
displayExtension: ->
path.extname(@displayName())[1..-1]
module.exports = File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 643 B

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 16 KiB