How to use unhide method in Mocha

Best JavaScript code snippet using mocha

Run Mocha automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

common_tasks.js

Source: common_tasks.js Github

copy
1// Copyright (c) 2019, Paul Karugu and contributors
2// For license information, please see license.txt
3
4/* section below contains general functions*/
5// =================================================================================================
6
7// global variables
8
9var field_to_hide_unhide = {
10	hours:["hours"],
11	days:["days"],
12	all:["hours","days"]
13}
14
15/*function that hides fields ,called on refresh*/
16function hide_unhide_fields(frm, list_of_fields, hide_or_unhide) {
17	for (var i = 0; i < list_of_fields.length; i++) {
18		frm.toggle_display(list_of_fields[i], hide_or_unhide)
19	}
20}
21
22// function that hides or unhides certain fields on refresh
23function hide_unhide_on_refresh(frm) {
24	if (frm.doc.average_turn_around_time == "Hours") {
25		hide_function(frm, field_to_hide_unhide, "hours")
26	}
27	else if (frm.doc.average_turn_around_time == "Days") {
28		hide_function(frm, field_to_hide_unhide, "days")
29	}
30	else {
31		hide_function(frm, field_to_hide_unhide, "none")
32	}
33
34	// check whether to show if_yes_which_task_does_this_task_come_after field
35	if(frm.doc.does_this_task_require_to_be_handled_after_another_task == "Yes"){
36		frm.toggle_display("if_yes_which_task_does_this_task_come_after", true)
37	}
38	else{
39		frm.toggle_display("if_yes_which_task_does_this_task_come_after", false)
40	}
41
42	function hide_function(frm, field_to_hide_unhide, selected_option) {
43		var hide_fields = field_to_hide_unhide["all"]
44		var unhide_fields = field_to_hide_unhide[selected_option]
45		if (selected_option == "none") {
46			hide_unhide_fields(frm, hide_fields, false)
47		}
48		else {
49			hide_unhide_fields(frm, hide_fields, false)
50			hide_unhide_fields(frm, unhide_fields, true)
51		}
52	}
53}
54
55// function that alerts a message provided to it as parameter
56function alert_message(message_to_print){
57	msgprint(message_to_print)
58}
59
60/* end of the general functions section
61// =================================================================================================
62/* This section  contains functions that are triggered by the form action refresh or
63reload etc to perform various action*/
64
65frappe.ui.form.on('Common Tasks', {
66	refresh: function(frm) {
67		// hide unhide fields
68		hide_unhide_on_refresh(frm)
69	}
70});
71
72
73// functionality triggered by filling the does_this_task_require_to_be_handled_after_another_task
74frappe.ui.form.on("Common Tasks", "does_this_task_require_to_be_handled_after_another_task", function (frm) {
75	frm.refresh()
76	// clear the unselected field
77	frm.doc.total_time_to_finish_task = ""
78	frm.doc.if_yes_which_task_does_this_task_come_after = ""
79})
80
81// functionality triggered by clicking on the Average Turn Around Time button
82frappe.ui.form.on("Common Tasks", "average_turn_around_time", function (frm) {
83	console.log("triggered avarage")
84	frm.refresh()
85
86	// clear the unselected field
87	frm.doc.days = ""	
88	frm.doc.hours = ""
89	frm.doc.total_time_to_finish_task = ""
90
91	if(frm.doc.hours){
92		console.log("still exists")
93	}
94})
95
96// functionality triggered by filling the hours field
97frappe.ui.form.on("Common Tasks", "hours", function (frm) {
98	calcuate_total_turnaround_time(frm)
99	frm.refresh()
100})
101
102// functionality triggered by filling the days field
103frappe.ui.form.on("Common Tasks", "days", function (frm) {
104	calcuate_total_turnaround_time(frm)
105	frm.refresh()
106})
107
108// functionality triggered by clicking does_this_task_require_to_be_handled_after_another_task
109frappe.ui.form.on("Common Tasks", "if_yes_which_task_does_this_task_come_after", function (frm) {
110	calcuate_total_turnaround_time(frm)
111	frm.refresh()
112})
113
Full Screen

script.js

Source: script.js Github

