Skip to content

Commit

Permalink
testing survey class
Browse files Browse the repository at this point in the history
  • Loading branch information
Annelein committed Nov 23, 2023
1 parent 4103e5e commit 9661946
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
2 changes: 1 addition & 1 deletion templates/for-teachers.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h2>{{_('my_classes')}}</h2>
<tr>
<td class="px-4 py-2"><a href="for-teachers/class/{{class.id}}" class="view_class" data-cy="view_class_link">{{class.name|e}}</a></td>
<td class="username_cell">{{class.teacher}}</td>
<td class="text-center p-2">{{class.students|length}}</td>
<td class="text-center p-2"><div id="total_students">{{class.students|length}}</div></td>
<td class="text-center p-2"><a class="no-underline cursor-pointer" onclick='hedyApp.duplicate_class("{{class.id}}", {{_('class_name_prompt')|default(None)|tojson}}, {% if class.teacher != username %}"{{class.name}}"{% else %}" "{% endif %})'><span class="fas fa-copy"></span></a></td>
<td class="text-center p-2"><a class="no-underline cursor-pointer" onclick='hedyApp.delete_class("{{class.id}}", {{_('delete_class_prompt')|default(None)|tojson}})'>🗑️</a></td>
</tr>
Expand Down
8 changes: 4 additions & 4 deletions templates/htmx-survey.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
<div class="mb-4">
<div id="question" class="text-white mb-4 text-xl">{{ _(question) }}</div>
<div class="flex flex-row justify-center space-x-1">
<input autofocus="autofocus" id="input" type="text" class="flex items-center border border-green-400 rounded p-2 px-3 w-4/5 mx-auto" name="{{ question }}">
<input autofocus="autofocus" id="input" data-cy="input_{{ loop.index }}" type="text" class="flex items-center border border-green-400 rounded p-2 px-3 w-4/5 mx-auto" name="{{ question }}">
</div>
</div>
{% endfor %}
<div class="mt-4 flex flex-row gap-2 justify-center">
<button type="submit" class="green-btn block mx-auto w-40 pb-4 pt-4"
<button id="submit" class="green-btn block mx-auto w-40 pb-4 pt-4"
hx-trigger="click"
hx-post="/surveys/submit-survey/{{ survey_id }}"
hx-include="[name='question']"
hx-swap="innerHTML"
_="on click toggle .hidden on #survey">
{{_('survey_submit')}}</button>
<button type="remind_later" class="red-btn block mx-auto w-40 pb-4 pt-4"
<button id="remind_later" class="red-btn block mx-auto w-40 pb-4 pt-4"
hx-trigger="click"
hx-post="/surveys/remind-later-survey/{{ survey_id }}"
hx-swap="innerHTML"
_="on click toggle .hidden on #survey">
{{_(survey_later)}}</button>
</div>
<div class="flex-row justify-center">
<button type="skip" class="text-white m-1 w-40 pb-4 pt-4"
<button id="skip" class="text-white m-1 w-40 pb-4 pt-4"
hx-trigger="click"
hx-post="/surveys/skip-survey/{{ survey_id }}"
hx-swap="innerHTML"
Expand Down
82 changes: 82 additions & 0 deletions tests/cypress/e2e/for-teacher_page/class_page/class-survey.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {loginForTeacher, logout} from '../../tools/login/login.js'
import { createClass} from '../../tools/classes/class'

const surveyView = body => body.find("#survey")
describe('Class Survey View', () => {
it('Can respond to 1 questions', () => {

loginForTeacher();
cy.wait(500);

cy.get("#total_students").should('not.have.value', '0').then(
cy.get(".view_class").first().click(),
cy.get("body").then(surveyView).then(survey => {
if (survey.length){
survey = cy.get("#survey")
survey.should("exist")
survey.get("#input").type("test")
survey.get("#submit").click()
}
})
)
})

it('Should have 3 questions remaning, can respond to those', () => {

loginForTeacher();
cy.wait(500);

cy.get("#total_students").should('not.have.value', '0').then(
cy.get(".view_class").first().click(),
cy.get("body").then(surveyView).then(survey => {
if (survey.length){
survey = cy.get("#survey")
survey.should("exist")
var surveyInputs = Array.from({length:3},(v, k)=>k+1)
cy.wrap(surveyInputs).each((index) => {
cy.getBySel("input_" + index)
.type("test")
.invoke('val').then((text) => {
expect('test').to.equal(text);
});
});
survey.get("#submit").click()
}
})
)
})

it('Can be skipped - never show again', () => {

loginForTeacher();
cy.wait(500);

cy.get("#total_students").should('not.have.value', '0').then(
cy.get(".view_class").eq(2).click(),
cy.get("body").then(surveyView).then(survey => {
if (survey.length){
survey = cy.get("#survey")
survey.should("exist")
survey.get("#skip").click()
}
})
)
})

it('Can be skipped - remind me later', () => {

loginForTeacher();
cy.wait(500);

cy.get("#total_students").should('not.have.value', '0').then(
cy.get(".view_class").eq(3).click(),
cy.get("body").then(surveyView).then(survey => {
if (survey.length){
survey = cy.get("#survey")
survey.should("exist")
survey.get("#remind_later").click()
}
})
)
})
})

0 comments on commit 9661946

Please sign in to comment.