From 3faa0556e8a4fbd7f1e26d1c4880c7d1a31c567b Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Mon, 12 Feb 2018 16:20:37 +0000 Subject: [PATCH] Add test for cmEditor directive --- .../editor/directives/cmEditorTests.coffee | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 services/web/test/unit_frontend/coffee/ide/editor/directives/cmEditorTests.coffee diff --git a/services/web/test/unit_frontend/coffee/ide/editor/directives/cmEditorTests.coffee b/services/web/test/unit_frontend/coffee/ide/editor/directives/cmEditorTests.coffee new file mode 100644 index 0000000000..3f74268ad9 --- /dev/null +++ b/services/web/test/unit_frontend/coffee/ide/editor/directives/cmEditorTests.coffee @@ -0,0 +1,53 @@ +define ['ide/editor/directives/cmEditor'], () -> + describe 'cmEditor', () -> + beforeEach(module('SharelatexApp')) + + beforeEach () -> + @richTextInit = sinon.stub() + window.Frontend = { + richText: { + init: @richTextInit + } + } + + it 'inits Rich Text', () -> + inject ($compile, $rootScope) -> + $compile('
')($rootScope) + expect(@richTextInit).to.have.been.called + + it 'attaches to CM', () -> + inject ($compile, $rootScope) -> + setValue = sinon.stub() + @richTextInit.returns({ setValue: setValue }) + getSnapshot = sinon.stub() + detachFromCM = sinon.stub() + attachToCM = sinon.stub() + $rootScope.sharejsDoc = { + getSnapshot: getSnapshot + detachFromCM: detachFromCM + attachToCM: attachToCM + } + + $compile('
')($rootScope) + $rootScope.$digest() + + expect(getSnapshot).to.have.been.called + expect(setValue).to.have.been.called + expect(detachFromCM).to.have.been.called + expect(attachToCM).to.have.been.called + + it 'detaches from CM when destroyed', () -> + inject ($compile, $rootScope) -> + @richTextInit.returns({ setValue: sinon.stub() }) + detachFromCM = sinon.stub() + $rootScope.sharejsDoc = { + getSnapshot: sinon.stub() + detachFromCM: detachFromCM + attachToCM: sinon.stub() + } + + $compile('
')($rootScope) + $rootScope.$digest() + $rootScope.$broadcast('destroy') + + expect(detachFromCM).to.have.been.called