Skip to content

Commit

Permalink
spec: [ci-coverage] use dialog reference for queries
Browse files Browse the repository at this point in the history
This spec has been flaky. The theory is that it might not be acting on
the correct DOM elements, due to DOM pollution. The result is that it
ends up waiting on behavior that was never triggered, and times out.

Change-Id: I107aac0e9fe8185dcdf81137a71ca5a0e75ee7f9
Reviewed-on: https://gerrit.instructure.com/208056
Tested-by: Jenkins
Reviewed-by: Gary Mei <[email protected]>
QA-Review: Jeremy Neander <[email protected]>
Product-Review: Jeremy Neander <[email protected]>
  • Loading branch information
jneander committed Sep 4, 2019
1 parent 93e4894 commit aaff474
Showing 1 changed file with 30 additions and 34 deletions.
64 changes: 30 additions & 34 deletions spec/javascripts/jsx/shared/SetDefaultGradeDialogSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,31 @@

import $ from 'jquery'

import {waitFor} from '../support/Waiters'

import SetDefaultGradeDialog from 'compiled/shared/SetDefaultGradeDialog'
import {waitFor} from '../support/Waiters'

import 'jst/SetDefaultGradeDialog'
import 'jst/_grading_box'
QUnit.module('Shared > SetDefaultGradeDialog', suiteHooks => {
let assignment
let dialog

const assignment = Object.freeze({
id: '2',
points_possible: 10,
name: 'an Assignment',
grading_type: 'points'
})
suiteHooks.beforeEach(() => {
assignment = {
grading_type: 'points',
id: '2',
name: 'an Assignment',
points_possible: 10
}
})

function closeDialog() {
Array.from(document.querySelectorAll('button'))
.find(node => node.innerText === 'close')
.click()
}
function getDialog() {
return dialog.$dialog[0].closest('.ui-dialog')
}

QUnit.module('SetDefaultGradeDialog', () => {
let dialog
function closeDialog() {
Array.from(getDialog().querySelectorAll('button'))
.find(node => node.innerText === 'close')
.click()
}

test('#gradeIsExcused returns true if grade is EX', () => {
dialog = new SetDefaultGradeDialog({assignment})
Expand All @@ -64,7 +67,7 @@ QUnit.module('SetDefaultGradeDialog', () => {
test('#show text', () => {
dialog = new SetDefaultGradeDialog({assignment})
dialog.show()
ok(document.getElementById('default_grade_description').innerText.includes('same grade'))
ok(getDialog().querySelector('#default_grade_description').innerText.includes('same grade'))
closeDialog()
})

Expand All @@ -73,40 +76,33 @@ QUnit.module('SetDefaultGradeDialog', () => {
dialog = new SetDefaultGradeDialog({assignment: percentAssignmentParams})
dialog.show()
ok(
document.getElementById('default_grade_description').innerText.includes('same percent grade')
getDialog().querySelector('#default_grade_description').innerText.includes('same percent grade')
)
closeDialog()
})

QUnit.module('submit behaviors', submitBehaviorHooks => {
const context_id = '1'
let alert
let server
let publishStub

function clickSetDefaultGrade() {
Array.from(document.querySelectorAll('button[role="button"]'))
Array.from(getDialog().querySelectorAll('button[role="button"]'))
.find(node => node.innerText === 'Set Default Grade')
.click()
}

function respondWithPayload(payload) {
server.respondWith('POST', `/courses/${context_id}/gradebook/update_submission`, [
sandbox.server.respondWith('POST', `/courses/${context_id}/gradebook/update_submission`, [
200,
{'Content-Type': 'application/json'},
JSON.stringify(payload)
])
}

submitBehaviorHooks.beforeEach(() => {
server = sinon.createFakeServer({respondImmediately: true})
sandbox.server.respondImmediately = true
alert = sinon.spy()
publishStub = sinon.stub($, 'publish')
})

submitBehaviorHooks.afterEach(() => {
publishStub.restore()
server.restore()
sandbox.stub($, 'publish')
})

test('submit reports number of students', async () => {
Expand All @@ -118,9 +114,9 @@ QUnit.module('SetDefaultGradeDialog', () => {
const students = [{id: '3'}, {id: '4'}]
dialog = new SetDefaultGradeDialog({assignment, students, context_id, alert})
dialog.show()
await waitFor(() => document.getElementById('set_default_grade_form'))
await waitFor(() => getDialog())
clickSetDefaultGrade()
await waitFor(() => !document.getElementById('set_default_grade_form'))
await waitFor(() => !getDialog())
const {
firstCall: {
args: [message]
Expand All @@ -141,9 +137,9 @@ QUnit.module('SetDefaultGradeDialog', () => {
// adjust page size so that we generate two requests
dialog = new SetDefaultGradeDialog({assignment, students, context_id, page_size: 2, alert})
dialog.show()
await waitFor(() => document.getElementById('set_default_grade_form'))
await waitFor(() => getDialog())
clickSetDefaultGrade()
await waitFor(() => !document.getElementById('set_default_grade_form'))
await waitFor(() => !getDialog())
const {
firstCall: {
args: [message]
Expand Down

0 comments on commit aaff474

Please sign in to comment.