copy
1
2
3/**
4 *
5 * @param {string} lightboxID 
6 */
7function unhideLightbox(lightboxID) {
8	
9	document.getElementById('lightbox-overlay').classList.remove('hidden');
10
11	
12	document.getElementById(lightboxID).classList.remove('hidden');
13}
14
15
16
17
18function unhideLightbox1() {
19	
20	unhideLightbox("art1");
21}
22
23document.getElementById("picture-1").onclick = unhideLightbox1;
24
25function unhideLightbox2() {
26	unhideLightbox("art2");
27}
28
29document.getElementById("picture-2").onclick = unhideLightbox2;
30
31
32
33function unhideLightbox3() {
34	unhideLightbox("art3");
35}
36
37document.getElementById("picture-3").onclick = unhideLightbox3;
38
39function unhideLightbox4() {
40	unhideLightbox("art4");
41}
42
43document.getElementById("picture-4").onclick = unhideLightbox4;
44
45function unhideLightbox5() {
46	unhideLightbox("art5");
47}
48
49document.getElementById("picture-5").onclick = unhideLightbox5;
50
51function unhideLightbox6() {
52	unhideLightbox("art6");
53}
54
55document.getElementById("picture-6").onclick = unhideLightbox6;
56
57
58
59
60
61function closeLightbox(lightboxID) {
62	document.getElementById('lightbox-overlay').classList.add('hidden');
63
64	document.getElementById(lightboxID).classList.add('hidden');
65}
66
67
68function closeAllLightboxes() {
69	var lightboxElements = document.getElementsByClassName('lightbox');
70
71	for (var i = 0; i < lightboxElements.length; i++) {
72		var id = lightboxElements[i].id;
73		closeLightbox(id);
74	}
75}
76
77document.getElementById("lightbox-overlay").onclick = closeAllLightboxes;
Full Screen

navbar.js

Source: navbar.js Github

copy
1const unhide_conferencing = document.getElementById("conferencing");
2const unhide_online = document.getElementById("online");
3const unhide_warum = document.getElementById("warum");
4const suche = document.getElementById("suche");
5const dropdown_suche = document.getElementById("dropdown_suche");
6const dropdown_conferencing = document.getElementById("dropdown_conferencing");
7const dropdown_online = document.getElementById("dropdown_online");
8const dropdown_warum = document.getElementById("dropdown_warum");
9
10
11suche.addEventListener("mouseover", function () {
12    dropdown_suche.classList.remove("hide");
13    dropdown_conferencing.classList.add("hide")
14    dropdown_online.classList.add("hide");
15    dropdown_warum.classList.add("hide");
16    unhide_conferencing.classList.remove("active_heading");
17    unhide_online.classList.remove("active_heading");
18    unhide_warum.classList.remove("active_heading");
19})
20unhide_conferencing.addEventListener("mouseover", function () {
21    dropdown_suche.classList.add("hide");
22    suche.classList.remove("active_heading");
23    dropdown_conferencing.classList.remove("hide");
24    dropdown_online.classList.add("hide");
25    dropdown_warum.classList.add("hide");
26    unhide_conferencing.classList.add("active_heading");
27    unhide_online.classList.remove("active_heading");
28    unhide_warum.classList.remove("active_heading");
29})
30unhide_online.addEventListener("mouseover", function () {
31    dropdown_suche.classList.add("hide");
32    suche.classList.remove("active_heading");
33    dropdown_conferencing.classList.add("hide");
34    dropdown_online.classList.remove("hide");
35    dropdown_warum.classList.add("hide");
36    unhide_conferencing.classList.remove("active_heading");
37    unhide_online.classList.add("active_heading");
38    unhide_warum.classList.remove("active_heading");
39})
40unhide_warum.addEventListener("mouseover", function () {
41    dropdown_suche.classList.add("hide");
42    suche.classList.remove("active_heading");
43    dropdown_conferencing.classList.add("hide");
44    dropdown_online.classList.add("hide");
45    dropdown_warum.classList.remove("hide");
46    unhide_conferencing.classList.remove("active_heading");
47    unhide_online.classList.remove("active_heading");
48    unhide_warum.classList.add("active_heading");
49})
50
51dropdown_suche.addEventListener("mouseleave", function () {
52    leave_function();
53
54})
55dropdown_conferencing.addEventListener("mouseleave", function () {
56    leave_function()
57})
58dropdown_online.addEventListener("mouseleave", function () {
59    leave_function()
60})
61dropdown_warum.addEventListener("mouseleave", function () {
62    leave_function()
63})
64
65function leave_function() {
66    dropdown_suche.classList.add("hide");
67    dropdown_conferencing.classList.add("hide");
68    dropdown_online.classList.add("hide");
69    dropdown_warum.classList.add("hide");
70    suche.classList.remove("active_heading")
71    unhide_conferencing.classList.remove("active_heading");
72    unhide_online.classList.remove("active_heading");
73    unhide_warum.classList.remove("active_heading");
74    error_message.classList.add("hide_error");
75}
76
77window.onscroll = function () {
78    make_sticky()
79};
80
81const navbar = document.getElementById("navbar_sticky");
82const sticky = navbar.offsetTop;
83
84function make_sticky() {
85    if (window.pageYOffset >= sticky && window.pageYOffset > 0) {
86        navbar.classList.add("nav_sticky")
87    }else {
88        navbar.classList.remove("nav_sticky");
89    }
90}
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Mocha on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)