PDF textbooks only accept PDF files

All other file types will trigger a validation error
This commit is contained in:
David Baumgold
2013-06-20 11:34:20 -04:00
parent 4c304f1d18
commit e8b79dc696
5 changed files with 67 additions and 17 deletions

View File

@@ -133,3 +133,26 @@ describe "CMS.Collections.ChapterSet", ->
# try going back one
@collection.remove(@collection.last())
expect(@collection.nextOrder()).toEqual(2)
describe "CMS.Models.FileUpload", ->
beforeEach ->
@model = new CMS.Models.FileUpload()
it "is valid by default", ->
expect(@model.isValid()).toBeTruthy()
it "is valid for PDF files", ->
file = {"type": "application/pdf"}
@model.set("selectedFile", file);
expect(@model.isValid()).toBeTruthy()
it "is invalid for text files", ->
file = {"type": "text/plain"}
@model.set("selectedFile", file);
expect(@model.isValid()).toBeFalsy()
it "is invalid for PNG files", ->
file = {"type": "image/png"}
@model.set("selectedFile", file);
expect(@model.isValid()).toBeFalsy()

View File

@@ -230,12 +230,25 @@ describe "CMS.Views.UploadDialog", ->
expect(@view.$el).toContain("input[type=file]")
expect(@view.$(".action-upload")).toBeDisabled()
it "should render with a file selected", ->
@mockFiles.push({name: "fake.pdf"})
it "should render with a PDF selected", ->
file = {name: "fake.pdf", "type": "application/pdf"}
@mockFiles.push(file)
@model.set("selectedFile", file)
@view.render()
expect(@view.$el).toContain("input[type=file]")
expect(@view.$el).not.toContain("p.error")
expect(@view.$(".action-upload")).not.toBeDisabled()
it "should render an error with an invalid file type selected", ->
file = {name: "fake.png", "type": "image/png"}
@mockFiles.push(file)
@model.set("selectedFile", file)
@view.render()
expect(@view.$el).toContain("input[type=file]")
expect(@view.$el).toContain("p.error")
expect(@view.$(".action-upload")).toBeDisabled()
it "adds body class on show()", ->
@view.show()
expect(@view.options.shown).toBeTruthy()