Skip to content

Commit 2afebff

Browse files
committed
patch several specs to cleanup DOM state
Not cleaning up the DOM after tests that put markup into "fixtures" can cause inconsistent starting state for other specs. This takes several specs that do that and cleans them up in my push to have less fragile aux builds Change-Id: Id83a5724b9ea23d5d6879eae08f7ae29c8a3f7f2 Reviewed-on: https://gerrit.instructure.com/52335 Reviewed-by: Clay Diffrient <cdiffrient@instructure.com> Product-Review: Ethan Vizitei <evizitei@instructure.com> QA-Review: Ethan Vizitei <evizitei@instructure.com> Tested-by: Ethan Vizitei <evizitei@instructure.com>
1 parent c0a2213 commit 2afebff

8 files changed

Lines changed: 30 additions & 15 deletions

File tree

spec/coffeescripts/flashNotificationSpec.coffee

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ define [
22
'jquery'
33
'compiled/jquery.rails_flash_notifications'
44
], ($) ->
5+
fixtures = null
56
module 'FlashNotifications',
67
setup: ->
7-
@fixture = $('<div id="flash_message_holder"/><div id="flash_screenreader_holder"/>').appendTo('#fixtures')
8+
fixtures = document.getElementById("fixtures")
9+
flashHtml = "<div id='flash_message_holder'/><div id='flash_screenreader_holder'/>"
10+
fixtures.innerHTML = flashHtml
811
$.initFlashContainer()
912
teardown: ->
10-
@fixture.remove()
13+
fixtures.innerHTML = ""
1114

1215
test 'text notification', ->
1316
$.flashMessage('here is a thing')

spec/coffeescripts/views/SearchViewSpec.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ define [
3939
clock.restore()
4040
server.restore()
4141
searchView.remove()
42+
$("#fixtures").empty()
4243

4344
# asserts match and order of rendered items
4445
assertRenderedItems = (names=[]) ->

spec/coffeescripts/views/SelectViewSpec.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ define [
1919
view.$el.appendTo $('#fixtures')
2020
teardown: ->
2121
view.remove()
22+
$("#fixtures").empty()
2223

2324
test 'onChange it updates the model', ->
2425
view.model = new Backbone.Model

spec/coffeescripts/views/SyllabusViewSpec.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ define [
141141
@clock.restore()
142142
tz.restore(@tzSnapshot)
143143
@server.restore()
144+
document.getElementById("fixtures").innerHTML = ""
144145

145146
render: ->
146147
@view.render()

spec/coffeescripts/views/courses/roster/InvitationsViewSpec.coffee

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,21 @@ define [
55
'helpers/assertions'
66
], ($, InvitationsView, RosterUser, assert) ->
77

8-
view = null
9-
server = null
10-
118
module 'InvitationsView',
129
setup: ->
1310
teardown: ->
1411

1512
buildView = (enrollment)->
1613
model = new RosterUser( enrollments: [enrollment] )
1714
model.currentRole = 'student'
18-
view = new InvitationsView(model: model)
15+
new InvitationsView(model: model)
1916

2017
test 'knows when invitation is pending', ->
2118
enrollment = {id: 1, role: 'student', enrollment_state: 'invited'}
22-
buildView enrollment
19+
view = buildView enrollment
2320
equal view.invitationIsPending(), true
2421

2522
test 'knows when invitation is not pending', ->
2623
enrollment = {id: 1, role: 'student', enrollment_state: 'accepted'}
27-
buildView enrollment
24+
view = buildView enrollment
2825
equal view.invitationIsPending(), false

spec/coffeescripts/views/groups/manage/GroupCategoriesViewSpec.coffee

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ define [
88
clock = null
99
view = null
1010
categories = null
11+
wrapper = null
12+
sanbox = null
1113

1214
module 'GroupCategoriesView',
1315
setup: ->
@@ -18,16 +20,19 @@ define [
1820
{id: 1, name: "group set 1"}
1921
{id: 2, name: "group set 2"}
2022
]
23+
sinon.stub(categories, "fetch").returns([])
2124
view = new GroupCategoriesView
2225
collection: categories
2326
view.render()
24-
view.$el.appendTo($(document.body))
27+
wrapper = document.getElementById("fixtures")
28+
wrapper.innerHTML = ""
29+
view.$el.appendTo($("#fixtures"))
2530

2631
teardown: ->
2732
fakeENV.teardown()
2833
clock.restore()
2934
view.remove()
30-
$('.group_categories_area').remove()
35+
wrapper.innerHTML = ""
3136

3237
test 'render tab and panel elements', ->
3338
# find the tabs

spec/coffeescripts/views/quizzes/IndexViewSpec.coffee

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define [
1010
'helpers/jquery.simulate'
1111
], (Backbone, Quiz, QuizCollection, IndexView, QuizItemGroupView, NoQuizzesView, $, fakeENV) ->
1212

13-
fixtures = $('#fixtures')
13+
fixtures = null
1414

1515
indexView = (assignments, open, surveys) ->
1616
$('<div id="content"></div>').appendTo fixtures
@@ -53,12 +53,16 @@ define [
5353
permissions: permissions
5454
flags: flags
5555
urls: urls
56-
view.$el.appendTo $('#fixtures')
56+
view.$el.appendTo fixtures
5757
view.render()
5858

5959
module 'IndexView',
60-
setup: -> fakeENV.setup()
61-
teardown: -> fakeENV.teardown()
60+
setup: ->
61+
fixtures = $("#fixtures")
62+
fakeENV.setup()
63+
teardown: ->
64+
fakeENV.teardown()
65+
fixtures.empty()
6266

6367
# hasNoQuizzes
6468
test '#hasNoQuizzes if assignment and open quizzes are empty', ->

spec/coffeescripts/views/wiki/WikiPageRevisionsViewSpec.coffee

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ define [
44
'compiled/views/wiki/WikiPageRevisionsView'
55
], ($, WikiPageRevisionsCollection, WikiPageRevisionsView) ->
66

7-
module 'WikiPageRevisionsView'
7+
module 'WikiPageRevisionsView',
8+
setup: ->
9+
teardown: ->
10+
document.getElementById("fixtures").innerHTML = ""
811

912
test 'selecting a model/view sets the selected attribute on the model', ->
1013
fixture = $('<div id="main"><div id="content"></div></div>').appendTo('#fixtures')

0 commit comments

Comments
 (0)