Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧪 Refactor cypress tests (part 3) #5592

Merged
merged 51 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
dc8a9f6
first part customize_class_second_teacher.cy.js
Annelein May 28, 2024
72ac0bc
revert to getBySel()
Annelein May 30, 2024
6501ed1
Merge branch 'main' into ref-cyp-tests
Annelein Jun 4, 2024
2ce8969
merge main
Annelein Jun 4, 2024
3c73671
moving around customize_class test to one test for a second teacher a…
Annelein Jun 4, 2024
762e1fe
all customize class tests
Annelein Jun 4, 2024
cbf7eac
Merge branch 'main' into ref-cyp-tests
Annelein Jun 4, 2024
0039b40
add imports for openClassView
Annelein Jun 5, 2024
d98ee95
Merge branch 'main' into ref-cyp-tests
Annelein Jun 5, 2024
8f214db
refactor customize class and dropdown_level. few fixes
Annelein Jun 5, 2024
57d9a49
Merge branch 'ref-cyp-tests' of https://github.com/hedyorg/hedy into …
Annelein Jun 5, 2024
8029146
customize adventure page tests
Annelein Jun 5, 2024
fbd0e0f
customize adventure page tests
Annelein Jun 5, 2024
62cbd8b
general tests
Annelein Jun 5, 2024
5867c4d
reordering tests and removing duplicate testing
Annelein Jun 5, 2024
ed8080e
refactor tests
Annelein Jun 5, 2024
a3f0390
refactor general tests
Annelein Jun 10, 2024
1a94532
Merge branch 'main' into ref-cyp-tests
Annelein Jun 10, 2024
44f976c
🤖 Automatically update generated files
Annelein Jun 10, 2024
5ef764c
invite_by_username
Annelein Jun 10, 2024
22a80d6
begin to refactor customize class test
Annelein Jun 10, 2024
5c985b9
Merge branch 'main' into ref-cyp-tests
Annelein Jun 11, 2024
39a49cc
fix failing cypress tests
Annelein Jun 11, 2024
07b3682
fix failing cypress tests
Annelein Jun 11, 2024
49d9b06
fix failing cypress tests
Annelein Jun 11, 2024
34b55e5
Merge branch 'main' into ref-cyp-tests
Annelein Jun 11, 2024
9237da8
🤖 Automatically update generated files
Annelein Jun 11, 2024
8394d98
refactor without awaits and data-cys
Annelein Jun 12, 2024
e82e0f5
Merge branch 'ref-cyp-tests' of https://github.com/hedyorg/hedy into …
Annelein Jun 12, 2024
9044ec0
🤖 Automatically update generated files
Annelein Jun 12, 2024
f3d11d0
test for second teachers?
Annelein Jun 12, 2024
2b39812
some small fixes
Annelein Jun 12, 2024
d9049e3
fix failing tests
Annelein Jun 12, 2024
3317524
Merge branch 'main' into ref-cyp-tests
Annelein Jun 12, 2024
b245386
removeCustomizations() failing
Annelein Jun 12, 2024
a8a6a27
Merge branch 'main' into ref-cyp-tests
Annelein Jun 12, 2024
4e761b5
🤖 Automatically update generated files
Annelein Jun 12, 2024
2ccf967
remove modal for unsaved changes
Annelein Jun 13, 2024
bc4acd0
look for issue in quiz_parsons.cy.js
Annelein Jun 13, 2024
eeaed07
change to hide_quiz_setting
Annelein Jun 13, 2024
4dfddd5
remove modal for unsaved changes
Annelein Jun 13, 2024
6a56f8e
Merge branch 'main' into ref-cyp-tests
Annelein Jun 13, 2024
4a5d9f5
fix quiz_parsons.cy.js
Annelein Jun 13, 2024
343a20b
Merge branch 'ref-cyp-tests' of https://github.com/hedyorg/hedy into …
Annelein Jun 13, 2024
b398518
fix for failing dropdown_level.cy.js
Annelein Jun 13, 2024
5521ca5
add tests for second teachers
Annelein Jun 17, 2024
926153c
Merge branch 'main' into ref-cyp-tests
Annelein Jun 17, 2024
9403539
remove comment
Annelein Jun 17, 2024
7a02770
Merge branch 'ref-cyp-tests' of https://github.com/hedyorg/hedy into …
Annelein Jun 17, 2024
c3ff339
Merge branch 'main' into ref-cyp-tests
Annelein Jun 18, 2024
dc8fb15
🤖 Automatically update generated files
Annelein Jun 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 18 additions & 52 deletions static/js/appbundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -60416,7 +60416,6 @@ ${o3}` : i3;
changeUserEmail: () => changeUserEmail,
change_language: () => change_language,
change_password_student: () => change_password_student,
clearUnsavedChanges: () => clearUnsavedChanges,
closeAchievement: () => closeAchievement,
closeContainingModal: () => closeContainingModal,
comeBackHereAfterLogin: () => comeBackHereAfterLogin,
Expand All @@ -60442,7 +60441,6 @@ ${o3}` : i3;
getPreviousAndNext: () => getPreviousAndNext,
get_active_and_trimmed_code: () => get_active_and_trimmed_code,
goToLevel: () => goToLevel,
hasUnsavedChanges: () => hasUnsavedChanges,
hide_editor: () => hide_editor,
incrementDebugLine: () => incrementDebugLine,
initialize: () => initialize,
Expand All @@ -60469,7 +60467,6 @@ ${o3}` : i3;
logs: () => logs,
markAsTeacher: () => markAsTeacher,
markSuperTeacher: () => markSuperTeacher,
markUnsavedChanges: () => markUnsavedChanges,
modal: () => modal,
modalStepOne: () => modalStepOne,
preview_adventure: () => preview_adventure,
Expand Down Expand Up @@ -77722,24 +77719,6 @@ def note_with_error(value, err):
});
}

// static/js/browser-helpers/unsaved-changes.ts
function unloadHandler(event2) {
event2.preventDefault();
return event2.returnValue = ClientMessages["Unsaved_Changes"];
}
var unsavedChanges = false;
function hasUnsavedChanges() {
return unsavedChanges;
}
function markUnsavedChanges() {
unsavedChanges = true;
window.addEventListener("beforeunload", unloadHandler, { capture: true });
}
function clearUnsavedChanges() {
unsavedChanges = false;
window.removeEventListener("beforeunload", unloadHandler, { capture: true });
}

// static/js/tutorials/intro.ts
var current_step = 0;
function startIntro() {
Expand Down Expand Up @@ -77871,15 +77850,13 @@ def note_with_error(value, err):
$("#code_content_container").addClass("z-40");
$("#adventures").addClass("z-40 bg-gray-100");
$("#adventures").show();
clearUnsavedChanges();
addHighlightBorder("adventures");
relocatePopup(50, 40);
tutorialPopup("intro", current_step);
}
function adventureTabsStep() {
$("#adventures_buttons").children().each(function() {
if ($(this).attr("data-tab") == "story") {
clearUnsavedChanges();
$(this).click();
}
});
Expand All @@ -77888,7 +77865,6 @@ def note_with_error(value, err):
function parsonsTabStep() {
$("#adventures_buttons").children().each(function() {
if ($(this).attr("data-tab") == "parsons") {
clearUnsavedChanges();
$(this).click();
}
});
Expand All @@ -77897,7 +77873,6 @@ def note_with_error(value, err):
function quizTabStep() {
$("#adventures_buttons").children().each(function() {
if ($(this).attr("data-tab") == "quiz") {
clearUnsavedChanges();
$(this).click();
}
});
Expand All @@ -77906,7 +77881,6 @@ def note_with_error(value, err):
function saveShareStep() {
$("#adventures_buttons").children().each(function() {
if ($(this).attr("data-tab") == "default") {
clearUnsavedChanges();
$(this).click();
}
});
Expand Down Expand Up @@ -103791,7 +103765,7 @@ def note_with_error(value, err):
});
}
function duplicate_class(id2, teacher_classes, second_teacher_prompt, prompt, defaultValue = "") {
if (teacher_classes) {
if (teacher_classes && !defaultValue) {
modal.confirm(second_teacher_prompt, function() {
apiDuplicateClass(id2, prompt, true, defaultValue);
}, function() {
Expand Down Expand Up @@ -104132,7 +104106,6 @@ def note_with_error(value, err):
showAchievements(response.achievement, false, "");
}
modal.notifySuccess(response.success);
clearUnsavedChanges();
$("#remove_customizations_button").removeClass("hidden");
}).fail(function(err) {
modal.notifyError(err.responseText);
Expand All @@ -104159,7 +104132,6 @@ def note_with_error(value, err):
});
}
function enable_level(level3) {
markUnsavedChanges();
if ($("#enable_level_" + level3).is(":checked")) {
$("#opening_date_level_" + level3).prop("disabled", false).attr("type", "text").attr("placeholder", ClientMessages.directly_available).removeClass("bg-green-300").addClass("bg-gray-200");
} else {
Expand All @@ -104183,16 +104155,23 @@ def note_with_error(value, err):
}
}
function add_account_placeholder() {
let row = $("#account_row_unique").clone();
row.removeClass("hidden");
row.attr("id", "");
row.find(":input").each(function() {
if ($(this).prop("id") != "classes") {
$(this).prop("required", true);
}
});
const rowTemplate = $("#account_row_unique").clone();
rowTemplate.removeClass("hidden");
rowTemplate.attr("id", "");
function updateDataCyAttributes(row, index3) {
row.find("[data-cy]").each(function() {
const currentCy = $(this).attr("data-cy");
if (currentCy) {
const newCy = currentCy.replace(/_\d+$/, `_${index3}`);
$(this).attr("data-cy", newCy);
}
});
}
const existingRowsCount = $(".account_row").length;
for (let x = 0; x < 5; x++) {
row.clone().appendTo("#account_rows_container");
const newRow = rowTemplate.clone();
updateDataCyAttributes(newRow, existingRowsCount + x + 1);
newRow.appendTo("#account_rows_container");
}
}
function generate_passwords() {
Expand Down Expand Up @@ -104327,21 +104306,8 @@ def note_with_error(value, err):
}
function initializeCustomizeClassPage(options) {
$(document).ready(function() {
$("input").on("change", function() {
markUnsavedChanges();
});
$("#back_to_class").on("click", () => {
function backToClass() {
window.location.href = `/for-teachers/class/${options.class_id}`;
}
if (hasUnsavedChanges()) {
modal.confirm(ClientMessages.unsaved_class_changes, () => {
clearUnsavedChanges();
backToClass();
});
} else {
backToClass();
}
window.location.href = `/for-teachers/class/${options.class_id}`;
});
$("[id^=opening_date_level_]").each(function() {
setDateLevelInputColor($(this).attr("level"));
Expand Down
6 changes: 3 additions & 3 deletions static/js/appbundle.js.map

Large diffs are not rendered by default.

29 changes: 0 additions & 29 deletions static/js/browser-helpers/unsaved-changes.ts

This file was deleted.

1 change: 0 additions & 1 deletion static/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export * from './statistics';
export * from './logs';
export * from './tutorials/tutorial';
export * from './teachers';
export * from './browser-helpers/unsaved-changes';
export * from './initialize';
export * from './debugging';
export { getPreviousAndNext } from './tabs';
Expand Down
61 changes: 27 additions & 34 deletions static/js/teachers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { modal } from './modal';
import { showAchievements, theKeywordLanguage } from "./app";
import { markUnsavedChanges, clearUnsavedChanges, hasUnsavedChanges } from './browser-helpers/unsaved-changes';
import { ClientMessages } from './client-messages';
import DOMPurify from 'dompurify'
import { startTeacherTutorial } from './tutorials/tutorial';
Expand Down Expand Up @@ -59,7 +58,7 @@ export function rename_class(id: string, class_name_prompt: string) {
}

export function duplicate_class(id: string, teacher_classes: string[], second_teacher_prompt: string, prompt: string, defaultValue: string = '') {
if (teacher_classes){
if (teacher_classes && !defaultValue){
modal.confirm(second_teacher_prompt, function () {
apiDuplicateClass(id, prompt, true, defaultValue);
}, function () {
Expand Down Expand Up @@ -429,7 +428,6 @@ export function save_customizations(class_id: string) {
showAchievements(response.achievement, false, "");
}
modal.notifySuccess(response.success);
clearUnsavedChanges();
$('#remove_customizations_button').removeClass('hidden');
}).fail(function (err) {
modal.notifyError(err.responseText);
Expand Down Expand Up @@ -472,7 +470,6 @@ export function restore_customization_to_default(prompt: string) {
}

export function enable_level(level: string) {
markUnsavedChanges();
if ($('#enable_level_' + level).is(':checked')) {
$('#opening_date_level_' + level).prop('disabled', false)
.attr('type', 'text')
Expand Down Expand Up @@ -510,19 +507,31 @@ export function setDateLevelInputColor(level: string) {
}

export function add_account_placeholder() {
let row = $('#account_row_unique').clone();
row.removeClass('hidden');
row.attr('id', "");
// Set all inputs except class to required
row.find(':input').each(function() {
if ($(this).prop('id') != 'classes') {
$(this).prop('required', true);
}
});
// Append 5 rows at once
for (let x = 0; x < 5; x++) {
row.clone().appendTo("#account_rows_container");
}
// Get the hidden row template
const rowTemplate = $('#account_row_unique').clone();
rowTemplate.removeClass('hidden');
rowTemplate.attr('id', "");

// Function to update data-cy attributes
function updateDataCyAttributes(row: JQuery<HTMLElement>, index: number) {
row.find('[data-cy]').each(function() {
const currentCy = $(this).attr('data-cy');
if (currentCy) {
const newCy = currentCy.replace(/_\d+$/, `_${index}`);
$(this).attr('data-cy', newCy);
}
});
}

// Get the current number of rows
const existingRowsCount = $('.account_row').length;

// Append 5 rows at once
for (let x = 0; x < 5; x++) {
const newRow = rowTemplate.clone();
updateDataCyAttributes(newRow, existingRowsCount + x + 1);
newRow.appendTo("#account_rows_container");
}
}

export function generate_passwords() {
Expand Down Expand Up @@ -694,24 +703,8 @@ export interface InitializeCustomizeClassPageOptions {

export function initializeCustomizeClassPage(options: InitializeCustomizeClassPageOptions) {
$(document).ready(function(){
// Use this to make sure that we return a prompt when a user leaves the page without saving
$( "input" ).on('change', function() {
markUnsavedChanges();
});

$('#back_to_class').on('click', () => {
function backToClass() {
window.location.href = `/for-teachers/class/${options.class_id}`;
}

if (hasUnsavedChanges()) {
modal.confirm(ClientMessages.unsaved_class_changes, () => {
clearUnsavedChanges();
backToClass();
});
} else {
backToClass();
}
window.location.href = `/for-teachers/class/${options.class_id}`;
});

$('[id^=opening_date_level_]').each(function() {
Expand Down
10 changes: 0 additions & 10 deletions static/js/tutorials/intro.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {pushAchievement, runit, theGlobalEditor} from "../app";
import {addHighlightBorder, relocatePopup, removeBorder, tutorialPopup} from "./utils";
import { clearUnsavedChanges } from '../browser-helpers/unsaved-changes';

let current_step = 0;

Expand Down Expand Up @@ -158,8 +157,6 @@ function levelDefaultStep() {
$('#adventures').addClass('z-40 bg-gray-100');
$('#adventures').show();

// Set to false, prevent "are you sure you want to switch without saving" pop-up
clearUnsavedChanges();

addHighlightBorder("adventures");
relocatePopup(50, 40);
Expand All @@ -169,8 +166,6 @@ function levelDefaultStep() {
function adventureTabsStep() {
$('#adventures_buttons').children().each(function() {
if ($(this).attr('data-tab') == "story") {
// Set to false, prevent "are you sure you want to switch without saving" pop-up
clearUnsavedChanges();
$(this).click();
}
});
Expand All @@ -181,8 +176,6 @@ function adventureTabsStep() {
function parsonsTabStep() {
$('#adventures_buttons').children().each(function() {
if ($(this).attr('data-tab') == "parsons") {
// Set to false, prevent "are you sure you want to switch without saving" pop-up
clearUnsavedChanges();
$(this).click();
}
});
Expand All @@ -192,8 +185,6 @@ function parsonsTabStep() {
function quizTabStep() {
$('#adventures_buttons').children().each(function() {
if ($(this).attr('data-tab') == "quiz") {
// Set to false, prevent "are you sure you want to switch without saving" pop-up
clearUnsavedChanges();
$(this).click();
}
});
Expand All @@ -204,7 +195,6 @@ function saveShareStep() {
// We should go back to the intro tab to make sure the save/share option is shown
$('#adventures_buttons').children().each(function() {
if ($(this).attr('data-tab') == "default") {
clearUnsavedChanges();
$(this).click();
}
});
Expand Down
8 changes: 4 additions & 4 deletions templates/create-accounts.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ <h2 class="w-full text-center my-0 py-0">{{_('password')}}</h2>
<!-- we create one hidden row -> we can simply copy this one and append() below when adding rows -->
{% for i in range(5) %}
<div class="flex flex-row w-full gap-2 items-center mb-4 account_row {% if i == 0 %}hidden{% endif %}" {% if i == 0 %}id="account_row_unique"{% endif %}>
<input id="username" data-cy="username" autocomplete="off" name="username" type=text placeholder="{{_('username')}}" 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">
<input id="password" data-cy="password" autocomplete="off" name="password" minlength="6" type=text placeholder="{{_('password')}}" class="passwords_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">
<input id="username" data-cy="username_{{i}}" autocomplete="off" name="username" type=text placeholder="{{_('username')}}" 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">
<input id="password" data-cy="password_{{i}}" autocomplete="off" name="password" minlength="6" type=text placeholder="{{_('password')}}" class="passwords_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">
<input id="classes" name="class" value="{{current_class.name}}" disabled type="hidden">
<svg class="fill-current w-40 text-red-500 cursor-pointer" xmlns="http://www.w3.org/2000/svg" onclick="$(this).parent().remove();" viewBox="0 0 20 20"><path d="M14.348 14.849a1.2 1.2 0 0 1-1.697 0L10 11.819l-2.651 3.029a1.2 1.2 0 1 1-1.697-1.697l2.758-3.15-2.759-3.152a1.2 1.2 0 1 1 1.697-1.697L10 8.183l2.651-3.031a1.2 1.2 0 1 1 1.697 1.697l-2.758 3.152 2.758 3.15a1.2 1.2 0 0 1 0 1.698z"/></svg>
<svg data-cy="remove_student_{{i}}" class="fill-current w-40 text-red-500 cursor-pointer" xmlns="http://www.w3.org/2000/svg" onclick="$(this).parent().remove();" viewBox="0 0 20 20"><path d="M14.348 14.849a1.2 1.2 0 0 1-1.697 0L10 11.819l-2.651 3.029a1.2 1.2 0 1 1-1.697-1.697l2.758-3.15-2.759-3.152a1.2 1.2 0 1 1 1.697-1.697L10 8.183l2.651-3.031a1.2 1.2 0 1 1 1.697 1.697l-2.758 3.152 2.758 3.15a1.2 1.2 0 0 1 0 1.698z"/></svg>
</div>
{% endfor %}
</div>
Expand Down Expand Up @@ -61,7 +61,7 @@ <h2 class="w-full text-center my-0 py-0">{{_('password')}}</h2>
<button class="yellow-btn text-white" onclick="hedyApp.append_classname();">{{_('postfix_classname')}}</button>
<button type="reset" data-cy="reset_button" class="red-btn" onclick="window.open('/for-teachers/create-accounts/{{ current_class.id }}', '_self');">
{{_('reset_view')}}</button>
<button type="submit" id="create_accounts_button" class="blue-btn px-4">{{_('create_accounts')}}</button>
<button type="submit" data-cy="create_accounts_button" class="blue-btn px-4">{{_('create_accounts')}}</button>
</div>
</div>
</form>
Expand Down
Loading
Loading