mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-11 07:00:47 +02:00
Merge pull request #3495 from overleaf/ae-prettier-2
Upgrade Prettier to v2 GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
@@ -20,8 +20,8 @@ const MockRequest = require('../helpers/MockRequest')
|
||||
const MockResponse = require('../helpers/MockResponse')
|
||||
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
||||
|
||||
describe('DocumentController', function() {
|
||||
beforeEach(function() {
|
||||
describe('DocumentController', function () {
|
||||
beforeEach(function () {
|
||||
this.DocumentController = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'../Project/ProjectGetter': (this.ProjectGetter = {}),
|
||||
@@ -44,24 +44,24 @@ describe('DocumentController', function() {
|
||||
return (this.rev = 5)
|
||||
})
|
||||
|
||||
describe('getDocument', function() {
|
||||
beforeEach(function() {
|
||||
describe('getDocument', function () {
|
||||
beforeEach(function () {
|
||||
return (this.req.params = {
|
||||
Project_id: this.project_id,
|
||||
doc_id: this.doc_id
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the project exists without project history enabled', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the project exists without project history enabled', function () {
|
||||
beforeEach(function () {
|
||||
this.project = { _id: this.project_id }
|
||||
return (this.ProjectGetter.getProject = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, this.project))
|
||||
})
|
||||
|
||||
describe('when the document exists', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the document exists', function () {
|
||||
beforeEach(function () {
|
||||
this.doc = { _id: this.doc_id }
|
||||
this.ProjectLocator.findElement = sinon
|
||||
.stub()
|
||||
@@ -83,13 +83,13 @@ describe('DocumentController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should get the project', function() {
|
||||
it('should get the project', function () {
|
||||
return this.ProjectGetter.getProject
|
||||
.calledWith(this.project_id, { rootFolder: true, overleaf: true })
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should get the pathname of the document', function() {
|
||||
it('should get the pathname of the document', function () {
|
||||
return this.ProjectLocator.findElement
|
||||
.calledWith({
|
||||
project: this.project,
|
||||
@@ -99,13 +99,13 @@ describe('DocumentController', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should get the document content', function() {
|
||||
it('should get the document content', function () {
|
||||
return this.ProjectEntityHandler.getDoc
|
||||
.calledWith(this.project_id, this.doc_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should return the document data to the client as JSON', function() {
|
||||
it('should return the document data to the client as JSON', function () {
|
||||
this.res.type.should.equal('application/json')
|
||||
return this.res.body.should.equal(
|
||||
JSON.stringify({
|
||||
@@ -118,8 +118,8 @@ describe('DocumentController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe("when the document doesn't exist", function() {
|
||||
beforeEach(function() {
|
||||
describe("when the document doesn't exist", function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectLocator.findElement = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, new Errors.NotFoundError('not found'))
|
||||
@@ -130,7 +130,7 @@ describe('DocumentController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call next with the NotFoundError', function() {
|
||||
it('should call next with the NotFoundError', function () {
|
||||
return this.next
|
||||
.calledWith(sinon.match.instanceOf(Errors.NotFoundError))
|
||||
.should.equal(true)
|
||||
@@ -138,8 +138,8 @@ describe('DocumentController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when project exists with project history enabled', function() {
|
||||
beforeEach(function() {
|
||||
describe('when project exists with project history enabled', function () {
|
||||
beforeEach(function () {
|
||||
this.doc = { _id: this.doc_id }
|
||||
this.projectHistoryId = 1234
|
||||
this.projectHistoryDisplay = true
|
||||
@@ -176,7 +176,7 @@ describe('DocumentController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should return the history id and display setting to the client as JSON', function() {
|
||||
it('should return the history id and display setting to the client as JSON', function () {
|
||||
this.res.type.should.equal('application/json')
|
||||
return this.res.body.should.equal(
|
||||
JSON.stringify({
|
||||
@@ -191,8 +191,8 @@ describe('DocumentController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the project does not exist', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the project does not exist', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, null)
|
||||
return this.DocumentController.getDocument(
|
||||
this.req,
|
||||
@@ -201,22 +201,22 @@ describe('DocumentController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('returns a 404', function() {
|
||||
it('returns a 404', function () {
|
||||
return this.res.statusCode.should.equal(404)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('setDocument', function() {
|
||||
beforeEach(function() {
|
||||
describe('setDocument', function () {
|
||||
beforeEach(function () {
|
||||
return (this.req.params = {
|
||||
Project_id: this.project_id,
|
||||
doc_id: this.doc_id
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the document exists', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the document exists', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectEntityUpdateHandler.updateDocLines = sinon.stub().yields()
|
||||
this.req.body = {
|
||||
lines: this.doc_lines,
|
||||
@@ -232,7 +232,7 @@ describe('DocumentController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should update the document in Mongo', function() {
|
||||
it('should update the document in Mongo', function () {
|
||||
return sinon.assert.calledWith(
|
||||
this.ProjectEntityUpdateHandler.updateDocLines,
|
||||
this.project_id,
|
||||
@@ -245,13 +245,13 @@ describe('DocumentController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should return a successful response', function() {
|
||||
it('should return a successful response', function () {
|
||||
return this.res.success.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when the document doesn't exist", function() {
|
||||
beforeEach(function() {
|
||||
describe("when the document doesn't exist", function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectEntityUpdateHandler.updateDocLines = sinon
|
||||
.stub()
|
||||
.yields(new Errors.NotFoundError('document does not exist'))
|
||||
@@ -263,7 +263,7 @@ describe('DocumentController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call next with the NotFoundError', function() {
|
||||
it('should call next with the NotFoundError', function () {
|
||||
return this.next
|
||||
.calledWith(sinon.match.instanceOf(Errors.NotFoundError))
|
||||
.should.equal(true)
|
||||
|
||||
@@ -15,55 +15,55 @@ const { expect } = require('chai')
|
||||
const modulePath = '../../../../app/src/Features/Documents/DocumentHelper.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe('DocumentHelper', function() {
|
||||
beforeEach(function() {
|
||||
describe('DocumentHelper', function () {
|
||||
beforeEach(function () {
|
||||
return (this.DocumentHelper = SandboxedModule.require(modulePath))
|
||||
})
|
||||
|
||||
describe('getTitleFromTexContent', function() {
|
||||
it('should return the title', function() {
|
||||
describe('getTitleFromTexContent', function () {
|
||||
it('should return the title', function () {
|
||||
const document = '\\begin{document}\n\\title{foo}\n\\end{document}'
|
||||
return expect(
|
||||
this.DocumentHelper.getTitleFromTexContent(document)
|
||||
).to.equal('foo')
|
||||
})
|
||||
|
||||
it('should return the title if surrounded by space', function() {
|
||||
it('should return the title if surrounded by space', function () {
|
||||
const document = '\\begin{document}\n \\title{foo} \n\\end{document}'
|
||||
return expect(
|
||||
this.DocumentHelper.getTitleFromTexContent(document)
|
||||
).to.equal('foo')
|
||||
})
|
||||
|
||||
it('should return null if there is no title', function() {
|
||||
it('should return null if there is no title', function () {
|
||||
const document = '\\begin{document}\n\\end{document}'
|
||||
return expect(
|
||||
this.DocumentHelper.getTitleFromTexContent(document)
|
||||
).to.eql(null)
|
||||
})
|
||||
|
||||
it('should accept an array', function() {
|
||||
it('should accept an array', function () {
|
||||
const document = ['\\begin{document}', '\\title{foo}', '\\end{document}']
|
||||
return expect(
|
||||
this.DocumentHelper.getTitleFromTexContent(document)
|
||||
).to.equal('foo')
|
||||
})
|
||||
|
||||
it('should parse out formatting elements from the title', function() {
|
||||
it('should parse out formatting elements from the title', function () {
|
||||
const document = '\\title{\\textbf{\\large{Second Year LaTeX Exercise}}}'
|
||||
return expect(
|
||||
this.DocumentHelper.getTitleFromTexContent(document)
|
||||
).to.equal('Second Year LaTeX Exercise')
|
||||
})
|
||||
|
||||
it('should ignore junk after the title', function() {
|
||||
it('should ignore junk after the title', function () {
|
||||
const document = '\\title{wombat} potato'
|
||||
return expect(
|
||||
this.DocumentHelper.getTitleFromTexContent(document)
|
||||
).to.equal('wombat')
|
||||
})
|
||||
|
||||
it('should ignore junk before the title', function() {
|
||||
it('should ignore junk before the title', function () {
|
||||
const document =
|
||||
'% this is something that v1 relied on, even though it seems odd \\title{wombat}'
|
||||
return expect(
|
||||
@@ -76,7 +76,7 @@ describe('DocumentHelper', function() {
|
||||
// document = "\\title{Second Year \\large{LaTeX} Exercise}"
|
||||
// expect(@DocumentHelper.getTitleFromTexContent(document)).to.equal "Second Year LaTeX Exercise"
|
||||
|
||||
it('should collapse whitespace', function() {
|
||||
it('should collapse whitespace', function () {
|
||||
const document = '\\title{Second Year LaTeX Exercise}'
|
||||
return expect(
|
||||
this.DocumentHelper.getTitleFromTexContent(document)
|
||||
@@ -84,27 +84,27 @@ describe('DocumentHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('detex', function() {
|
||||
describe('detex', function () {
|
||||
// note, there are a number of tests for getTitleFromTexContent that also test cases here
|
||||
it('leaves a non-TeX string unchanged', function() {
|
||||
it('leaves a non-TeX string unchanged', function () {
|
||||
expect(this.DocumentHelper.detex('')).to.equal('')
|
||||
expect(this.DocumentHelper.detex('a')).to.equal('a')
|
||||
return expect(this.DocumentHelper.detex('a a')).to.equal('a a')
|
||||
})
|
||||
|
||||
it('collapses spaces', function() {
|
||||
it('collapses spaces', function () {
|
||||
expect(this.DocumentHelper.detex('a a')).to.equal('a a')
|
||||
return expect(this.DocumentHelper.detex('a \n a')).to.equal('a \n a')
|
||||
})
|
||||
|
||||
it('replaces named commands', function() {
|
||||
it('replaces named commands', function () {
|
||||
expect(this.DocumentHelper.detex('\\LaTeX')).to.equal('LaTeX')
|
||||
expect(this.DocumentHelper.detex('\\TikZ')).to.equal('TikZ')
|
||||
expect(this.DocumentHelper.detex('\\TeX')).to.equal('TeX')
|
||||
return expect(this.DocumentHelper.detex('\\BibTeX')).to.equal('BibTeX')
|
||||
})
|
||||
|
||||
it('removes general commands', function() {
|
||||
it('removes general commands', function () {
|
||||
expect(this.DocumentHelper.detex('\\foo')).to.equal('')
|
||||
expect(this.DocumentHelper.detex('\\foo{}')).to.equal('')
|
||||
expect(this.DocumentHelper.detex('\\foo~Test')).to.equal('Test')
|
||||
@@ -112,35 +112,35 @@ describe('DocumentHelper', function() {
|
||||
return expect(this.DocumentHelper.detex('\\textit{e}')).to.equal('e')
|
||||
})
|
||||
|
||||
it('leaves basic math', function() {
|
||||
it('leaves basic math', function () {
|
||||
return expect(this.DocumentHelper.detex('$\\cal{O}(n^2)$')).to.equal(
|
||||
'O(n^2)'
|
||||
)
|
||||
})
|
||||
|
||||
it('removes line spacing commands', function() {
|
||||
it('removes line spacing commands', function () {
|
||||
return expect(this.DocumentHelper.detex('a \\\\[1.50cm] b')).to.equal(
|
||||
'a b'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('contentHasDocumentclass', function() {
|
||||
it('should return true if the content has a documentclass', function() {
|
||||
describe('contentHasDocumentclass', function () {
|
||||
it('should return true if the content has a documentclass', function () {
|
||||
const document = ['% line', '% line', '% line', '\\documentclass']
|
||||
return expect(
|
||||
this.DocumentHelper.contentHasDocumentclass(document)
|
||||
).to.equal(true)
|
||||
})
|
||||
|
||||
it('should allow whitespace before the documentclass', function() {
|
||||
it('should allow whitespace before the documentclass', function () {
|
||||
const document = ['% line', '% line', '% line', ' \\documentclass']
|
||||
return expect(
|
||||
this.DocumentHelper.contentHasDocumentclass(document)
|
||||
).to.equal(true)
|
||||
})
|
||||
|
||||
it('should not allow non-whitespace before the documentclass', function() {
|
||||
it('should not allow non-whitespace before the documentclass', function () {
|
||||
const document = [
|
||||
'% line',
|
||||
'% line',
|
||||
@@ -152,7 +152,7 @@ describe('DocumentHelper', function() {
|
||||
).to.equal(false)
|
||||
})
|
||||
|
||||
it('should return false when there is no documentclass', function() {
|
||||
it('should return false when there is no documentclass', function () {
|
||||
const document = ['% line', '% line', '% line']
|
||||
return expect(
|
||||
this.DocumentHelper.contentHasDocumentclass(document)
|
||||
|
||||
Reference in New Issue
Block a user