Skip to content

Commit

Permalink
Attempt to fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boryanagoncharenko committed Oct 22, 2024
1 parent ca32210 commit 716feab
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 56 deletions.
4 changes: 2 additions & 2 deletions templates/create-accounts.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h3 class="w-full my-0 py-0">
</span>
</div>
<div class="flex flex-row">
<textarea id="accounts_input" name="Text1" cols="40" rows="5" placeholder="{{_('create_accounts_placeholder')}}"
<textarea id="accounts_input" data-cy="create_accounts_input" cols="40" rows="7" placeholder="{{_('create_accounts_placeholder')}}"
required class="usernames_input w-full block appearance-none bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 ltr:pr-8 rtl:pl-8 rounded"></textarea>
<input id="classes" name="class" value="{{current_class.id}}" disabled hidden>
</div>
Expand All @@ -59,7 +59,7 @@ <h3 class="w-full my-0 py-0">
<button id="print_accounts" class="blue-btn px-4 mb-4" onclick="hedyApp.printAccounts()">
{{_('print_accounts')}}
</button>
<table id="accounts_table" class="w-full border border-gray-600">
<table id="accounts_table" data-cy="create_accounts_output" class="w-full border border-gray-600">
<tr class="">
<th class="px-10 py-2 text-center">{{_('username')}}</th>
<th class="px-10 py-2 text-center">{{_('password')}}</th>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,53 @@
import {loginForTeacher} from '../../../tools/login/login.js'
import {createClassAndAddStudents, navigateToClass} from '../../../tools/classes/class.js'
import { loginForTeacher } from '../../../tools/login/login.js'
import { createClassAndAddStudents, createClass, navigateToClass } from '../../../tools/classes/class.js'

let classname;
let students;
const teachers = ["teacher1", "teacher4"];

before(() => {
loginForTeacher();
})

beforeEach(() => {
loginForTeacher();
navigateToClass(classname);
cy.getDataCy('add_student').click();
cy.getDataCy('create_accounts').click();
})

teachers.forEach((teacher) => {
describe(`Testing creating accounts for ${teacher}`, () => {
it('Is able to download login credentials, generate passwords, click on go back button and see if students created in createClassAndAddStudents() are present', () => {
({classname, students} = createClassAndAddStudents());
// download login credentials
cy.readFile('cypress/downloads/accounts.csv');
it('Is able to create student accounts with usernames', () => {
const className = createClass();

navigateToClass(className);
cy.wait(500);

cy.get('body').then($b => $b.find('[data-cy="survey"]')).then($s => $s.length && $s.hide())
cy.getDataCy('add_student').click();
cy.getDataCy('create_accounts').click();

// generate passwords
cy.getDataCy('toggle_circle').click();
cy.getDataCy('password_1').should('have.length.greaterThan', 0);
const students = Array.from({length:5}, (_, index) => `student_${index}_${Math.random()}`)
cy.getDataCy('create_accounts_input').type(students.join('\n'));

cy.getDataCy('go_back_button').click();
cy.url().should('include', 'class/');
cy.getDataCy('create_accounts_button').click();
cy.getDataCy('modal_yes_button').click();

cy.getDataCy(`student_${students[0]}`).should('contain.text', students[0])
ensureStudentsCreatedSuccessfully(students);
})

it('Is able to add and remove a row and use the reset button', () => {
// testing add a row
cy.getDataCy('add_multiple_rows').click();
cy.getDataCy('username_6').should('have.value', '').should('have.value', '');
// testing removing a row
// fills in two rows
cy.getDataCy('username_1').type("student10");
cy.getDataCy('password_1').type("123456");
cy.getDataCy('username_2').type("student11");
cy.getDataCy('password_2').type("123456");

// deletes the first row
cy.getDataCy('remove_student_1').click();
// check if the first row is now student11
cy.getDataCy('username_2').should('have.value', 'student11');
cy.getDataCy('username_3').should('have.value', '');
// testing reseting
cy.getDataCy('reset_button').click();
cy.getDataCy('username_2').should('have.value', '');
cy.getDataCy('username_3').should('have.value', '');
it('Is able to create student accounts with usernames and passwords', () => {
// This test is relying on the util method used to create a class with students
let {_, students} = createClassAndAddStudents();

ensureStudentsCreatedSuccessfully(students);
})
})
})
})

function ensureStudentsCreatedSuccessfully(students)
{
// Accounts are created successfully when the input textarea is hidden and the results table is displayed
cy.getDataCy('create_accounts_output').should('be.visible');
cy.getDataCy('create_accounts_input').should('not.be.visible');

// Go back to the class overview and check that all students appear in the class table
cy.getDataCy('go_back_button').click();
cy.url().should('include', 'class/');

cy.wrap(students).each((_, index) => {
cy.getDataCy(`student_${students[index]}`).should('contain.text', students[index])
});
}
16 changes: 9 additions & 7 deletions tests/cypress/e2e/tools/classes/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,22 @@ export function ensureClass()

export function addStudents(classname, count) {
const students = Array.from({length:count}, (_, index) => `student_${index}_${Math.random()}`)

goToTeachersPage();
cy.wait(500);

openClassView(classname);
cy.wait(500);

cy.get('body').then($b => $b.find('[data-cy="survey"]')).then($s => $s.length && $s.hide())
cy.get('body').then($b => $b.find('[data-cy="survey"]')).then($s => $s.length && $s.hide())
cy.getDataCy('add_student').click();
cy.getDataCy('create_accounts').click();
cy.wrap(students).each((student, index) => {
cy.getDataCy(`username_${index + 1}`).type(student);
cy.getDataCy(`password_${index + 1}`).type('123456');
})

cy.getDataCy('toggle_circle').click();
const accounts = students.map(function (s) {
return `${s};123456`;
}).join('\n');
cy.getDataCy('create_accounts_input').type(accounts);

cy.getDataCy('create_accounts_button').click();
cy.getDataCy('modal_yes_button').click();

Expand Down Expand Up @@ -130,4 +132,4 @@ export function selectLevel(level) {
cy.getDataCy('levels_dropdown').select(level);
}

export default {createClassAndAddStudents};
export default {createClassAndAddStudents};
13 changes: 8 additions & 5 deletions tests_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -1584,16 +1584,19 @@ def test_invalid_create_accounts(self):
self.post_data('for-teachers/create-accounts', invalid_body, expect_http_code=400)

def test_create_accounts(self):
# GIVEN a new teacher
# GIVEN a new teacher with a new class
self.given_fresh_teacher_is_logged_in()
class_ = self.post_data('class', {'name': 'class1'})

# WHEN attempting to create a valid adventure
# THEN receive an OK response with the server
body = {
'accounts': [
{'username': 'panda', 'password': 'test123'},
{'username': 'panda2', 'password': 'test321'}
]
'class': class_['id'],
'generate_passwords': False,
'accounts': '''
platypus;test123
platypus2;test321
'''
}
self.post_data('for-teachers/create-accounts', body, expect_http_code=200)

Expand Down

0 comments on commit 716feab

Please sign in to comment.