How to use Song method in Jasmine-core

Best JavaScript code snippet using jasmine-core

chordpro.js

Source:chordpro.js Github

copy

Full Screen

1module.exports = {2 fromString: function(input) {3 title = "";4 artist = "";5 lyrics = [];6 chords = [];7 chorddefinitions = [];8 lineNum = 0;9 sections = [];10 lines = input.split("\n");11 for (i = 0; i < lines.length; i++) {12 line = lines[i].trim();13 if (isaDirective(line)) {14 directive = parseDirective(line);15 if (directive.name == 'title') {16 title = directive.value;17 }18 if (directive.name == 'subtitle') {19 artist = directive.value;20 }21 if (directive.name == 'define') {22 chorddefinitions.push(parseDefinition(directive.value));23 }24 } else {25 if (i == lines.length-1 && !line) {26 // ignore last line if it's empty27 } else {28 lyric = parseLyric(line, lineNum);29 if ((lyric.text.startsWith("Verse") ||30 lyric.text.startsWith("Intro") ||31 lyric.text.startsWith("Outro") ||32 lyric.text.startsWith("Chorus") ||33 lyric.text.startsWith("Bridge")) && lyric.chords.length == 0) {34 if (sections.length > 0) {35 sections[sections.length-1].end = lineNum-1;36 }37 sections.push({ text:lyric.text , start:lineNum , end:0 });38 lyrics.push("");39 } else {40 lyrics.push(lyric.text);41 }42 lineNum++;43 for (c = 0; c < lyric.chords.length; c++) {44 chords.push(lyric.chords[c]);45 }46 }47 }48 }49 if (sections.length > 0) {50 sections[sections.length-1].end = lineNum-1;51 }52 return { title:title , artist:artist , lyrics:lyrics , chords:chords , chorddefs:chorddefinitions , sections:sections };53 },54 toString: function(song) {55 string = "";56 if (song.title != "") {57 string += "{t:" + song.title + "}\n";58 }59 if (song.artist != "") {60 string += "{st:" + song.artist + "}\n";61 }62 for (i = 0; i < song.chorddefs.length; i++) {63 string += "{define: " + song.chorddefs[i].name +64 " base-fret " + song.chorddefs[i].basefret.toString() +65 " frets ";66 for (f = 0; f < song.chorddefs[i].frets.length; f++) {67 if (song.chorddefs[i].frets[f] < 0) {68 string += "x";69 } else {70 string += song.chorddefs[i].frets[f].toString();71 }72 if (f < 5) {73 string += " ";74 }75 }76 string += "}\n"77 }78 var chordNum = 0;79 var sectionNum = 0;80 for (i = 0; i < song.lyrics.length; i++) {81 if (song.sections.length > 0 && song.lyrics[i].length == 0 && song.sections[sectionNum].start == i) {82 string += song.sections[sectionNum].text + "\n";83 if (sectionNum < song.sections.length-1) {84 sectionNum++;85 }86 } else {87 lastCol = 0;88 while (chordNum < song.chords.length && song.chords[chordNum].line == i) {89 string += song.lyrics[i].substring(lastCol, song.chords[chordNum].col) + "["+ song.chords[chordNum].name + "]";90 lastCol = song.chords[chordNum].col;91 chordNum++;92 }93 string += song.lyrics[i].substring(lastCol, song.lyrics[i].length) + "\n";94 }95 }96 return string;97 },98 distinctChords: function(song) {99 distinct = [];100 for (i = 0; i < song.chords.length; i++) {101 found = false;102 if (distinct.indexOf(song.chords[i].name) == -1) {103 distinct.push(song.chords[i].name);104 }105 }106 return distinct;107 },108 addDefs: function(song, defs, options) {109 if (defs.length == 0) {110 return song;111 }112 var hasDefine = defs[0].hasOwnProperty('define');113 // replace first114 if (options.replace) {115 for (i = 0; i < song.chorddefs.length; i++) {116 for (j = 0; j < defs.length; j++) {117 if (song.chorddefs[i].name == defs[j].name) {118 if (hasDefine) {119 define = defs[i].define.substring(8,defs[j].define.length);120 song.chorddefs[i] = parseDefinition(define);121 } else {122 song.chorddefs[i] = defs[j];123 }124 }125 }126 }127 }128 // then add the rest129 for (i = 0; i < defs.length; i++) {130 if (!hasDefinition(song.chorddefs, defs[i].name)) {131 if (hasDefine) {132 define = defs[i].define.substring(8,defs[i].define.length);133 song.chorddefs.push(parseDefinition(define));134 } else {135 song.chorddefs.push(defs[i]);136 }137 }138 }139 return song;140 },141 setChordSequence: function(song, sequence) {142 newChordDefs = [];143 for (i = 0; i < sequence.length; i++) {144 newChordDefs.push(getDefinition(song.chorddefs, sequence[i]));145 }146 song.chorddefs = newChordDefs;147 return song;148 },149 renameChord: function(song, from, to) {150 for (i = 0; i < song.chords.length; i++) {151 if (song.chords[i].name == from) {152 song.chords[i].name = to;153 }154 }155 for (i = 0; i < song.chorddefs.length; i++) {156 if (song.chorddefs[i].name == from) {157 song.chorddefs[i].name = to;158 }159 }160 return song;161 },162 getSection: function(song, id) {163 return getSongSection(song, id);164 },165 moveChord: function(song, from, to) {166 for(ci = 0; ci < song.chords.length; ci++) {167 if (from.line == song.chords[ci].line && from.col == song.chords[ci].col && from.name == song.chords[ci].name) {168 song.chords[ci].col = to.col;169 }170 }171 return song;172 },173 copyChords: function(song, section, toSectionId) {174 var newChords = [];175 for (i = 0; i < song.chords.length; i++) {176 if (song.chords[i].line < song.sections[toSectionId].start) {177 newChords.push(song.chords[i]);178 }179 }180 for (i = 0; i < section.chords.length; i++) {181 section.chords[i].line += (song.sections[toSectionId].start + 1);182 newChords.push(section.chords[i]);183 }184 for (i = 0; i < song.chords.length; i++) {185 if (song.chords[i].line > song.sections[toSectionId].end) {186 newChords.push(song.chords[i]);187 }188 }189 for (i = 0; i < song.chords.length; i++) {190 if (song.chords[i].line > song.sections[toSectionId].end) {191 newChords.push(song.chords[i]);192 }193 }194 song.chords = newChords;195 return song;196 }197};198function hasDefinition(chorddefs, name) {199 for (d = 0; d < chorddefs.length; d++) {200 if (chorddefs[d].name == name) {201 return true;202 }203 }204 return false;205}206function getDefinition(chorddefs, name) {207 for (d = 0; d < chorddefs.length; d++) {208 if (chorddefs[d].name == name) {209 return chorddefs[d];210 }211 }212 return {};213}214function parseDefinition(definition) {215 name = "";216 basefret = "";217 frets = [0,0,0,0,0,0];218 // {define: Am base-fret 0 frets x 0 2 2 1 0}219 var defineRegEx = /([^}]+)\sbase-fret\s([^}]+)\sfrets\s([^}]+)\s([^}]+)\s([^}]+)\s([^}]+)\s([^}]+)\s([^}]+)/;220 if (defineRegEx.test(definition)) {221 match = defineRegEx.exec(definition);222 name = match[1].trim();223 basefret = parseInt(match[2]);224 for (f = 0; f < frets.length; f++) {225 if (match[3+f] == 'x') {226 frets[f] = -1;227 } else {228 frets[f] = parseInt(match[3+f]);229 }230 }231 }232 return { name:name , basefret:basefret , frets:frets };233}234var directiveRegEx = /{([^}]+):([^}]+)}/;235function isaDirective(line) {236 return directiveRegEx.test(line);237}238function parseDirective(line) {239 var matches = directiveRegEx.exec(line);240 if (matches.length == 3) {241 if (matches[1] == 't') {242 matches[1] = 'title';243 }244 if (matches[1] == 'st') {245 matches[1] = 'subtitle';246 }247 return { name:matches[1] , value:matches[2] }248 }249 return {};250}251function getSongSection(song, id) {252 section = { title:"" , chords:[] , lyrics:[] };253 if (id >= 0 && id < song.sections.length) {254 section.title = sections[id].text;255 }256 for (li = sections[id].start+1; li <= sections[id].end; li++) {257 section.lyrics.push(song.lyrics[li]);258 }259 for(ci = 0; ci < song.chords.length; ci++) {260 if (song.sections[id].start <= song.chords[ci].line && song.chords[ci].line <= song.sections[id].end) {261 var newChord = { line:song.chords[ci].line , col:song.chords[ci].col , name:song.chords[ci].name };262 newChord.line -= (song.sections[id].start+1);263 section.chords.push(newChord);264 }265 }266 return section;267}268function parseLyric(line, lineNum) {269 lyric = "";270 isaChord = false;271 chord = "";272 linechords = [];273 col = 0;274 for (j=0; j < line.length; j++) {275 if (line[j] == '[') {276 isaChord = true;277 } else if (line[j] == ']') {278 isaChord = false;279 linechords.push({ name:chord , line:lineNum , col:col });280 chord = "";281 } else {282 if (isaChord) {283 chord += line[j];284 } else {285 col++;286 lyric += line[j];287 }288 }289 }290 return { text:lyric , chords:linechords };...

Full Screen

Full Screen

app.js

Source:app.js Github

copy

Full Screen

...71 var length = songs.length - 1;72 id = length.toString();73 }74 }75 service.getSong(id)76 .success(function(song) {77 $scope.song = song;78 });79 });80 service.getFretboard()81 .success(function(fb) {82 $scope.fretboard = fb;83 $scope.newchordname = fb.chorddef.name;84 });85 }86 $scope.initSection = function() {87 var id = $routeParams.id;88 var sectionid = $routeParams.sectionid;89 service.getSection(id, sectionid)90 .success(function(section) {91 $scope.section = section;92 $scope.sectionid = sectionid;93 if ($scope.section.chords.length > 0) {94 $scope.from = $scope.section.chords[0];95 $scope.to = $scope.section.chords[0];96 }97 });98 service.getSong(id)99 .success(function(song) {100 $scope.song = song;101 });102 }103 $scope.changeSectionChord = function(chordId) {104 var ch = parseInt(chordId);105 $scope.from = $scope.section.chords[ch];106 $scope.to = $scope.section.chords[ch];107 $scope.confirmMoveChord();108 }109 $scope.moveChordRight = function() {110 $scope.to.col += 1;111 $scope.confirmMoveChord();112 }113 $scope.moveChordLeft = function() {114 $scope.to.col -= 1;115 $scope.confirmMoveChord();116 }117 $scope.updateSection = function() {118 service.updateSection($scope.section._id, {section:$scope.section}, $scope.sectionid)119 .success(function(song) {120 $scope.song = song;121 });122 }123 $scope.filterMutedStrings = function(note) {124 return note.mute;125 }126 $scope.filterExcludeMutedStrings = function(note) {127 return !note.mute;128 }129 $scope.filterBaseFretNotZero = function(chorddef) {130 return chorddef.basefret != 0;131 }132 $scope.updateSong = function() {133 service.updateSong({text:$scope.song.text}, $scope.song._id)134 .success(function(song) {135 $scope.song = song;136 });137 }138 $scope.copyChords = function() {139// service.copyChords({text:$scope.song.text}, $scope.song._id)140// .success(function(song) {141// $scope.song = song;142// });143 }144 $scope.editChord = function(chordId) {145 var ch = parseInt(chordId);146 if (ch >= 0 && ch < $scope.song.chorddefs.length) {147 service.updateFretboard($scope.song.chorddefs[ch])...

Full Screen

Full Screen

lyrics.js

Source:lyrics.js Github

copy

Full Screen

1const axios = require('axios');2const LenoxCommand = require('../LenoxCommand.js');3const config = require('../../settings.json');4module.exports = class lyricsCommand extends LenoxCommand {5 constructor(client) {6 super(client, {7 name: 'lyrics',8 group: 'botowner',9 memberName: 'lyrics',10 description: 'Fetch lyrics for a given artist and song',11 format: 'lyrics {query}',12 aliases: [],13 examples: ['lyrics parkway drive - boneyards'],14 clientpermissions: ['SEND_MESSAGES', 'EMBED_LINKS'],15 userpermissions: [],16 shortDescription: 'Lyrics',17 dashboardsettings: false18 });19 }20 async run(msg) {21 const langSet = msg.client.provider.getGuild(msg.guild.id, 'language');22 const lang = require(`../../languages/${langSet}.json`);23 if (!config.owners.includes(msg.author.id)) return msg.channel.send(lang.botownercommands_error);24 const text_truncate = (str, length, ending) => {25 if (length === null) length = 100;26 if (ending === null) ending = '...';27 if (str.length > length) return str.substring(0, length - ending.length) + ending;28 return str;29 };30 const MESSAGE_CHAR_LIMIT = 2000;31 const splitString = (string, prepend = '', append = '') => {32 if (string.length <= MESSAGE_CHAR_LIMIT) return [string];33 const splitIndex = string.lastIndexOf('\n', MESSAGE_CHAR_LIMIT - prepend.length - append.length);34 const sliceEnd = splitIndex > 0 ? splitIndex : MESSAGE_CHAR_LIMIT - prepend.length - append.length;35 const rest = splitString(string.slice(sliceEnd), prepend, append);36 return [`${string.slice(0, sliceEnd)}${append}`, `${prepend}${rest[0]}`, ...rest.slice(1)];37 };38 const input = msg.content.split(' ');39 const searchString = input.slice(1).join(' ');40 if (!searchString) return msg.channel.send(lang.lyrics_nosongname);41 await axios({42 method: 'GET',43 url: `https://api.audd.io/findLyrics/?itunes_country=us&api_token=${config.auddKey}&q=${encodeURIComponent(searchString)}`,44 headers: {45 Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',46 'Content-Type': 'application/json; charset=utf-8'47 }48 }).then(async (res) => {49 if (!res.data.result.length) return msg.channel.send(`Couldn't find lyrics for the song \`${searchString}\`.`);50 const audd_song = res.data.result[0];51 const ksoft_res = await axios.get(`https://ksoft.derpyenterprises.org/lyrics?input=${encodeURIComponent(`${audd_song.artist} - ${audd_song.title}`)}`);52 if (ksoft_res.data.data.length) { // check to make sure ksoft returned a response (this response is used to add properties from ksoft to audd)53 const ksoft_song = ksoft_res.data.data[0];54 if (!audd_song.lyrics && ksoft_song.lyrics) { // make sure audd and ksoft returned lyrics55 audd_song.lyrics = ksoft_song.lyrics;56 }57 else if (!audd_song.lyrics && !ksoft_song.lyrics) { // if audd and ksoft didn't return lyrics then try to get them from makeitpersonal as a last resort58 try {59 const mip_lyrics = await axios.get(`https://makeitpersonal.co/lyrics?artist=${encodeURIComponent(audd_song.artist)}&title=${encodeURIComponent(audd_song.title)}`); // use this api if audd is down or can't find lyrics for a song. (it is rare for audd not to find lyrics for a song but just as a safety precaution.)60 audd_song.lyrics = mip_lyrics.data; // add the lyrics to the audd api (I like doing it this way so I won't have to check the api if it didn't find lyrics before having them sent.)61 }62 catch (e) { }63 }64 /* add properties from ksoft to audd */65 audd_song.album = ksoft_song.album;66 audd_song.album_ids = ksoft_song.album_ids;67 audd_song.album_year = ksoft_song.album_year;68 audd_song.album_art = ksoft_song.album_art;69 audd_song.artist_id = ksoft_song.artist_id;70 audd_song.search_str = ksoft_song.search_str;71 audd_song.popularity = ksoft_song.popularity;72 audd_song.id = ksoft_song.id;73 audd_song.search_score = ksoft_song.search_score;74 }75 audd_song.lyrics = audd_song.lyrics.replace(/^\n+/, '').replace(/\n{3,}/g, '\n\n').replace(/&amp;/g, '&')76 .replace(/&gt;/g, '>')77 .replace(/&lt;/g, '<')78 .replace(/&quot;/g, '"')79 .replace(/&OElig;/g, 'Œ')80 .replace(/&oelig;/g, 'œ')81 .replace(/&Scaron;/g, 'Š')82 .replace(/&scaron;/g, 'š')83 .replace(/&Yuml;/g, 'Ÿ')84 .replace(/&circ;/g, 'ˆ')85 .replace(/&tilde;/g, '˜')86 .replace(/&ndash;/g, '–')87 .replace(/&mdash;/g, '—')88 .replace(/&lsquo;/g, '‘')89 .replace(/&rsquo;/g, '’')90 .replace(/&sbquo;/g, '‚')91 .replace(/&ldquo;/g, '“')92 .replace(/&rdquo;/g, '”')93 .replace(/&bdquo;/g, '„')94 .replace(/&dagger;/g, '†')95 .replace(/&Dagger;/g, '‡')96 .replace(/&permil;/g, '‰')97 .replace(/&lsaquo;/g, '‹')98 .replace(/&rsaquo;/g, '›')99 .replace(/&euro;/g, '€')100 .replace(/&copy;/g, '©')101 .replace(/&trade;/g, '™')102 .replace(/&reg;/g, '®')103 .replace(/&nbsp;/g, ' ');104 audd_song.lyrics = splitString(audd_song.lyrics);105 let pagenum = 1;106 audd_song.lyrics.forEach((page) => { // iterate through the pages107 msg.channel.send({108 embed: {109 description: page.toString() || 'N/A',110 thumbnail: {111 url: audd_song.album_art ? audd_song.album_art : undefined112 },113 timestamp: new Date(),114 color: 3447003,115 title: text_truncate(`${audd_song.album ? `[${audd_song.album}] ` : ''}${audd_song.artist} - ${audd_song.title}${audd_song.album_year ? ` (${audd_song.album_year})` : ''}`, 256),116 author: {117 name: text_truncate(audd_song.artist, 256) || 'N/A'118 },119 footer: {120 text: `${lang.lyrics_page} ${pagenum++ || 'N/A'}`121 }122 }123 });124 });125 }).catch((e) => console.error(e));126 }...

Full Screen

Full Screen

song.js

Source:song.js Github

copy

Full Screen

...4var text2chordpro = require('../../lib/text2chordpro');5var router = require('express').Router();6var Song = require('../../lib/songinmem');7var songs = [];8function getSong(paramId) {9 for (i = 0; i < songs.length; i++) {10 if (songs[i]._id == paramId) {11 return songs[i];12 }13 }14 return null;15}16function parseSong(newText) {17 var song = {18 title: "", _id: "", artist: "",19 lyrics: [],20 chorddefs:[],21 chords: [],22 text: "",23 sections:[]24 };25 if (!text2chordpro.isChordpro(newText)) {26 newText = text2chordpro.fromText(newText);27 }28 song = chordpro.fromString(newText);29 chords = chordpro.distinctChords(song);30 defs = chorddefs.getdefs(chords);31 song = chordpro.addDefs(song, defs, { replace:false });32 for (s = 0; s < song.chorddefs.length; s++) {33 song.chorddefs[s].positions = fretboard.getFingerPositions(song.chorddefs[s]);34 }35 song.text = chordpro.toString(song);36 return song;37}38router.get('/:id',function(req,res,next) {39 var song = getSong(req.params.id);40 if (song == null) {41 Song.findById(req.params.id, function(err, dbSong) {42 if (err) {43 console.error(err);44 return next(err);45 }46 if (dbSong != null && dbSong.text != null) {47 song = parseSong(dbSong.text);48 songs.push(song);49 res.json(song);50 }51 });52 } else {53 res.json(song);54 }55});56router.get('/',function(req,res,next) {57 res.json(songs);58});59router.post('/',function(req,res,next) {60 var song = parseSong(req.body.text);61 song._id = songs.length.toString();62 songs.push(song);63 res.status(201).json(songs[songs.length-1]);64});65router.put('/:id',function(req,res,next) {66 var song = getSong(req.params.id);67 if (song != null) {68 var id = parseInt(song._id);69 if ( req.body.hasOwnProperty('chorddef') ) {70 song = chordpro.addDefs(song, req.body.chorddef, { replace:true });71 song = parseSong(chordpro.toString(song));72 }73 if ( req.body.hasOwnProperty('text') ) {74 song = parseSong(req.body.text);75 }76 song._id = req.params.id;77 songs[id] = song;78 res.status(200).json(song);79 }80});81router.put('/:id/chords/:chordid',function(req,res,next) {82 var song = getSong(req.params.id);83 if (song != null) {84 var id = parseInt(song._id);85 if (req.params.chordid >= 0 && req.params.chordid < song.chords.length) {86 if ( req.body.hasOwnProperty('name') ) {87 song = chordpro.renameChord(song, song.chords[req.params.chordid].name, req.body.name);88 }89 if ( req.body.hasOwnProperty('col') ) {90 var col = parseInt(req.body.col);91 var to = { name:song.chords[req.params.chordid].name , line:song.chords[req.params.chordid].line , col:col };92 song = chordpro.moveChord(song, song.chords[req.params.chordid], to);93 }94 song._id = req.params.id;95 songs[id] = song;96 }97 res.status(200).json(song);98 }99});100router.get('/:id/sections/:sectionid',function(req,res,next) {101 var song = getSong(req.params.id);102 var section = { title:"" , chords:[] , lyrics:[] , _id:''};103 if (song != null) {104 section = chordpro.getSection(song, req.params.sectionid);105 section._id = req.params.id;106 }107 res.json(section);108});109router.put('/:id/sections/:sectionid',function(req,res,next) {110 var song = getSong(req.params.id);111 if (song != null) {112 var id = parseInt(song._id);113 if (req.params.sectionid >= 0 && req.params.sectionid < song.sections.length) {114 if ( req.body.hasOwnProperty('section') ) {115 song = chordpro.copyChords(song, req.body.section, req.params.sectionid);116 }117 song._id = req.params.id;118 songs[id] = song;119 }120 res.status(200).json(song);121 }122});...

Full Screen

Full Screen

script.js

Source:script.js Github

copy

Full Screen

...11const songs = ['hey', 'summer', 'ukulele'];12// Keep track of song13let songIndex = 2;14// Initially load song details into DOM15loadSong(songs[songIndex]);16// Update song details17function loadSong(song) {18 title.innerText = song;19 audio.src = `music/${song}.mp3`;20 cover.src = `images/${song}.jpg`;21}22// Play song23function playSong() {24 musicContainer.classList.add('play');25 playBtn.querySelector('i.fas').classList.remove('fa-play');26 playBtn.querySelector('i.fas').classList.add('fa-pause');27 audio.play();28}29// Pause song30function pauseSong() {31 musicContainer.classList.remove('play');32 playBtn.querySelector('i.fas').classList.add('fa-play');33 playBtn.querySelector('i.fas').classList.remove('fa-pause');34 audio.pause();35}36// Previous song37function prevSong() {38 songIndex--;39 if (songIndex < 0) {40 songIndex = songs.length - 1;41 }42 loadSong(songs[songIndex]);43 playSong();44}45// Next song46function nextSong() {47 songIndex++;48 if (songIndex > songs.length - 1) {49 songIndex = 0;50 }51 loadSong(songs[songIndex]);52 playSong();53}54// Update progress bar55function updateProgress(e) {56 const { duration, currentTime } = e.srcElement;57 const progressPercent = (currentTime / duration) * 100;58 progress.style.width = `${progressPercent}%`;59}60// Set progress bar61function setProgress(e) {62console.log(this);63 const width = this.clientWidth;64 console.log(width);65 console.log(this.width);66 const clickX = e.offsetX;67 const duration = audio.duration;68 audio.currentTime = (clickX / width) * duration;69}70// Event listeners71playBtn.addEventListener('click', () => {72 const isPlaying = musicContainer.classList.contains('play');73 if (isPlaying) {74 pauseSong();75 } else {76 playSong();77 }78});79// Change song80prevBtn.addEventListener('click', prevSong);81nextBtn.addEventListener('click', nextSong);82// Time/song update83audio.addEventListener('timeupdate', updateProgress);84// Click on progress bar85progressContainer.addEventListener('click', setProgress);86// Song ends...

Full Screen

Full Screen

SongContainer.js

Source:SongContainer.js Github

copy

Full Screen

1import React, { Component } from 'react';2import PropTypes from 'prop-types';3import { connect } from 'react-redux';4import Song from './Song';5import { isSongIdPlaying, getListenerCount } from './song.selector';6import { playSongId, pauseSongId } from './song.actions';7class SongContainer extends Component {8 static propTypes = {9 data: PropTypes.shape({10 id: PropTypes.string.isRequired,11 title: PropTypes.string.isRequired,12 singer: PropTypes.string.isRequired,13 art: PropTypes.string.isRequired,14 }).isRequired,15 isSongIdPlaying: PropTypes.func.isRequired,16 playSongId: PropTypes.func.isRequired,17 pauseSongId: PropTypes.func.isRequired,18 getListenerCount: PropTypes.func.isRequired,19 };20 constructor(props) {21 super(props);22 this.audio = new Audio();23 // setting preload to none as we don't want to pre-download all the songs on the page24 this.audio.preload = 'none';25 const url = `${process.env.REACT_APP_API_HOST}/song/${props.data.id}.mp3`;26 this.audio.src = url;27 // call pause when the audio ends28 this.audio.onended = this.onPlayPauseClick;29 }30 componentWillReceiveProps(nextProps) {31 const { data: song } = nextProps;32 const isPlaying = nextProps.isSongIdPlaying(song.id);33 if (isPlaying) this.audio.play();34 else this.audio.pause();35 }36 onPlayPauseClick = () => {37 const { data: song } = this.props;38 const isPlaying = this.props.isSongIdPlaying(song.id);39 if (isPlaying) this.props.pauseSongId(song.id);40 else this.props.playSongId(song.id);41 };42 render() {43 const { data: song } = this.props;44 const isPlaying = this.props.isSongIdPlaying(song.id);45 const listenerCount = this.props.getListenerCount(song.id);46 return <Song data={song} onClick={this.onPlayPauseClick} isPlaying={isPlaying} listenerCount={listenerCount} />;47 }48}49const mapStateToProps = state => ({50 isSongIdPlaying: isSongIdPlaying(state),51 getListenerCount: getListenerCount(state),52});53const mapDispatchToProps = {54 playSongId,55 pauseSongId,56};...

Full Screen

Full Screen

songinmem.js

Source:songinmem.js Github

copy

Full Screen

1var should = require('chai').should();2var Song = require('../lib/songinmem');3describe('#songinmem', function() {4 it("should save a song without error",function(done){5 var song = new Song({6 username:"guest",7 title: "title",8 artist: "artist",9 text: "{t:title}"10 })11 should.not.exist(song._id);12 song.save(function(err,theSong) {13 should.not.exist(err);14 should.exist(theSong._id);15 done();16 });17 });18 it("should find a saved song",function(done){19 var song = new Song({20 username:"guest2",21 title: "title2",22 artist: "artist2",23 text: "{t:title2}"24 })25 song.save(function(err,theSong) {26 should.exist(theSong._id);27 theSong.findById(theSong._id, function(err2, theSong2) {28 should.not.exist(err2);29 theSong2.title.should.equal("title2");30 done();31 });32 });33 });34 it("should return error finding an invalid id",function(done){35 var song = new Song({36 username:"",37 title: "",38 artist: "",39 text: ""40 })41 song.findById(267, function(err, song) {42 should.exist(err);43 done();44 });45 });46 it("should update a song",function(done){47 var song = new Song({48 username:"guest2",49 title: "title2",50 artist: "artist2",51 text: "{t:title2}"52 })53 song.save(function(err,theSong) {54 should.exist(theSong._id);55 theSong.findById(theSong._id, function(err2, theSong2) {56 should.not.exist(err2);57 theSong2.title.should.equal("title2");58 theSong2.title = "title3";59 theSong2.save(function(err,theSong) {60 should.exist(theSong._id);61 theSong.findById(theSong._id, function(err2, theSong2) {...

Full Screen

Full Screen

Library.jsx

Source:Library.jsx Github

copy

Full Screen

1import LibrarySong from "./LibrarySong";2const Library = ({libraryStatus, songs, setSongs, currentSong, setCurrentSong, audioRef, isPlaying}) => {3 //! States:4 //! Event Handlers:5 //! Render:6 return (7 <div className={`library ${libraryStatus ? `library-active mobile-active` : ``}`}>8 <h2>Library</h2>9 <ul>10 {songs.map((song) => (11 <LibrarySong 12 active={song.active} //? This is the active state of the song13 artist={song.artist} //? This is the artist of the song14 audioRef={audioRef} //? This is the audioRef of the song15 cover={song.cover} //? This is the cover of the song16 currentSong={currentSong} //? This is the current song that is being passed in17 setCurrentSong={setCurrentSong} //? This is the function to change the current song to something else18 id={song.id} //? This is the id of the song19 isPlaying={isPlaying} //? This is the isPlaying state of the song20 key={song.id.toString()} //? This is a unique key for each song that React requires21 name={song.name} //? This is the name of the song22 song={song} //? This is the individual song and their information23 songs={songs} //? This is the array of songs that is being passed in24 setSongs={setSongs} //? This is the function that is being passed in25 />26 ))}27 </ul>28 </div>29 )30}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("Song", function() {2 it("should be able to play a Song", function() {3 var song = new Song();4 song.play();5 expect(song.isPlaying).toBeTruthy();6 expect(song).toBePlaying();7 });8});9var Song = function() {10};11Song.prototype.play = function() {12 this.isPlaying = true;13};14Song.prototype.pause = function() {15 this.isPlaying = false;16};17Song.prototype.resume = function() {18 if (this.isPlaying) {19 throw new Error("song is already playing");20 }21 this.isPlaying = true;22};23beforeEach(function() {24 this.song = new Song();25});26afterEach(function() {27 this.song.stop();28});29describe("Song", function() {30 it("should be able to play a Song", function() {31 this.song.play();32 expect(this.song.isPlaying).toBeTruthy();33 });34 describe("when song has been paused", function() {35 beforeEach(function() {36 this.song.play();37 this.song.pause();38 });39 it("should indicate that the song is currently paused", function() {40 expect(this.song.isPlaying).toBeFalsy();41 expect(this.song).not.toBePlaying();42 });43 it("should be possible to resume", function() {44 this.song.resume();45 expect(this.song.isPlaying).toBeTruthy();46 expect(this.song).toBePlaying();47 });48 });49});50var Song = function() {51};52Song.prototype.play = function() {53 this.isPlaying = true;54};55Song.prototype.pause = function() {56 this.isPlaying = false;57};58Song.prototype.resume = function() {59 if (this.isPlaying) {60 throw new Error("song is already playing");61 }62 this.isPlaying = true;63};64beforeEach(function() {65 this.song = new Song();66});67afterEach(function() {68 this.song.stop();69});70describe("Song", function() {71 it("should be able to play a Song", function() {72 this.song.play();73 expect(this.song.isPlaying).toBeTruthy();74 });75 describe("when song has been paused", function() {76 beforeEach(function() {77 this.song.play();78 this.song.pause();79 });80 it("should indicate that the song

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("Song", function() {2 var song;3 beforeEach(function() {4 song = new Song();5 });6 it("should be able to play a Song", function() {7 song.play();8 expect(song.isPlaying).toBeTruthy();9 expect(song).toBePlaying();10 });11 describe("when song has been paused", function() {12 beforeEach(function() {13 song.play();14 song.pause();15 });16 it("should indicate that the song is currently paused", function() {17 expect(song.isPlaying).toBeFalsy();18 expect(song).not.toBePlaying();19 });20 it("should be possible to resume", function() {21 song.resume();22 expect(song.isPlaying).toBeTruthy();23 expect(song).toBePlaying();24 });25 });26 it("tells the current song if the user has made it a favorite", function() {27 spyOn(song, 'persistFavoriteStatus');28 song.favorite();29 expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true);30 });31 describe("#resume", function() {32 it("should throw an exception if song is already playing", function() {33 song.play();34 expect(function() {35 song.resume();36 }).toThrowError("song is already playing");37 });38 });39});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("Song", function() {2 var song;3 beforeEach(function() {4 song = new Song();5 });6 it("should be able to play a Song", function() {7 song.play();8 expect(song.isPlaying).toBeTruthy();9 expect(song).toBePlaying();10 });11 describe("when song has been paused", function() {12 beforeEach(function() {13 song.play();14 song.pause();15 });16 it("should indicate that the song is currently paused", function() {17 expect(song.isPlaying).toBeFalsy();18 expect(song).not.toBePlaying();19 });20 it("should be possible to resume", function() {21 song.resume();22 expect(song.isPlaying).toBeTruthy();23 expect(song).toBePlaying();24 });25 });26 it("tells the current song if the user has made it a favorite", function() {27 spyOn(song, 'persistFavoriteStatus');28 song.favorite();29 expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true);30 });31 describe("#resume", function() {32 it("should throw an exception if song is already playing", function() {33 song.play();34 expect(function() {35 song.resume();36 }).toThrowError("song is already playing");37 });38 });39});40function Song() {41}42Song.prototype.play = function() {43 this.isPlaying = true;44};45Song.prototype.pause = function() {46 this.isPlaying = false;47};48Song.prototype.resume = function() {49 if (this.isPlaying) {50 throw new Error("song is already playing");51 }52 this.isPlaying = true;53};54Song.prototype.favorite = function() {55 this.persistFavoriteStatus(true);56};57Song.prototype.persistFavoriteStatus = function(value) {58 throw new Error("not yet implemented");59};60Song.prototype.resume = function() {61 if (this.isPlaying) {62 throw new Error("song is already playing");63 }64 this.isPlaying = true;65};66Song.prototype.favorite = function() {67 this.persistFavoriteStatus(true);68};69Song.prototype.persistFavoriteStatus = function(value) {70 throw new Error("not yet implemented");71};

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("Song", function() {2 it("should be able to play a Song", function() {3 var song = new Song();4 song.play();5 expect(song).toBePlaying();6 });7});8describe("Song", function() {9 it("should be able to play a Song", function() {10 var song = new Song();11 song.play();12 expect(song).toBePlaying();13 });14});15describe("Song", function() {16 it("should be able to play a Song", function() {17 var song = new Song();18 song.play();19 expect(song).toBePlaying();20 });21});22describe("Song", function() {23 it("should be able to play a Song", function() {24 var song = new Song();25 song.play();26 expect(song).toBePlaying();27 });28});29describe("Song", function() {30 it("should be able to play a Song", function() {31 var song = new Song();32 song.play();33 expect(song).toBePlaying();34 });35});36describe("Song", function() {37 it("should be able to play a Song", function() {38 var song = new Song();39 song.play();40 expect(song).toBePlaying();41 });42});43describe("Song", function() {44 it("should be able to play a Song", function() {45 var song = new Song();46 song.play();47 expect(song).toBePlaying();48 });49});50describe("Song", function() {51 it("should be able to play a Song", function() {52 var song = new Song();53 song.play();54 expect(song).toBePlaying();55 });56});57describe("Song", function() {58 it("should be able to play a Song", function() {59 var song = new Song();60 song.play();61 expect(song).toBePlaying();62 });63});64describe("Song", function() {

Full Screen

Using AI Code Generation

copy

Full Screen

1var Jasmine = require('jasmine');2var jasmine = new Jasmine();3jasmine.loadConfigFile('spec/support/jasmine.json');4jasmine.execute();5{6}7describe("A suite", function() {8 it("contains spec with an expectation", function() {9 expect(true).toBe(true);10 });11});12exports.helper = function() {13 return true;14};

Full Screen

Using AI Code Generation

copy

Full Screen

1var Song = require('../js/song.js');2var song;3beforeEach(function(){4 song = new Song();5});6describe('Song', function(){7 it('should be able to play a Song', function(){8 song.play();9 expect(song.isPlaying).toBe(true);10 });11 it('should be able to pause a Song', function(){12 song.play();13 song.pause();14 expect(song.isPlaying).toBe(false);15 });16});17function Song(){18 this.isPlaying = false;19}20Song.prototype.play = function(){21 this.isPlaying = true;22};23Song.prototype.pause = function(){24 this.isPlaying = false;25};

Full Screen

Using AI Code Generation

copy

Full Screen

1var Song = require('../src/song');2var song;3describe("Song", function() {4 beforeEach(function() {5 song = new Song();6 });7 it("should be able to play a Song", function() {8 song.play();9 expect(song.isPlaying).toBeTruthy();10 expect(song).toBePlaying();11 });12 it("should not be playing a song", function() {13 expect(song.isPlaying).toBeFalsy();14 expect(song).not.toBePlaying();15 });16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var Song = require('./song.js');2var song = new Song();3describe('Song', function() {4 it('should be able to play a Song', function() {5 expect(song.play()).toEqual('Playing: The Less I Know The Better');6 });7});8describe('Song', function() {9 it('should be able to pause a Song', function() {10 expect(song.pause()).toEqual('Pausing: The Less I Know The Better');11 });12});13describe('Song', function() {14 it('should be able to resume a Song', function() {15 expect(song.resume()).toEqual('Resuming: The Less I Know The Better');16 });17});18describe('Song', function() {19 it('should be able to stop a Song', function() {20 expect(song.stop()).toEqual('Stopping: The Less I Know The Better');21 });22});23var Song = function() {24 this.name = 'The Less I Know The Better';25 this.playing = false;26 this.paused = false;27 this.stopped = false;28 this.resume = false;29};30Song.prototype.play = function() {31 this.playing = true;32 this.paused = false;33 this.stopped = false;34 this.resume = false;35 return 'Playing: ' + this.name;36};37Song.prototype.pause = function() {38 if (this.playing) {39 this.paused = true;40 this.playing = false;41 this.resume = false;42 return 'Pausing: ' + this.name;43 }44};45Song.prototype.resume = function() {46 if (this.paused) {47 this.resume = true;48 this.paused = false;49 this.playing = true;50 return 'Resuming: ' + this.name;51 }52};53Song.prototype.stop = function() {54 this.stopped = true;55 this.playing = false;56 this.paused = false;57 this.resume = false;58 return 'Stopping: ' + this.name;59};60module.exports = Song;61at Object.<anonymous> (test.js:4:

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Jasmine-core automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful