Skip to content

Instantly share code, notes, and snippets.

@jennifer-shehane
Last active October 23, 2015 17:23
Show Gist options
  • Save jennifer-shehane/7c10dbe910a7974a61ea to your computer and use it in GitHub Desktop.
Save jennifer-shehane/7c10dbe910a7974a61ea to your computer and use it in GitHub Desktop.
alias-bug
describe "Questions List (Form Builder) [lhw]", ->
before -> @visit()
beforeEach ->
cy
.server()
.fixture("form_template").as("formTemplate")
.fixture("question_headings").as("questionHeadings")
.fixture("question_heading").as("questionHeading")
.fixture("questions").as("questions")
@setup = ->
cy
.route(/question_types/, "fixture:question_types")
.route(/priorities/, "fixture:priorities")
.route(/form_templates\/\d+$/, "@formTemplate").as("getFormTemplate")
.route(/form_templates\/\d+\/question_headings/, "@questionHeadings").as("getQuestionHeadings")
.route(/form_templates\/\d+\/questions/, "@questions").as("getQuestions")
.then ->
App.as("admin").enter(Routes.form_template_path(452)).ready (@controller) =>
.region("#main")
.wait(["@getFormTemplate", "@getQuestionHeadings", "@getQuestions"])
context "layout [7x8]", ->
beforeEach ->
@setup()
describe "question headings list [261]", ->
beforeEach ->
cy
.get(".question-heading-list")
.find(">li:first>.question-heading-wrapper").as("firstQuestionHeading")
it "displays all question headings [262]", ->
cy.get(".question-heading-list").find(">li").should("have.length", @questionHeadings.items.length)
it "displays question heading name [262]", ->
cy.get("@firstQuestionHeading").contains @questionHeadings.items[0].name
context "edit question heading [269]", ->
it "displays inline input with name on click of edit [263]", ->
cy
.get("@firstQuestionHeading").within ->
cy
.get("input")
.should("not.be.visible")
.get("[data-js='edit-question-heading']")
.click()
.should("not.be.visible")
.get("input")
.should("be.visible")
.should("have.value", @questionHeadings.items[0].name)
describe "successfully update [26a]", ->
it "PUTS name [26b]", ->
cy
.route("PUT", /question_headings\/\d+/, @questionHeading).as("putQuestionHeading")
.get("@firstQuestionHeading").within ->
cy
.get("[data-js='edit-question-heading']").click()
.get("input").type("bar").blur()
.wait("@putQuestionHeading").then (request) ->
expect(request.requestJSON).to.have.property "name"
it "hides input and shows name [26c]", ->
cy
.route("PUT", /question_headings\/\d+/, @questionHeading).as("putQuestionHeading")
.get("@firstQuestionHeading").within ->
cy
.get("[data-js='edit-question-heading']").click()
.get("input").type("bar").blur()
.wait("@putQuestionHeading")
.get("@firstQuestionHeading").within ->
cy
.get("input").should("not.be.visible")
.get("[data-js='name']").should("be.visible")
describe "error on update [26a]", ->
it "displays error [26d]", ->
@message = "name is required."
cy
.route({
method: "PUT"
status: 412
url: /question_headings\/\d+/
response: {errors: {name: [@message]}}
}).as("putQuestionHeadingErr")
.get("@firstQuestionHeading").within ->
cy
.get("[data-js='edit-question-heading']").click()
.get("input").clear().blur()
.wait("@putQuestionHeadingErr")
.get("@firstQuestionHeading").within ->
cy
.get("input").should("be.visible")
.get(".error-wrap").should("be.visible")
.get(".form-group").should("have.class", "error")
.contains(@message)
it "triggers destroy:question:heading on click of delete [264]", ->
cy
.region("#question-headings-list").view().then (view) ->
@trigger = @agents.spy view, "trigger"
.get("@firstQuestionHeading")
.find("[data-js='destroy-question-heading']").click().then ->
expect(@trigger).to.be.calledWith "childview:destroy:question:heading:clicked"
describe "questions list [266]", ->
beforeEach ->
cy
.get(".questions-list:first").within ->
cy
.get(">li:first").as("firstQuestion")
.get(">li:nth-child(2)").as("secondQuestion")
it "displays all questions [262]", ->
cy.get(".questions-list>li").should("have.length", @questions.items.length)
it "displays question title [262]", ->
cy.get("@firstQuestion").contains @questions.items[0].title
it "displays question definition [262]", ->
cy.get("@firstQuestion").contains @questions.items[0].definition
it "displays required asterisk when required [262]", ->
cy.get("@firstQuestion").find(".required").contains "*"
it "does not display required asterisk when not required [262]", ->
cy.get("@secondQuestion").should("not.contain", "*")
it "triggers edit:question on click of edit [263]", ->
cy
.region("#question-headings-list").view().then (view) ->
@trigger = @agents.spy view, "trigger"
.get("@firstQuestion")
.find("[data-js='edit-question']").click().then ->
expect(@trigger).to.be.calledWith "childview:childview:edit:question:clicked"
it "triggers copy:question on click of copy [263]"
it "triggers destroy:question on click of delete [264]", ->
cy
.region("#question-headings-list").view().then (view) ->
@trigger = @agents.spy view, "trigger"
.get("@firstQuestion")
.find("[data-js='destroy-question']").click().then ->
expect(@trigger).to.be.calledWith "childview:childview:destroy:question:clicked"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment