Files
edx-platform/cms/static/coffee/spec/models/upload_spec.js
David Ormsbee 0880502f26 CoffeeScript tests migration: Decaffeinate files
This is running decaffeinate, with no additional cleanup.
2017-11-22 15:39:50 -05:00

94 lines
3.7 KiB
JavaScript

/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
define(["js/models/uploads"], FileUpload =>
describe("FileUpload", function() {
beforeEach(function() {
return this.model = new FileUpload();
});
it("is unfinished by default", function() {
return expect(this.model.get("finished")).toBeFalsy();
});
it("is not uploading by default", function() {
return expect(this.model.get("uploading")).toBeFalsy();
});
it("is valid by default", function() {
return expect(this.model.isValid()).toBeTruthy();
});
it("is valid for text files by default", function() {
const file = {"type": "text/plain", "name": "filename.txt"};
this.model.set("selectedFile", file);
return expect(this.model.isValid()).toBeTruthy();
});
it("is valid for PNG files by default", function() {
const file = {"type": "image/png", "name": "filename.png"};
this.model.set("selectedFile", file);
return expect(this.model.isValid()).toBeTruthy();
});
it("can accept a file type when explicitly set", function() {
const file = {"type": "image/png", "name": "filename.png"};
this.model.set({"mimeTypes": ["image/png"]});
this.model.set("selectedFile", file);
return expect(this.model.isValid()).toBeTruthy();
});
it("can accept a file format when explicitly set", function() {
const file = {"type": "", "name": "filename.png"};
this.model.set({"fileFormats": ["png"]});
this.model.set("selectedFile", file);
return expect(this.model.isValid()).toBeTruthy();
});
it("can accept multiple file types", function() {
const file = {"type": "image/gif", "name": "filename.gif"};
this.model.set({"mimeTypes": ["image/png", "image/jpeg", "image/gif"]});
this.model.set("selectedFile", file);
return expect(this.model.isValid()).toBeTruthy();
});
it("can accept multiple file formats", function() {
const file = {"type": "image/gif", "name": "filename.gif"};
this.model.set({"fileFormats": ["png", "jpeg", "gif"]});
this.model.set("selectedFile", file);
return expect(this.model.isValid()).toBeTruthy();
});
describe("fileTypes", () =>
it("returns a list of the uploader's file types", function() {
this.model.set('mimeTypes', ['image/png', 'application/json']);
this.model.set('fileFormats', ['gif', 'srt']);
return expect(this.model.fileTypes()).toEqual(['PNG', 'JSON', 'GIF', 'SRT']);
})
);
return describe("formatValidTypes", function() {
it("returns a map of formatted file types and extensions", function() {
this.model.set('mimeTypes', ['image/png', 'image/jpeg', 'application/json']);
const formatted = this.model.formatValidTypes();
return expect(formatted).toEqual({
fileTypes: 'PNG, JPEG or JSON',
fileExtensions: '.png, .jpeg or .json'
});
});
return it("does not format with only one mime type", function() {
this.model.set('mimeTypes', ['application/pdf']);
const formatted = this.model.formatValidTypes();
return expect(formatted).toEqual({
fileTypes: 'PDF',
fileExtensions: '.pdf'
});
});
});
})
);