Convert existing frontend tests to run in karma

This commit is contained in:
Alasdair Smith 2018-02-13 16:29:16 +00:00
parent 3faa0556e8
commit c7957b8ad4
2 changed files with 189 additions and 210 deletions

View file

@ -1,23 +1,11 @@
Path = require 'path' define ['ide/history/HistoryV2Manager'], (HistoryV2Manager) ->
SandboxedModule = require "sandboxed-module"
modulePath = Path.join __dirname, '../../../../../public/js/ide/history/HistoryV2Manager'
sinon = require("sinon")
expect = require("chai").expect
describe "HistoryV2Manager", -> describe "HistoryV2Manager", ->
beforeEach -> beforeEach ->
@moment = {}
@ColorManager = {}
SandboxedModule.require modulePath, globals:
"define": (dependencies, builder) =>
@HistoryV2Manager = builder(@moment, @ColorManager)
@scope = @scope =
$watch: sinon.stub() $watch: sinon.stub()
$on: sinon.stub() $on: sinon.stub()
@ide = {} @ide = {}
@historyManager = new HistoryV2Manager(@ide, @scope)
@historyManager = new @HistoryV2Manager(@ide, @scope)
it "should setup the history scope on intialization", -> it "should setup the history scope on intialization", ->
expect(@scope.history).to.deep.equal({ expect(@scope.history).to.deep.equal({

View file

@ -1,26 +1,17 @@
Path = require 'path' define ['ide/history/util/displayNameForUser'], (displayNameForUser) ->
SandboxedModule = require "sandboxed-module"
modulePath = Path.join __dirname, '../../../../../public/js/ide/history/util/displayNameForUser'
sinon = require("sinon")
expect = require("chai").expect
describe "displayNameForUser", -> describe "displayNameForUser", ->
beforeEach -> beforeEach ->
SandboxedModule.require modulePath, globals: window.user = { id: 42 }
"define": (dependencies, builder) =>
@displayNameForUser = builder()
"window": @window = {}
@window.user = { id: 42 }
it "should return 'Anonymous' with no user", -> it "should return 'Anonymous' with no user", ->
expect( expect(
@displayNameForUser(null) displayNameForUser(null)
).to.equal "Anonymous" ).to.equal "Anonymous"
it "should return 'you' when the user has the same id as the window", -> it "should return 'you' when the user has the same id as the window", ->
expect( expect(
@displayNameForUser({ displayNameForUser({
id: @window.user.id id: window.user.id
email: "james.allen@overleaf.com" email: "james.allen@overleaf.com"
first_name: "James" first_name: "James"
last_name: "Allen" last_name: "Allen"
@ -29,8 +20,8 @@ describe "displayNameForUser", ->
it "should return the first_name and last_name when present", -> it "should return the first_name and last_name when present", ->
expect( expect(
@displayNameForUser({ displayNameForUser({
id: @window.user.id + 1 id: window.user.id + 1
email: "james.allen@overleaf.com" email: "james.allen@overleaf.com"
first_name: "James" first_name: "James"
last_name: "Allen" last_name: "Allen"
@ -39,8 +30,8 @@ describe "displayNameForUser", ->
it "should return only the firstAname if no last_name", -> it "should return only the firstAname if no last_name", ->
expect( expect(
@displayNameForUser({ displayNameForUser({
id: @window.user.id + 1 id: window.user.id + 1
email: "james.allen@overleaf.com" email: "james.allen@overleaf.com"
first_name: "James" first_name: "James"
last_name: "" last_name: ""
@ -49,8 +40,8 @@ describe "displayNameForUser", ->
it "should return the email username if there are no names", -> it "should return the email username if there are no names", ->
expect( expect(
@displayNameForUser({ displayNameForUser({
id: @window.user.id + 1 id: window.user.id + 1
email: "james.allen@overleaf.com" email: "james.allen@overleaf.com"
first_name: "" first_name: ""
last_name: "" last_name: ""
@ -59,8 +50,8 @@ describe "displayNameForUser", ->
it "should return the '?' if it has nothing", -> it "should return the '?' if it has nothing", ->
expect( expect(
@displayNameForUser({ displayNameForUser({
id: @window.user.id + 1 id: window.user.id + 1
email: "" email: ""
first_name: "" first_name: ""
last_name: "" last_name: ""