Best JavaScript code snippet using taiko
university.js
Source:university.js
...20 let newDosen = {};21 //starting the view of the application and prompting for username22 view.startingHeader();23 prevState = "askingUsername"24 rl.setPrompt("Username : ");25 rl.prompt();26 //readline27 rl.on("line", function(line) {28 //if there is no user selected, we will get inside this if statement block29 if(selectedUser === undefined) {30 //prompting password to the user31 if(prevState === "askingUsername") {32 prevState = "askingPassword"33 usernameInput = line34 rl.setPrompt("Password : ");35 view.singleLine();36 rl.prompt();37 }38 //check whether the username and password match39 else if(prevState === "askingPassword") {40 prevState = "checkingPassword"41 passwordInput = line42 //selectedUser43 selectedUser = model.userVerification(usernameInput, passwordInput, data.user)44 if(selectedUser === undefined) {45 prevState = "askingUsername"46 view.loginFailed();47 rl.setPrompt("Username : ");48 rl.prompt();49 }50 }51 }52 //if username and password is correct, the code block will run53 if (selectedUser !== undefined) {54 //=============================55 //main menu56 //=============================57 if(prevState === "checkingPassword") {58 prevState = "mainMenu";59 view.userPanel(selectedUser.NAMA_USER, selectedUser.ROLE)60 view.mainMenu();61 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");62 rl.prompt();63 }64 //=============================65 //students menu view66 //=============================67 else if (line.trim() === "1" && prevState === "mainMenu") {68 prevState = "mahasiswaMenu";69 view.mahasiswaMenu();70 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");71 rl.prompt();72 }73 //=============================74 //List of all students75 //=============================76 else if(line.trim() === "1" && prevState === "mahasiswaMenu") {77 prevState = "mahasiswaMenu"78 view.cliTable(data, "mahasiswa")79 view.mahasiswaMenu();80 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");81 rl.prompt();82 }83 //=============================84 //searching for specific student, prompting for student's identification number85 //=============================86 else if ( line.trim() === "2" && (prevState === "mahasiswaMenu") ) {87 prevState = "mahasiswaMenuCariMahasiswa1";88 view.singleLine();89 rl.setPrompt("Masukkan NIM : ");90 rl.prompt();91 }92 //=============================93 //searching's logic for finding specific student94 //=============================95 else if (prevState === "mahasiswaMenuCariMahasiswa1" || prevState === "nimTidakDitemukan") {96 let NIMMAhasiswa = line;97 let selectedDataMahasiswa = model.searchMember(NIMMAhasiswa, data, "mahasiswa", "NIM")98 //if we find the student, display him/her99 if (selectedDataMahasiswa) {100 view.cariMahasiswa(101 selectedDataMahasiswa.data.NIM,102 selectedDataMahasiswa.data.NAMA_MAHASISWA,103 selectedDataMahasiswa.data.ALAMAT,104 selectedDataMahasiswa.data.UMUR,105 selectedDataMahasiswa.data.JURUSANID106 );107 view.mahasiswaMenu();108 prevState = "mahasiswaMenu";109 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");110 rl.prompt();111 }112 //else, tell the user we don't find him/her113 else {114 prevState = "nimTidakDitemukan";115 console.log(`mahasiswa dengan NIM ${NIMMAhasiswa} tidak terdaftar`);116 rl.setPrompt("Masukkan NIM : ");117 rl.prompt();118 }119 }120 //=============================121 //adding new student & prompting his/her name122 //=============================123 else if (line.trim() === "3" && prevState === "mahasiswaMenu") {124 view.addMember()125 prevState = "tambahMuridNAMA";126 rl.setPrompt("NAMA:");127 rl.prompt();128 }129 //=============================130 //adding new student & prompting his/her identification number (NIM)131 //=============================132 else if (prevState === "tambahMuridNAMA") {133 newStudent.MAHASISWAID = data.mahasiswa.length + 1;134 newStudent.NAMA_MAHASISWA = line;135 prevState = "tambahMuridNIM";136 rl.setPrompt("NIM:");137 rl.prompt();138 }139 //=============================140 //adding new student & prompting his/her field of study141 //=============================142 else if (prevState === "tambahMuridNIM") {143 newStudent.NIM = line;144 prevState = "tambahMuridJURUSAN";145 rl.setPrompt("JURUSAN:");146 rl.prompt();147 }148 //=============================149 //adding new student & prompting his/her age150 //=============================151 else if (prevState === "tambahMuridJURUSAN") {152 newStudent.JURUSANID = Number(line);153 prevState = "tambahMuridUMUR";154 rl.setPrompt("UMUR:");155 rl.prompt();156 }157 //=============================158 //adding new student & prompting his/her address159 //=============================160 else if (prevState === "tambahMuridUMUR") {161 newStudent.UMUR = Number(line);162 prevState = "tambahMuridALAMAT";163 rl.setPrompt("ALAMAT:");164 rl.prompt();165 }166 //=============================167 //adding new student & prompting his/her field of study168 //=============================169 else if (prevState === "tambahMuridALAMAT") {170 newStudent.ALAMAT = line;171 prevState = "mahasiswaMenu";172 data.mahasiswa.push(newStudent);173 view.cliTable(data, "mahasiswa")174 view.mahasiswaMenu();175 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");176 rl.prompt();177 }178 //=============================179 //delete student menu180 //=============================181 else if (line.trim() === "4" && prevState === "mahasiswaMenu") {182 prevState = "hapusMurid";183 view.singleLine();184 rl.setPrompt("masukkan NIM mahasiswa yang akan dihapus:");185 rl.prompt();186 }187 //=============================188 //the logic for deleting the student189 //=============================190 else if (prevState === "hapusMurid") {191 var NIMMAhasiswa = line;192 var indexMahasiswa = model.searchMember(NIMMAhasiswa, data, "mahasiswa", "NIM");193 data.mahasiswa = model.deleteData(data, indexMahasiswa.index, "mahasiswa");194 view.cliTable(data, "mahasiswa")195 console.log(`mahasiswa dengan NIM: ${NIMMAhasiswa} telah dihapus`);196 view.mahasiswaMenu();197 prevState = "mahasiswaMenu";198 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");199 rl.prompt();200 }201 //=============================202 //going back to the main menu203 //=============================204 else if (line.trim() === "5" && prevState === "mahasiswaMenu") {205 prevState = "mainMenu";206 view.mainMenu();207 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");208 rl.prompt();209 }210 //=============================211 //field of study menu212 //=============================213 else if (line.trim() === "2" && prevState === "mainMenu") {214 prevState = "mainMenu";215 view.cliTable(data, "jurusan")216 view.mainMenu();217 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");218 rl.prompt();219 }220 //=============================221 //Teachers menu222 //=============================223 else if (line.trim() === "3" && prevState === "mainMenu") {224 view.dosenMenu();225 prevState = "dosenMenu"226 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");227 rl.prompt();228 }229 //=============================230 //displaying all teachers231 //=============================232 else if(line.trim() === "1" && prevState === "dosenMenu") {233 view.cliTable(data, "dosen")234 view.dosenMenu();235 prevState = "dosenMenu"236 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");237 rl.prompt();238 }239 //=============================240 //searching teachers menu & prompting for his/her identification number (NIP)241 //=============================242 else if(line.trim() === "2" && prevState === "dosenMenu") {243 prevState = "dosenMenuCariDosen"244 view.singleLine();245 rl.setPrompt("Masukkan NIP : ");246 rl.prompt();247 }248 //=============================249 //the logic behind teachers search250 //=============================251 else if (prevState === "dosenMenuCariDosen" || prevState === "nipTidakDitemukan") {252 let NIPDosen = line;253 //let selectedDosen = searchDosen(NIPDosen, data.dosen);254 let selectedDosen = model.searchMember(NIPDosen, data, "dosen", "NIP")255 //if we found the teacher, we will display his/her data to the user256 if(selectedDosen) {257 view.cariDosen(258 selectedDosen.data.NAMA_DOSEN,259 selectedDosen.data.NIP);260 view.dosenMenu();261 prevState = "dosenMenu";262 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");263 rl.prompt();264 }265 //otherwise, tell the user we did't find him/her266 else {267 console.log(`dosen dengan NIP ${NIPDosen} tidak terdaftar`);268 rl.setPrompt("Masukkan NIP : ");269 prevState = "nipTidakDitemukan"270 rl.prompt();271 }272 }273 //=============================274 //adding new teacher && prompting for his/her name275 //=============================276 else if(line.trim() === "3" && prevState === "dosenMenu") {277 view.addMember()278 rl.setPrompt("NAMA: ");279 prevState = "tambahDosenNama";280 rl.prompt();281 }282 //=============================283 //adding new teacher && prompting for his/her user identification (NIP)284 //=============================285 else if(prevState === "tambahDosenNama") {286 newDosen.DOSENID = data.dosen.length + 1;287 newDosen.NAMA_DOSEN = line;288 rl.setPrompt("NIP: ");289 prevState = "tambahDosenNIP"290 rl.prompt();291 }292 //=============================293 //adding the new teacher into the database294 //=============================295 else if(prevState === "tambahDosenNIP") {296 newDosen.NIP = line;297 data.dosen.push(newDosen)298 view.cliTable(data, "dosen")299 view.dosenMenu()300 prevState = "dosenMenu"301 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");302 rl.prompt();303 }304 //=============================305 //delete teacher menu && prompting for his/her NIP306 //=============================307 else if(line.trim() === "4" && prevState === "dosenMenu") {308 prevState = "hapusDosen";309 view.singleLine();310 rl.setPrompt("masukkan NIP Dosen yang akan dihapus:");311 rl.prompt();312 }313 //=============================314 //delete teacher logic315 //=============================316 else if(prevState === "hapusDosen" || prevState === "gagalHapusDosen") {317 var NIPDosen = line;318 var indexDosen = model.searchMember(NIPDosen, data, "dosen", "NIP")319 //if we find the teacher, delete him/her data, and tell the user320 if(indexDosen !== undefined) {321 data.dosen = model.deleteData(data, indexDosen.index, "dosen");322 view.cliTable(data, "dosen")323 console.log(`dosen dengan NIP ${NIPDosen} telah dihapus`);324 view.dosenMenu();325 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");326 prevState = "dosenMenu"327 rl.prompt();328 }329 //otherwise, prompt the user again for his/her NIP330 else {331 console.log(`dosen dengan NIP ${NIPDosen} tidak terdaftar`);332 rl.setPrompt("masukkan NIP Dosen yang akan dihapus:");333 prevState = "gagalHapusDosen"334 rl.prompt();335 }336 }337 //=============================338 //going back to main menu from teacher's menu339 //=============================340 else if (line.trim() === "5" && prevState === "dosenMenu") {341 view.mainMenu();342 prevState = "mainMenu";343 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");344 rl.prompt();345 }346 //=============================347 //the coursework's menu348 //=============================349 else if (line.trim() === "4" && prevState === "mainMenu") {350 view.cliTable(data, "matakuliah")351 view.mainMenu();352 prevState = "mainMenu"353 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");354 rl.prompt();355 }356 //=============================357 //kontrakkuliah menu358 //=============================359 else if (line.trim() === "5" && prevState === "mainMenu") {360 view.cliTable(data, "kontrakkuliah")361 view.mainMenu();362 prevState = "mainMenu"363 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");364 rl.prompt();365 }366 //=============================367 //logout menu368 //=============================369 else if (line === "6" && prevState === "mainMenu") {370 //comparing whether the user make a change to the database371 var dataComparison = JSON.stringify(originalData) === JSON.stringify(data);372 //if the user did not change the database, logout the user373 if(dataComparison) {374 selectedUser = undefined;375 view.noDataChange()376 view.logout()377 view.startingHeader()378 prevState = "askingUsername"379 rl.setPrompt("Username :");380 rl.prompt();381 }382 //otherwise, set the state that there is a change, prompt for confirmation383 //whether to save the change or not384 else {385 prevState = "differentDataComparison"386 view.dataChangePrompt()387 rl.setPrompt("yes/no :");388 rl.prompt();389 }390 }391 //=============================392 //logout confirmation logic (the user want to save the database changes)393 //=============================394 else if( (line.trim().toLowerCase() === "y" || line.trim().toLowerCase() === "yes") && prevState === "differentDataComparison") {395 selectedUser = undefined;396 view.savingData()397 prevState = "askingUsername"398 model.saveDatabase(originalData, data)399 originalData = data;400 rl.setPrompt("Username :");401 rl.prompt();402 }403 //=============================404 //logout confirmation logic (the user don't want to save the database changes)405 //=============================406 else if( (line.trim().toLowerCase() === "n" || line.trim().toLowerCase() === "no") && prevState === "differentDataComparison") {407 view.noDataChange();408 prevState = "askingUsername"409 rl.setPrompt("Username :");410 rl.prompt();411 }412 }413 });...
test.js
Source:test.js
...20 let newDosen = {};21 //starting the view of the application and prompting for username22 view.startingHeader();23 prevState = "askingUsername"24 rl.setPrompt("Username : ");25 rl.prompt();26 //readline27 rl.on("line", function(line) {28 //if there is no user selected, we will get inside this if statement block29 if(selectedUser === undefined) {30 //prompting password to the user31 if(prevState === "askingUsername") {32 prevState = "askingPassword"33 usernameInput = line34 rl.setPrompt("Password : ");35 view.singleLine();36 rl.prompt();37 }38 //check whether the username and password match39 else if(prevState === "askingPassword") {40 prevState = "checkingPassword"41 passwordInput = line42 //selectedUser43 selectedUser = model.userVerification(usernameInput, passwordInput, data.user)44 if(selectedUser === undefined) {45 prevState = "askingUsername"46 view.loginFailed();47 rl.setPrompt("Username : ");48 rl.prompt();49 }50 }51 }52 //if username and password is correct, the code block will run53 if (selectedUser !== undefined) {54 //=============================55 //main menu56 //=============================57 if(prevState === "checkingPassword") {58 prevState = "mainMenu";59 view.userPanel(selectedUser.NAMA_USER, selectedUser.ROLE)60 view.mainMenu();61 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");62 rl.prompt();63 }64 //=============================65 //students menu view66 //=============================67 else if (line.trim() === "1" && prevState === "mainMenu") {68 prevState = "mahasiswaMenu";69 view.mahasiswaMenu();70 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");71 rl.prompt();72 }73 //=============================74 //List of all students75 //=============================76 else if(line.trim() === "1" && prevState === "mahasiswaMenu") {77 prevState = "mahasiswaMenu"78 view.cliTable(data, "mahasiswa")79 view.mahasiswaMenu();80 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");81 rl.prompt();82 }83 //=============================84 //searching for specific student, prompting for student's identification number85 //=============================86 else if ( line.trim() === "2" && (prevState === "mahasiswaMenu") ) {87 prevState = "mahasiswaMenuCariMahasiswa1";88 view.singleLine();89 rl.setPrompt("Masukkan NIM : ");90 rl.prompt();91 }92 //=============================93 //searching's logic for finding specific student94 //=============================95 else if (prevState === "mahasiswaMenuCariMahasiswa1" || prevState === "nimTidakDitemukan") {96 let NIMMAhasiswa = line;97 let selectedDataMahasiswa = model.searchMember(NIMMAhasiswa, data, "mahasiswa", "NIM")98 //if we find the student, display him/her99 if (selectedDataMahasiswa) {100 view.cariMahasiswa(101 selectedDataMahasiswa.data.NIM,102 selectedDataMahasiswa.data.NAMA_MAHASISWA,103 selectedDataMahasiswa.data.ALAMAT,104 selectedDataMahasiswa.data.UMUR,105 selectedDataMahasiswa.data.JURUSANID106 );107 view.mahasiswaMenu();108 prevState = "mahasiswaMenu";109 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");110 rl.prompt();111 }112 //else, tell the user we don't find him/her113 else {114 prevState = "nimTidakDitemukan";115 console.log(`mahasiswa dengan NIM ${NIMMAhasiswa} tidak terdaftar`);116 rl.setPrompt("Masukkan NIM : ");117 rl.prompt();118 }119 }120 //=============================121 //adding new student & prompting his/her name122 //=============================123 else if (line.trim() === "3" && prevState === "mahasiswaMenu") {124 view.addMember()125 prevState = "tambahMuridNAMA";126 rl.setPrompt("NAMA:");127 rl.prompt();128 }129 //=============================130 //adding new student & prompting his/her identification number (NIM)131 //=============================132 else if (prevState === "tambahMuridNAMA") {133 newStudent.MAHASISWAID = data.mahasiswa.length + 1;134 newStudent.NAMA_MAHASISWA = line;135 prevState = "tambahMuridNIM";136 rl.setPrompt("NIM:");137 rl.prompt();138 }139 //=============================140 //adding new student & prompting his/her field of study141 //=============================142 else if (prevState === "tambahMuridNIM") {143 newStudent.NIM = line;144 prevState = "tambahMuridJURUSAN";145 rl.setPrompt("JURUSAN:");146 rl.prompt();147 }148 //=============================149 //adding new student & prompting his/her age150 //=============================151 else if (prevState === "tambahMuridJURUSAN") {152 newStudent.JURUSANID = Number(line);153 prevState = "tambahMuridUMUR";154 rl.setPrompt("UMUR:");155 rl.prompt();156 }157 //=============================158 //adding new student & prompting his/her address159 //=============================160 else if (prevState === "tambahMuridUMUR") {161 newStudent.UMUR = Number(line);162 prevState = "tambahMuridALAMAT";163 rl.setPrompt("ALAMAT:");164 rl.prompt();165 }166 //=============================167 //adding new student & prompting his/her field of study168 //=============================169 else if (prevState === "tambahMuridALAMAT") {170 newStudent.ALAMAT = line;171 prevState = "mahasiswaMenu";172 data.mahasiswa.push(newStudent);173 view.cliTable(data, "mahasiswa")174 view.mahasiswaMenu();175 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");176 rl.prompt();177 }178 //=============================179 //delete student menu180 //=============================181 else if (line.trim() === "4" && prevState === "mahasiswaMenu") {182 prevState = "hapusMurid";183 view.singleLine();184 rl.setPrompt("masukkan NIM mahasiswa yang akan dihapus:");185 rl.prompt();186 }187 //=============================188 //the logic for deleting the student189 //=============================190 else if (prevState === "hapusMurid") {191 var NIMMAhasiswa = line;192 var indexMahasiswa = model.searchMember(NIMMAhasiswa, data, "mahasiswa", "NIM");193 data.mahasiswa = model.deleteData(data, indexMahasiswa.index, "mahasiswa");194 view.cliTable(data, "mahasiswa")195 console.log(`mahasiswa dengan NIM: ${NIMMAhasiswa} telah dihapus`);196 view.mahasiswaMenu();197 prevState = "mahasiswaMenu";198 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");199 rl.prompt();200 }201 //=============================202 //going back to the main menu203 //=============================204 else if (line.trim() === "5" && prevState === "mahasiswaMenu") {205 prevState = "mainMenu";206 view.mainMenu();207 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");208 rl.prompt();209 }210 //=============================211 //field of study menu212 //=============================213 else if (line.trim() === "2" && prevState === "mainMenu") {214 prevState = "mainMenu";215 view.cliTable(data, "jurusan")216 view.mainMenu();217 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");218 rl.prompt();219 }220 //=============================221 //Teachers menu222 //=============================223 else if (line.trim() === "3" && prevState === "mainMenu") {224 view.dosenMenu();225 prevState = "dosenMenu"226 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");227 rl.prompt();228 }229 //=============================230 //displaying all teachers231 //=============================232 else if(line.trim() === "1" && prevState === "dosenMenu") {233 view.cliTable(data, "dosen")234 view.dosenMenu();235 prevState = "dosenMenu"236 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");237 rl.prompt();238 }239 //=============================240 //searching teachers menu & prompting for his/her identification number (NIP)241 //=============================242 else if(line.trim() === "2" && prevState === "dosenMenu") {243 prevState = "dosenMenuCariDosen"244 view.singleLine();245 rl.setPrompt("Masukkan NIP : ");246 rl.prompt();247 }248 //=============================249 //the logic behind teachers search250 //=============================251 else if (prevState === "dosenMenuCariDosen" || prevState === "nipTidakDitemukan") {252 let NIPDosen = line;253 //let selectedDosen = searchDosen(NIPDosen, data.dosen);254 let selectedDosen = model.searchMember(NIPDosen, data, "dosen", "NIP")255 //if we found the teacher, we will display his/her data to the user256 if(selectedDosen) {257 view.cariDosen(258 selectedDosen.data.NAMA_DOSEN,259 selectedDosen.data.NIP);260 view.dosenMenu();261 prevState = "dosenMenu";262 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");263 rl.prompt();264 }265 //otherwise, tell the user we did't find him/her266 else {267 console.log(`dosen dengan NIP ${NIPDosen} tidak terdaftar`);268 rl.setPrompt("Masukkan NIP : ");269 prevState = "nipTidakDitemukan"270 rl.prompt();271 }272 }273 //=============================274 //adding new teacher && prompting for his/her name275 //=============================276 else if(line.trim() === "3" && prevState === "dosenMenu") {277 view.addMember()278 rl.setPrompt("NAMA: ");279 prevState = "tambahDosenNama";280 rl.prompt();281 }282 //=============================283 //adding new teacher && prompting for his/her user identification (NIP)284 //=============================285 else if(prevState === "tambahDosenNama") {286 newDosen.DOSENID = data.dosen.length + 1;287 newDosen.NAMA_DOSEN = line;288 rl.setPrompt("NIP: ");289 prevState = "tambahDosenNIP"290 rl.prompt();291 }292 //=============================293 //adding the new teacher into the database294 //=============================295 else if(prevState === "tambahDosenNIP") {296 newDosen.NIP = line;297 data.dosen.push(newDosen)298 view.cliTable(data, "dosen")299 view.dosenMenu()300 prevState = "dosenMenu"301 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");302 rl.prompt();303 }304 //=============================305 //delete teacher menu && prompting for his/her NIP306 //=============================307 else if(line.trim() === "4" && prevState === "dosenMenu") {308 prevState = "hapusDosen";309 view.singleLine();310 rl.setPrompt("masukkan NIP Dosen yang akan dihapus:");311 rl.prompt();312 }313 //=============================314 //delete teacher logic315 //=============================316 else if(prevState === "hapusDosen" || prevState === "gagalHapusDosen") {317 var NIPDosen = line;318 var indexDosen = model.searchMember(NIPDosen, data, "dosen", "NIP")319 //if we find the teacher, delete him/her data, and tell the user320 if(indexDosen !== undefined) {321 data.dosen = model.deleteData(data, indexDosen.index, "dosen");322 view.cliTable(data, "dosen")323 console.log(`dosen dengan NIP ${NIPDosen} telah dihapus`);324 view.dosenMenu();325 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");326 prevState = "dosenMenu"327 rl.prompt();328 }329 //otherwise, prompt the user again for his/her NIP330 else {331 console.log(`dosen dengan NIP ${NIPDosen} tidak terdaftar`);332 rl.setPrompt("masukkan NIP Dosen yang akan dihapus:");333 prevState = "gagalHapusDosen"334 rl.prompt();335 }336 }337 //=============================338 //going back to main menu from teacher's menu339 //=============================340 else if (line.trim() === "5" && prevState === "dosenMenu") {341 view.mainMenu();342 prevState = "mainMenu";343 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");344 rl.prompt();345 }346 //=============================347 //the coursework's menu348 //=============================349 else if (line.trim() === "4" && prevState === "mainMenu") {350 view.cliTable(data, "matakuliah")351 view.mainMenu();352 prevState = "mainMenu"353 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");354 rl.prompt();355 }356 //=============================357 //kontrakkuliah menu358 //=============================359 else if (line.trim() === "5" && prevState === "mainMenu") {360 view.cliTable(data, "kontrakkuliah")361 view.mainMenu();362 prevState = "mainMenu"363 rl.setPrompt("masukkan salah satu no. dari opsi diatas :");364 rl.prompt();365 }366 //=============================367 //logout menu368 //=============================369 else if (line === "6" && prevState === "mainMenu") {370 //comparing whether the user make a change to the database371 var dataComparison = JSON.stringify(originalData) === JSON.stringify(data);372 //if the user did not change the database, logout the user373 if(dataComparison) {374 selectedUser = undefined;375 view.noDataChange()376 view.logout()377 view.startingHeader()378 prevState = "askingUsername"379 rl.setPrompt("Username :");380 rl.prompt();381 }382 //otherwise, set the state that there is a change, prompt for confirmation383 //whether to save the change or not384 else {385 prevState = "differentDataComparison"386 view.dataChangePrompt()387 rl.setPrompt("yes/no :");388 rl.prompt();389 }390 }391 //=============================392 //logout confirmation logic (the user want to save the database changes)393 //=============================394 else if( (line.trim().toLowerCase() === "y" || line.trim().toLowerCase() === "yes") && prevState === "differentDataComparison") {395 selectedUser = undefined;396 view.savingData()397 prevState = "askingUsername"398 model.saveDatabase(originalData, data)399 originalData = data;400 rl.setPrompt("Username :");401 rl.prompt();402 }403 //=============================404 //logout confirmation logic (the user don't want to save the database changes)405 //=============================406 else if( (line.trim().toLowerCase() === "n" || line.trim().toLowerCase() === "no") && prevState === "differentDataComparison") {407 view.noDataChange();408 prevState = "askingUsername"409 rl.setPrompt("Username :");410 rl.prompt();411 }412 }413 });...
cli-messenger-connect.js
Source:cli-messenger-connect.js
...36 console.log(37 chalk.gray(`Welcome!\nYou can begin chatting ... Type .help for command list`)38 )39 if (!displayName) {40 rl.setPrompt(data.id + '$ ')41 displayName = ws.id = data.id42 }43 else {44 rl.setPrompt(displayName + '$ ')45 ws.id = displayName46 ws.send(47 JSON.stringify({48 message: Events.CHANGE_NAME,49 name: displayName50 })51 )52 }53 }54 else console.log(chalk.gray(data.content))55 }56 else {57 readline.clearLine(process.stdout, 0);58 readline.cursorTo(process.stdout, 0, null);59 console.log(60 chalk.green(`${data.from}$`),61 chalk.green(data.content)62 )63 if (!process.env.SILENT) {64 player.play(process.env.MESSAGE_SOUND_FILE || path.join(__dirname, '../sounds/graceful.mp3'), (err) => {65 if (err) console.error(err)66 })67 }68 }69 rl.prompt()70 }71 else if (data.message == Events.USER_JOINED) {72 rl.setPrompt(SERVER + '$ ')73 rl.prompt()74 console.log(75 chalk.gray(`User ${data.id} joined`)76 )77 rl.setPrompt(ws.id + '$ ')78 rl.prompt()79 }80 else if (data.message == Events.USER_LEFT) {81 rl.setPrompt(SERVER + '$ ')82 rl.prompt()83 console.log(84 chalk.gray(`User ${data.id} left`)85 )86 rl.setPrompt(ws.id + '$ ')87 rl.prompt()88 }89 else if (data.message == Events.LIST_USERS) {90 if (Array.isArray(data.users)) {91 rl.setPrompt(SERVER + '$ ')92 data.users.map(user => {93 rl.prompt()94 console.log(95 chalk.gray(`${user} is in the chat`)96 )97 })98 rl.setPrompt(ws.id + '$ ')99 rl.prompt()100 }101 }102 else if (data.message == Events.CHANGE_NAME) {103 rl.setPrompt(SERVER + '$ ')104 rl.prompt()105 console.log(106 chalk.gray(`${data.from} has changed their name to ${data.to}`)107 )108 rl.setPrompt(ws.id + '$ ')109 rl.prompt()110 }111 })112 const handleError = () => {113 if (!handleError.executed) {114 if (ws.id) displayName = ws.id115 rl.setPrompt(SERVER + '$ ')116 rl.prompt()117 console.log(118 chalk.yellow(`You are not connected ... re-connecting in 3 seconds`)119 )120 rl.setPrompt((displayName|| '') + '$ ')121 rl.prompt()122 sleep(3000).then(() => connect({ displayName }))123 }124 handleError.executed = 1125 }126 ws.on('close', handleError)127 ws.on('error', handleError)128}129module.exports = connect130if (require.main === module) {131 connect({132 displayName: process.env.DISPLAY_NAME || ''133 })134}135rl136.addCommands({137 name: 'list',138 description: 'lists all users on this chat',139 func: function () {140 readline.moveCursor(process.stdout, 0,-1)141 ws.send(142 JSON.stringify({143 message: Events.LIST_USERS144 })145 )146 }147}, {148 name: 'name',149 description: 'change your display name',150 argNames: [ '<names>' ],151 func: function (...names) {152 readline.moveCursor(process.stdout, 0,-1)153 const name = names.join(' ')154 if (name && name.trim()) {155 ws.send(156 JSON.stringify({157 message: Events.CHANGE_NAME,158 name159 })160 )161 ws.id = name162 rl.setPrompt(ws.id + '$ ')163 rl.prompt()164 }165 }166}, {167 name: 'file',168 description: 'upload and send a file',169 func: function () {170 readline.moveCursor(process.stdout, 0,-1)171 openDialog({}).then((files = []) => {172 files.map(file => {173 const form = new FormData()174 form.append('name', file.split('/\/|\\/').slice(-1)[0] || uuid())175 form.append('file', fs.createReadStream(file))176 axios({...
Using AI Code Generation
1const { openBrowser, goto, setPrompt, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await setPrompt("alert", "This is a test alert");6 await click("Alert");7 } catch (e) {8 console.error(e);9 } finally {10 await closeBrowser();11 }12})();13const { openBrowser, goto, setPrompt, closeBrowser } = require('taiko');14(async () => {15 try {16 await openBrowser();17 await setPrompt("confirm", "This is a test confirm");18 await click("Confirm");19 } catch (e) {20 console.error(e);21 } finally {22 await closeBrowser();23 }24})();25const { openBrowser, goto, setPrompt, closeBrowser } = require('taiko');26(async () => {27 try {28 await openBrowser();29 await setPrompt("prompt", "This is a test prompt");30 await click("Prompt");31 } catch (e) {32 console.error(e);33 } finally {34 await closeBrowser();35 }36})();37const { openBrowser, goto, setPrompt, closeBrowser } = require('taiko');38(async () => {39 try {40 await openBrowser();41 await setPrompt("prompt", "This is a test prompt");42 await click("Prompt");43 } catch (e) {44 console.error(e);45 } finally {46 await closeBrowser();47 }48})();49const { openBrowser, goto, setPrompt, closeBrowser } = require('taiko');50(async () => {51 try {52 await openBrowser();53 await setPrompt("prompt", "This is a test prompt");54 await click("Prompt");55 } catch (e) {56 console.error(e);57 } finally {
Using AI Code Generation
1const { openBrowser, goto, setPrompt, textBox, write, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await setPrompt("test");6 await write("test");7 await textBox({id: "lst-ib"}).clear();8 await write("test");9 } catch (e) {10 console.error(e);11 } finally {12 await closeBrowser();13 }14})();
Using AI Code Generation
1const { openBrowser, goto, setPrompt, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await setPrompt("This is a test prompt");6 } catch (e) {7 console.error(e);8 } finally {9 await closeBrowser();10 }11})();12const { openBrowser, goto, setPrompt, closeBrowser } = require('taiko');13(async () => {14 try {15 await openBrowser();16 await setPrompt("This is a test prompt");17 } catch (e) {18 console.error(e);19 } finally {20 await closeBrowser();21 }22})();23const { openBrowser, goto, setPrompt, closeBrowser } = require('taiko');24(async () => {25 try {26 await openBrowser();27 await setPrompt("This is a test prompt");28 } catch (e) {29 console.error(e);30 } finally {31 await closeBrowser();32 }33})();34const { openBrowser, goto, setPrompt, closeBrowser } = require('taiko');35(async () => {36 try {37 await openBrowser();38 await setPrompt("This is a test prompt");39 } catch (e) {40 console.error(e);41 } finally {42 await closeBrowser();43 }44})();45const { openBrowser, goto, setPrompt, closeBrowser } = require('taiko');46(async () => {47 try {48 await openBrowser();49 await setPrompt("This is a test prompt");50 } catch (e) {51 console.error(e);52 } finally {53 await closeBrowser();54 }55})();56const { openBrowser, goto, setPrompt, closeBrowser } = require('taiko');57(async () => {58 try {59 await openBrowser();
Using AI Code Generation
1const { openBrowser, goto, setPrompt, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await setPrompt('test');6 await closeBrowser();7 } catch (e) {8 console.error(e);9 } finally {10 }11})();12 at openBrowser (C:\Users\user1\Documents\taiko_test\node_modules\taiko\lib\taiko.js:146:15)13 at process._tickCallback (internal/process/next_tick.js:68:7)
Using AI Code Generation
1const { openBrowser, write, setPrompt, goto, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await setPrompt("Enter your name");6 await write("Taiko");7 await closeBrowser();8 } catch (e) {9 console.error(e);10 } finally {11 }12})();13const { openBrowser, write, setPrompt, goto, closeBrowser } = require('taiko');14const { setPrompt } = require('taiko/lib/taiko');15const { openBrowser, write, setPrompt, goto, closeBrowser } = require('taiko');16const { setPrompt } = require('taiko/lib/taiko');17const { openBrowser, write, setPrompt, goto, closeBrowser } = require('taiko');18const { setPrompt } = require('taiko/lib/taiko');
Using AI Code Generation
1setConfig({retryTimeout: 10000});2setConfig({observeTime: 500});3setConfig({observe: true});4(async () => {5 try {6 await openBrowser({headless:false});7 await write("taiko",into(textBox(toRightOf("Search"))));8 await click("Google Search");9 await click("Taiko - Browser Automation Tool - Get Started");10 await screenshot({path: "./screenshot.png"});11 await closeBrowser();12 } catch (error) {13 console.error(error);14 } finally {15 closeBrowser();16 }17})();18setConfig({retryTimeout: 10000});19setConfig({observeTime: 500});20setConfig({observe: true});21(async () => {22 try {23 await openBrowser({headless:false});24 await write("taiko",into(textBox
Using AI Code Generation
1setConfig({2});3const { openBrowser, goto, click, closeBrowser, setConfig, setPrompt } = require('taiko');4(async () => {5 try {6 await openBrowser({ headless: false });7 await setPrompt("test");8 await click("test");9 await closeBrowser();10 } catch (e) {11 console.error(e);12 } finally {13 }14})();15 at ExecutionContext._evaluateInternal (/Users/ankita/Documents/taiko/node_modules/puppeteer/lib/ExecutionContext.js:122:13)16 at process._tickCallback (internal/process/next_tick.js:68:7)17 at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)18 at startup (internal/bootstrap/node.js:283:19)19 at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)20setConfig({21});22const { openBrowser, goto, click, closeBrowser, setConfig, setPrompt } = require('taiko');23(async () => {24 try {25 await openBrowser({ headless: false });26 await click("test");27 await closeBrowser();28 } catch (e) {29 console.error(e);30 } finally {31 }32})();33{ test: 'test' }
Using AI Code Generation
1setPrompt('Enter your name');2await openBrowser();3await write('John');4await closeBrowser();5setConfig({6});7await openBrowser();8await write('John');9await closeBrowser();10setNavigationOptions({11});12await openBrowser();13await write('John');14await closeBrowser();15setBrowserConfig({16});17await openBrowser();18await write('John');19await closeBrowser();20await openBrowser();21await setCookie({ name: 'foo', value: 'bar', domain: 'example.com' });22await closeBrowser();23await openBrowser();24await setCookie([25 { name: 'foo', value: 'bar', domain: 'example.com' },26 { name: 'foo1', value: 'bar1', domain: 'example.com' },27]);28await closeBrowser();29await openBrowser();30await setViewPort({ width: 500, height: 500 });31await closeBrowser();32await openBrowser();33await setViewPort({ deviceScaleFactor: 2 });34await closeBrowser();35await openBrowser();36await setViewPort({ isMobile: true });37await closeBrowser();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!