How to use storyId method in storybook-root

Best JavaScript code snippet using storybook-root

20220513195551-likes.js

Source:20220513195551-likes.js Github

copy

Full Screen

1'use strict';2module.exports = {3 up: (queryInterface, Sequelize) => {4 return queryInterface.bulkInsert('Likes', [5 {6 userId: 2,7 storyId: 1,8 createdAt: new Date(),9 updatedAt: new Date()10 },11 {12 userId: 2,13 storyId: 2,14 createdAt: new Date(),15 updatedAt: new Date()16 },17 {18 userId: 2,19 storyId: 3,20 createdAt: new Date(),21 updatedAt: new Date()22 },23 {24 userId: 2,25 storyId: 4,26 createdAt: new Date(),27 updatedAt: new Date()28 },29 {30 userId: 2,31 storyId: 5,32 createdAt: new Date(),33 updatedAt: new Date()34 },35 {36 userId: 3,37 storyId: 1,38 createdAt: new Date(),39 updatedAt: new Date()40 },41 {42 userId: 3,43 storyId: 2,44 createdAt: new Date(),45 updatedAt: new Date()46 },47 {48 userId: 3,49 storyId: 3,50 createdAt: new Date(),51 updatedAt: new Date()52 },53 {54 userId: 3,55 storyId: 4,56 createdAt: new Date(),57 updatedAt: new Date()58 },59 {60 userId: 3,61 storyId: 5,62 createdAt: new Date(),63 updatedAt: new Date()64 },65 {66 userId: 4,67 storyId: 1,68 createdAt: new Date(),69 updatedAt: new Date()70 },71 {72 userId: 4,73 storyId: 2,74 createdAt: new Date(),75 updatedAt: new Date()76 },77 {78 userId: 4,79 storyId: 3,80 createdAt: new Date(),81 updatedAt: new Date()82 },83 {84 userId: 4,85 storyId: 4,86 createdAt: new Date(),87 updatedAt: new Date()88 },89 {90 userId: 4,91 storyId: 5,92 createdAt: new Date(),93 updatedAt: new Date()94 },95 {96 userId: 5,97 storyId: 1,98 createdAt: new Date(),99 updatedAt: new Date()100 },101 {102 userId: 5,103 storyId: 2,104 createdAt: new Date(),105 updatedAt: new Date()106 },107 {108 userId: 5,109 storyId: 3,110 createdAt: new Date(),111 updatedAt: new Date()112 },113 {114 userId: 5,115 storyId: 4,116 createdAt: new Date(),117 updatedAt: new Date()118 },119 {120 userId: 5,121 storyId: 5,122 createdAt: new Date(),123 updatedAt: new Date()124 },125 {126 userId: 6,127 storyId: 2,128 createdAt: new Date(),129 updatedAt: new Date()130 },131 {132 userId: 6,133 storyId: 3,134 createdAt: new Date(),135 updatedAt: new Date()136 },137 {138 userId: 6,139 storyId: 4,140 createdAt: new Date(),141 updatedAt: new Date()142 },143 {144 userId: 6,145 storyId: 5,146 createdAt: new Date(),147 updatedAt: new Date()148 },149 {150 userId: 7,151 storyId: 2,152 createdAt: new Date(),153 updatedAt: new Date()154 },155 {156 userId: 7,157 storyId: 3,158 createdAt: new Date(),159 updatedAt: new Date()160 },161 {162 userId: 7,163 storyId: 4,164 createdAt: new Date(),165 updatedAt: new Date()166 },167 {168 userId: 7,169 storyId: 5,170 createdAt: new Date(),171 updatedAt: new Date()172 },173 {174 userId: 8,175 storyId: 2,176 createdAt: new Date(),177 updatedAt: new Date()178 },179 {180 userId: 8,181 storyId: 3,182 createdAt: new Date(),183 updatedAt: new Date()184 },185 {186 userId: 8,187 storyId: 4,188 createdAt: new Date(),189 updatedAt: new Date()190 },191 {192 userId: 8,193 storyId: 5,194 createdAt: new Date(),195 updatedAt: new Date()196 },197 {198 userId: 9,199 storyId: 2,200 createdAt: new Date(),201 updatedAt: new Date()202 },203 {204 userId: 9,205 storyId: 3,206 createdAt: new Date(),207 updatedAt: new Date()208 },209 {210 userId: 9,211 storyId: 4,212 createdAt: new Date(),213 updatedAt: new Date()214 },215 {216 userId: 9,217 storyId: 5,218 createdAt: new Date(),219 updatedAt: new Date()220 },221 {222 userId: 10,223 storyId: 3,224 createdAt: new Date(),225 updatedAt: new Date()226 },227 {228 userId: 10,229 storyId: 4,230 createdAt: new Date(),231 updatedAt: new Date()232 },233 {234 userId: 10,235 storyId: 5,236 createdAt: new Date(),237 updatedAt: new Date()238 },239 {240 userId: 10,241 storyId: 1,242 createdAt: new Date(),243 updatedAt: new Date()244 },245 {246 userId: 11,247 storyId: 3,248 createdAt: new Date(),249 updatedAt: new Date()250 },251 {252 userId: 11,253 storyId: 4,254 createdAt: new Date(),255 updatedAt: new Date()256 },257 {258 userId: 11,259 storyId: 5,260 createdAt: new Date(),261 updatedAt: new Date()262 },263 {264 userId: 12,265 storyId: 3,266 createdAt: new Date(),267 updatedAt: new Date()268 },269 {270 userId: 12,271 storyId: 4,272 createdAt: new Date(),273 updatedAt: new Date()274 },275 {276 userId: 12,277 storyId: 5,278 createdAt: new Date(),279 updatedAt: new Date()280 },281 {282 userId: 13,283 storyId: 3,284 createdAt: new Date(),285 updatedAt: new Date()286 },287 {288 userId: 13,289 storyId: 4,290 createdAt: new Date(),291 updatedAt: new Date()292 },293 {294 userId: 13,295 storyId: 5,296 createdAt: new Date(),297 updatedAt: new Date()298 },299 {300 userId: 14,301 storyId: 3,302 createdAt: new Date(),303 updatedAt: new Date()304 },305 {306 userId: 14,307 storyId: 4,308 createdAt: new Date(),309 updatedAt: new Date()310 },311 {312 userId: 14,313 storyId: 5,314 createdAt: new Date(),315 updatedAt: new Date()316 },317 {318 userId: 15,319 storyId: 3,320 createdAt: new Date(),321 updatedAt: new Date()322 },323 {324 userId: 15,325 storyId: 2,326 createdAt: new Date(),327 updatedAt: new Date()328 },329 {330 userId: 16,331 storyId: 1,332 createdAt: new Date(),333 updatedAt: new Date()334 },335 {336 userId: 16,337 storyId: 3,338 createdAt: new Date(),339 updatedAt: new Date()340 },341 {342 userId: 16,343 storyId: 4,344 createdAt: new Date(),345 updatedAt: new Date()346 },347 {348 userId: 17,349 storyId: 3,350 createdAt: new Date(),351 updatedAt: new Date()352 },353 {354 userId: 17,355 storyId: 5,356 createdAt: new Date(),357 updatedAt: new Date()358 },359 {360 userId: 18,361 storyId: 3,362 createdAt: new Date(),363 updatedAt: new Date()364 },365 {366 userId: 18,367 storyId: 2,368 createdAt: new Date(),369 updatedAt: new Date()370 },371 {372 userId: 19,373 storyId: 3,374 createdAt: new Date(),375 updatedAt: new Date()376 },377 {378 userId: 19,379 storyId: 4,380 createdAt: new Date(),381 updatedAt: new Date()382 },383 {384 userId: 20,385 storyId: 3,386 createdAt: new Date(),387 updatedAt: new Date()388 },389 {390 userId: 20,391 storyId: 1,392 createdAt: new Date(),393 updatedAt: new Date()394 },395 {396 userId: 21,397 storyId: 3,398 createdAt: new Date(),399 updatedAt: new Date()400 },401 {402 userId: 21,403 storyId: 1,404 createdAt: new Date(),405 updatedAt: new Date()406 },407 {408 userId: 21,409 storyId: 10,410 createdAt: new Date(),411 updatedAt: new Date()412 },413 {414 userId: 21,415 storyId: 9,416 createdAt: new Date(),417 updatedAt: new Date()418 },419 {420 userId: 21,421 storyId: 8,422 createdAt: new Date(),423 updatedAt: new Date()424 },425 {426 userId: 21,427 storyId: 7,428 createdAt: new Date(),429 updatedAt: new Date()430 },431 {432 userId: 21,433 storyId: 6,434 createdAt: new Date(),435 updatedAt: new Date()436 },437 {438 userId: 20,439 storyId: 10,440 createdAt: new Date(),441 updatedAt: new Date()442 },443 {444 userId: 20,445 storyId: 9,446 createdAt: new Date(),447 updatedAt: new Date()448 },449 {450 userId: 20,451 storyId: 8,452 createdAt: new Date(),453 updatedAt: new Date()454 },455 {456 userId: 20,457 storyId: 7,458 createdAt: new Date(),459 updatedAt: new Date()460 },461 {462 userId: 20,463 storyId: 6,464 createdAt: new Date(),465 updatedAt: new Date()466 },467 {468 userId: 19,469 storyId: 10,470 createdAt: new Date(),471 updatedAt: new Date()472 },473 {474 userId: 19,475 storyId: 9,476 createdAt: new Date(),477 updatedAt: new Date()478 },479 {480 userId: 19,481 storyId: 8,482 createdAt: new Date(),483 updatedAt: new Date()484 },485 {486 userId: 19,487 storyId: 7,488 createdAt: new Date(),489 updatedAt: new Date()490 },491 {492 userId: 19,493 storyId: 6,494 createdAt: new Date(),495 updatedAt: new Date()496 },497 {498 userId: 18,499 storyId: 10,500 createdAt: new Date(),501 updatedAt: new Date()502 },503 {504 userId: 18,505 storyId: 9,506 createdAt: new Date(),507 updatedAt: new Date()508 },509 {510 userId: 18,511 storyId: 7,512 createdAt: new Date(),513 updatedAt: new Date()514 },515 {516 userId: 18,517 storyId: 8,518 createdAt: new Date(),519 updatedAt: new Date()520 },521 {522 userId: 18,523 storyId: 6,524 createdAt: new Date(),525 updatedAt: new Date()526 },527 {528 userId: 17,529 storyId: 10,530 createdAt: new Date(),531 updatedAt: new Date()532 },533 {534 userId: 17,535 storyId: 8,536 createdAt: new Date(),537 updatedAt: new Date()538 },539 {540 userId: 17,541 storyId: 7,542 createdAt: new Date(),543 updatedAt: new Date()544 },545 {546 userId: 17,547 storyId: 6,548 createdAt: new Date(),549 updatedAt: new Date()550 },551 {552 userId: 17,553 storyId: 9,554 createdAt: new Date(),555 updatedAt: new Date()556 },557 {558 userId: 16,559 storyId: 9,560 createdAt: new Date(),561 updatedAt: new Date()562 },563 {564 userId: 16,565 storyId: 10,566 createdAt: new Date(),567 updatedAt: new Date()568 },569 {570 userId: 16,571 storyId: 8,572 createdAt: new Date(),573 updatedAt: new Date()574 },575 {576 userId: 16,577 storyId: 7,578 createdAt: new Date(),579 updatedAt: new Date()580 },581 {582 userId: 16,583 storyId: 6,584 createdAt: new Date(),585 updatedAt: new Date()586 },587 {588 userId: 15,589 storyId: 8,590 createdAt: new Date(),591 updatedAt: new Date()592 },593 {594 userId: 15,595 storyId: 10,596 createdAt: new Date(),597 updatedAt: new Date()598 },599 {600 userId: 15,601 storyId: 9,602 createdAt: new Date(),603 updatedAt: new Date()604 },605 {606 userId: 15,607 storyId: 7,608 createdAt: new Date(),609 updatedAt: new Date()610 },611 {612 userId: 15,613 storyId: 6,614 createdAt: new Date(),615 updatedAt: new Date()616 },617 {618 userId: 14,619 storyId: 8,620 createdAt: new Date(),621 updatedAt: new Date()622 },623 {624 userId: 14,625 storyId: 7,626 createdAt: new Date(),627 updatedAt: new Date()628 },629 {630 userId: 14,631 storyId: 6,632 createdAt: new Date(),633 updatedAt: new Date()634 },635 {636 userId: 14,637 storyId: 9,638 createdAt: new Date(),639 updatedAt: new Date()640 },641 {642 userId: 14,643 storyId: 10,644 createdAt: new Date(),645 updatedAt: new Date()646 },647 {648 userId: 13,649 storyId: 10,650 createdAt: new Date(),651 updatedAt: new Date()652 },653 {654 userId: 12,655 storyId: 10,656 createdAt: new Date(),657 updatedAt: new Date()658 },659 {660 userId: 12,661 storyId: 9,662 createdAt: new Date(),663 updatedAt: new Date()664 },665 {666 userId: 13,667 storyId: 8,668 createdAt: new Date(),669 updatedAt: new Date()670 },671 {672 userId: 11,673 storyId: 10,674 createdAt: new Date(),675 updatedAt: new Date()676 }677 ], {});678 },679 down: (queryInterface, Sequelize) => {680 return queryInterface.bulkDelete('Likes', null, {});681 }...

Full Screen

Full Screen

models.js

Source:models.js Github

copy

Full Screen

1"use strict";2const BASE_URL = "https://hack-or-snooze-v3.herokuapp.com";3/******************************************************************************4 * Story: a single story in the system5 */6class Story {7 /** Make instance of Story from data object about story:8 * - {title, author, url, username, storyId, createdAt}9 */10 constructor({ storyId, title, author, url, username, createdAt }) {11 this.storyId = storyId;12 this.title = title;13 this.author = author;14 this.url = url;15 this.username = username;16 this.createdAt = createdAt;17 }18 /** Parses hostname out of URL and returns it. */19 getHostName() {20 // UNIMPLEMENTED: complete this function!21 return new URL(this.url).host;22 }23}24/******************************************************************************25 * List of Story instances: used by UI to show story lists in DOM.26 */27class StoryList {28 constructor(stories) {29 this.stories = stories;30 }31 /** Generate a new StoryList. It:32 *33 * - calls the API34 * - builds an array of Story instances35 * - makes a single StoryList instance out of that36 * - returns the StoryList instance.37 */38 static async getStories() {39 // Note presence of `static` keyword: this indicates that getStories is40 // **not** an instance method. Rather, it is a method that is called on the41 // class directly. Why doesn't it make sense for getStories to be an42 // instance method?43 // query the /stories endpoint (no auth required)44 const response = await axios({45 url: `${BASE_URL}/stories`,46 method: "GET",47 });48 // turn plain old story objects from API into instances of Story class49 const stories = response.data.stories.map(story => new Story(story));50 // build an instance of our own class using the new array of stories51 return new StoryList(stories);52 }53 /** Adds story data to API, makes a Story instance, adds it to story list.54 * - user - the current instance of User who will post the story55 * - obj of {title, author, url}56 *57 * Returns the new Story instance58 */59 async addStory(user, { title, author, url }) {60 const token = user.loginToken;61 const response = await axios({62 method: "POST",63 url: `${BASE_URL}/stories`,64 data: { token, story: { title, author, url } },65 });66 const story = new Story(response.data.story);67 this.stories.unshift(story);68 user.ownStories.unshift(story);69 return story;70 }71 72 //ToDo:73 async editStory(user, { storyId, title, author, url }) {74 const token = user.loginToken;75 //alert("storyId " + storyId + " title " + title + "author " + author + " url " + url);76 try{77 const response = await axios({78 method: "PATCH",79 url: `${BASE_URL}/stories/${storyId}`,80 data: { token, story: { title, author, url } },81 });82 } catch(error){83 alert("Error in update " + error);84 }85 //Update StoryList86 let response;87 try{88 response = await axios({89 url: `${BASE_URL}/stories/${storyId}`,90 method: "GET",91 });92 } catch(error){93 alert(error);94 }95 96 // turn plain old story objects from API into instances of Story class97 //const stories = response.story.map(storyItem => new Story(storyItem));98 let content = response.data;99 storyId = content.story.storyId;100 author = content.story.author;101 url = content.story.url;102 let username = content.story.username;103 let createdAt = content.story.createdAt;104 let updatedStory = new Story({storyId, title, author, url, username, createdAt});105 106 // filter out the story we are updating first remove the story107 this.stories = this.stories.filter(story => story.storyId !== storyId);108 this.stories.push(updatedStory);109 // do the same thing for the user's list of stories & their favorites110 user.ownStories = user.ownStories.filter(s => s.storyId !== storyId);111 user.ownStories.push(updatedStory);112 if( user.favorites.some(s => (s.storyId === storyId))){113 user.favorites = user.favorites.filter(s => s.storyId !== storyId);114 user.favorites.push(updatedStory);115 }116 }117 /** Delete story from API and remove from the story lists.118 *119 * - user: the current User instance120 * - storyId: the ID of the story you want to remove121 */122 async removeStory(user, storyId) {123 const token = user.loginToken;124 await axios({125 url: `${BASE_URL}/stories/${storyId}`,126 method: "DELETE",127 data: { token: user.loginToken }128 });129 // filter out the story whose ID we are removing130 this.stories = this.stories.filter(story => story.storyId !== storyId);131 // do the same thing for the user's list of stories & their favorites132 user.ownStories = user.ownStories.filter(s => s.storyId !== storyId);133 user.favorites = user.favorites.filter(s => s.storyId !== storyId);134 }135}//StoryList136/******************************************************************************137 * User: a user in the system (only used to represent the current user)138 */139class User {140 /** Make user instance from obj of user data and a token:141 * - {username, name, createdAt, favorites[], ownStories[]}142 * - token143 */144 constructor({145 username,146 name,147 createdAt,148 favorites = [],149 ownStories = []150 },151 token) {152 this.username = username;153 this.name = name;154 this.createdAt = createdAt;155 // instantiate Story instances for the user's favorites and ownStories156 this.favorites = favorites.map(s => new Story(s));157 this.ownStories = ownStories.map(s => new Story(s));158 // store the login token on the user so it's easy to find for API calls.159 this.loginToken = token;160 }161 /** Register new user in API, make User instance & return it.162 *163 * - username: a new username164 * - password: a new password165 * - name: the user's full name166 */167 static async signup(username, password, name) {168 const response = await axios({169 url: `${BASE_URL}/signup`,170 method: "POST",171 data: { user: { username, password, name } },172 });173 let { user } = response.data174 return new User(175 {176 username: user.username,177 name: user.name,178 createdAt: user.createdAt,179 favorites: user.favorites,180 ownStories: user.stories181 },182 response.data.token183 );184 }185 /** Login in user with API, make User instance & return it.186 * - username: an existing user's username187 * - password: an existing user's password188 */189 static async login(username, password) {190 const response = await axios({191 url: `${BASE_URL}/login`,192 method: "POST",193 data: { user: { username, password } },194 });195 let { user } = response.data;196 return new User(197 {198 username: user.username,199 name: user.name,200 createdAt: user.createdAt,201 favorites: user.favorites,202 ownStories: user.stories203 },204 response.data.token205 );206 }207 /** ChangeProfile in user with API, make User instance & return it.208 * - username: an existing user's username209 * - password: an existing user's password210 */211 static async changeUserProfile(password) {212 const username = currentUser.username;213 const token = currentUser.loginToken;214 215 console.log("c_username " + username);216 console.log("token " + token );217 console.log("new password" + password);218 let updated = false219 try{220 let response = await axios({221 method: "PATCH",222 url: `${BASE_URL}/users/${username}`,223 data: { token, user: { username, password } },224 });225 let content = response.data;226 let testUser = content.user.username;227 let tUser = content.user.name;228 updated = true;229 //alert("after update " + testUser);230 231 } catch(error){232 alert("Error in update " + error);233 }234 return updated;235 236 }237 /** When we already have credentials (token & username) for a user,238 * we can log them in automatically. This function does that.239 */240 static async loginViaStoredCredentials(token, username) {241 try {242 const response = await axios({243 url: `${BASE_URL}/users/${username}`,244 method: "GET",245 params: { token },246 });247 let { user } = response.data;248 return new User(249 {250 username: user.username,251 name: user.name,252 createdAt: user.createdAt,253 favorites: user.favorites,254 ownStories: user.stories255 },256 token257 );258 } catch (err) {259 console.error("loginViaStoredCredentials failed", err);260 return null;261 }262 }263 /** Add a story to the list of user favorites and update the API264 * - story: a Story instance to add to favorites265 */266 async addFavorite(story) {267 this.favorites.push(story);268 await this._addOrRemoveFavorite("add", story)269 }270 /** Remove a story to the list of user favorites and update the API271 * - story: the Story instance to remove from favorites272 */273 async removeFavorite(story) {274 this.favorites = this.favorites.filter(s => s.storyId !== story.storyId);275 await this._addOrRemoveFavorite("remove", story);276 }277 /** Update API with favorite/not-favorite.278 * - newState: "add" or "remove"279 * - story: Story instance to make favorite / not favorite280 * */281 async _addOrRemoveFavorite(newState, story) {282 const method = newState === "add" ? "POST" : "DELETE";283 const token = this.loginToken;284 await axios({285 url: `${BASE_URL}/users/${this.username}/favorites/${story.storyId}`,286 method: method,287 data: { token },288 });289 }290 /** Return true/false if given Story instance is a favorite of this user. */291 isFavorite(story) {292 return this.favorites.some(s => (s.storyId === story.storyId));293 }...

Full Screen

Full Screen

ratings.js

Source:ratings.js Github

copy

Full Screen

1function loadRatingData(localRating) {2 var lastRatingUpdate = localStorage.getItem('lastRatingUpdate');3 if (lastRatingUpdate !== undefined) {4 if (localRating.rating_date <= lastRatingUpdate ) {5 addRatingToResults(localRating);6 return;7 }8 }9 var input = JSON.stringify(localRating);10 ajaxRequest('/rating_data', input, "application/json", "POST");11}12function getAverageRating(storyId) {13 var total = 0;14 var ratingCounter = 0;15 var localRatings = JSON.parse(localStorage.getItem('ratings'));16 for (var ratingItem in localRatings) {17 if (localRatings.hasOwnProperty(ratingItem)) {18 var ratingObject = localRatings[ratingItem];19 if (ratingObject.story_id === storyId) {20 ratingCounter += 1;21 total += ratingObject.vote;22 }23 }24 }25 var average = total/ratingCounter;26 if (isNaN(average)) average= 0;27 return average;28}29function handleRatingChange(n, storyId) {30 storyId = storyId.id;31 var username = document.cookie.split("=")[1]32 var ratingDate = Date.now();33 var ratingItem = {rating_id: storyId + username ,34 story_id: storyId, username: username,35 vote: n, rating_date: ratingDate}36 var ratingList = JSON.parse(localStorage.getItem('ratings'));37 if (ratingList == null) ratingList = [];38 ratingList.push(ratingItem);39 // find any duplicates40 var previousRating = ratingList.find(function (item) {41 return item.story_id === storyId &&42 item.username === username &&43 item.rating_date !== ratingDate;44 });45 // delete the previous rating from ratingList46 if (ratingList.indexOf(previousRating) > -1){47 ratingList.splice(ratingList.indexOf(previousRating), 1)48 }49 // delete rating50 if (ratingItem.vote === 0) {51 ratingList = ratingList.filter(function(elem) {52 return elem.rating_id !== ratingItem.rating_id;53 });54 }55 localStorage.setItem('ratings', JSON.stringify(ratingList));56 // store it in local storage57 storeRatingData(ratingItem);58 $('#'+"averageRating"+storyId).text("Average Rating: " + getAverageRating(storyId));59 addRatingToResults(ratingItem);60 ratingItem.vote_date = ratingItem.rating_date;61 delete ratingItem.rating_date;62 ajaxRequest('/rating_data', JSON.stringify(ratingItem), 'application/json', "POST" )63}64function addRatingToResults(ratingObject) {65 var storyId = ratingObject.story_id;66 var n = ratingObject.vote;67 var undoRatingButton = $('#' + "undoRatingButton" + storyId);68 var storyCard = $('#' + storyId);69 if (ratingObject.vote === 0) {70 undoRatingButton.hide()71 for (var k = 0; k<5; k++) {72 storyCard.find($('#' + 'star' + (k+1) + storyId)).attr('class', 'fa fa-star-o')73 }74 return;75 }76 undoRatingButton.show();77 // change UI of stars78 for (var i = 0; i <= n; i++) {79 var storyStar = storyCard.find($('#' + 'star' + (i) + storyId))80 storyStar.attr('class', 'fa fa-star')81 }82 for (var j = n; j < 5; j++) {83 var nextStoryStar = storyCard.find($('#' + 'star' + (j+1) + storyId))84 nextStoryStar.attr("class", 'fa fa-star-o');85 }86}87if (document.cookie) {88 socket.on('refreshRatings', function (ratingInput) {89 var ratingObj = JSON.parse(JSON.parse(ratingInput));90 ratingObj.rating_id = ratingObj.story_id + ratingObj.username91 delete ratingObj._id;92 var ratingDate = (new Date(ratingObj.vote_date).getTime());93 console.log(ratingDate);94 ratingObj.rating_date = ratingDate;95 delete ratingObj.vote_date;96 console.log("Rating input obj:", ratingObj);97 var ratingList = JSON.parse(localStorage.getItem('ratings'));98 if (ratingList == null) ratingList = [];99 // find any duplicates100 var previousRating = ratingList.find(function (item) {101 return item.rating_id === ratingObj.rating_id;102 });103 // delete the previous rating from ratingList104 if (ratingList.indexOf(previousRating) > -1) {105 ratingList.splice(ratingList.indexOf(previousRating), 1)106 }107 ratingList.push(ratingObj);108 // delete rating109 if (ratingObj.vote === 0) {110 ratingList = ratingList.filter(function (elem) {111 return elem.rating_id !== ratingObj.rating_id;112 });113 }114 localStorage.setItem('ratings', JSON.stringify(ratingList));115 // store it in local storage116 storeRatingData(ratingObj);117 $('#' + "averageRating" + ratingObj.story_id).text("Average Rating: " + getAverageRating(ratingObj.story_id));118 var loggedInUser = document.cookie.split("=")[1]119 if (loggedInUser === ratingObj.username) {120 addRatingToResults(ratingObj);121 }122 })...

Full Screen

Full Screen

20220512163056-comments.js

Source:20220512163056-comments.js Github

copy

Full Screen

1'use strict';2module.exports = {3 up: (queryInterface, Sequelize) => {4 return queryInterface.bulkInsert('Comments', [5 {6 content: 'Great Review!',7 userId: 2,8 storyId: 1,9 createdAt: new Date(),10 updatedAt: new Date()11 },12 {13 content: "I'll take notes",14 userId: 3,15 storyId: 1,16 createdAt: new Date(),17 updatedAt: new Date()18 },19 {20 content: 'I like marvel better but nice review',21 userId: 3,22 storyId: 2,23 createdAt: new Date(),24 updatedAt: new Date()25 },26 {27 content: 'Best movie ever',28 userId: 3,29 storyId: 3,30 createdAt: new Date(),31 updatedAt: new Date()32 },33 {34 content: 'That movie was a masterpiece',35 userId: 4,36 storyId: 5,37 createdAt: new Date(),38 updatedAt: new Date()39 },40 {41 content: "I'm not a big fan of this movie",42 userId: 5,43 storyId: 5,44 createdAt: new Date(),45 updatedAt: new Date()46 },47 {48 content: 'They should make more movies like this one',49 userId: 4,50 storyId: 2,51 createdAt: new Date(),52 updatedAt: new Date()53 },54 {55 content: 'Not just a great movie but they also had a great actor',56 userId: 5,57 storyId: 4,58 createdAt: new Date(),59 updatedAt: new Date()60 },61 {62 content: 'Nicolas Cage is overrated',63 userId: 2,64 storyId: 4,65 createdAt: new Date(),66 updatedAt: new Date()67 },68 {69 content: 'Appealing work you have here.',70 userId: 11,71 storyId: 6,72 createdAt: new Date(),73 updatedAt: new Date()74 },75 {76 content: 'Just exquisite!',77 userId: 12,78 storyId: 7,79 createdAt: new Date(),80 updatedAt: new Date()81 },82 {83 content: `I think I'm crying. It's that nice.`,84 userId: 13,85 storyId: 7,86 createdAt: new Date(),87 updatedAt: new Date()88 },89 {90 content: 'Outstandingly simple illustration.',91 userId: 14,92 storyId: 7,93 createdAt: new Date(),94 updatedAt: new Date()95 },96 {97 content: 'This is appealing work, friend.',98 userId: 15,99 storyId: 8,100 createdAt: new Date(),101 updatedAt: new Date()102 },103 {104 content: 'So fabulous and neat!!',105 userId: 16,106 storyId: 8,107 createdAt: new Date(),108 updatedAt: new Date()109 },110 {111 content: 'Really thought out! Yes yes yes yes yes yes.',112 userId: 17,113 storyId: 9,114 createdAt: new Date(),115 updatedAt: new Date()116 },117 {118 content: 'Nice work you have here.',119 userId: 18,120 storyId: 10,121 createdAt: new Date(),122 updatedAt: new Date()123 },124 {125 content: 'This review has navigated straight to my heart',126 userId: 19,127 storyId: 10,128 createdAt: new Date(),129 updatedAt: new Date()130 },131 {132 content: 'Whoa.',133 userId: 20,134 storyId: 10,135 createdAt: new Date(),136 updatedAt: new Date()137 }138 ], {});139 },140 down: (queryInterface, Sequelize) => {141 return queryInterface.bulkDelete('Comments', null, {});142 }...

Full Screen

Full Screen

20211214180809-likeSeeds.js

Source:20211214180809-likeSeeds.js Github

copy

Full Screen

1"use strict";2module.exports = {3 up: (queryInterface, Sequelize) => {4 return queryInterface.bulkInsert(5 "Likes",6 [7 {8 storyId: 1,9 commentId: null,10 userId: 11,11 createdAt: new Date(),12 updatedAt: new Date(),13 },14 {15 storyId: 2,16 commentId: null,17 userId: 11,18 createdAt: new Date(),19 updatedAt: new Date(),20 },21 {22 storyId: 4,23 commentId: null,24 userId: 11,25 createdAt: new Date(),26 updatedAt: new Date(),27 },28 {29 storyId: 3,30 commentId: null,31 userId: 11,32 createdAt: new Date(),33 updatedAt: new Date(),34 },35 {36 storyId: 5,37 commentId: null,38 userId: 11,39 createdAt: new Date(),40 updatedAt: new Date(),41 },42 {43 storyId: 5,44 commentId: null,45 userId: 2,46 createdAt: new Date(),47 updatedAt: new Date(),48 },49 {50 storyId: 5,51 commentId: null,52 userId: 3,53 createdAt: new Date(),54 updatedAt: new Date(),55 },56 {57 storyId: 5,58 commentId: null,59 userId: 4,60 createdAt: new Date(),61 updatedAt: new Date(),62 },63 {64 storyId: 3,65 commentId: null,66 userId: 5,67 createdAt: new Date(),68 updatedAt: new Date(),69 },70 {71 storyId: 3,72 commentId: null,73 userId: 4,74 createdAt: new Date(),75 updatedAt: new Date(),76 },77 {78 storyId: 2,79 commentId: null,80 userId: 3,81 createdAt: new Date(),82 updatedAt: new Date(),83 },84 ],85 {}86 );87 },88 down: (queryInterface, Sequelize) => {89 return queryInterface.bulkDelete("Likes", null, {});90 },...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storyId } from 'storybook-root';2import { storyId } from 'storybook-root';3import { storyId } from 'storybook-root';4import { storyId } from 'storybook-root';5import { storyId } from 'storybook-root';6import { storyId } from 'storybook-root';7import { storyId } from 'storybook-root';8import { storyId } from 'storybook-root';9import { storyId } from 'storybook-root';10import { storyId } from 'storybook-root';11import { storyId } from 'storybook-root';12import { storyId } from 'storybook-root';13import { storyId } from 'storybook-root';14import { storyId } from 'storybook-root';15import { storyId } from 'storybook-root';16import { storyId } from 'storybook-root';17import { storyId } from 'storybook-root';18import { storyId } from 'storybook-root';19import { storyId } from 'storybook-root';20import { storyId } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storiesOf } from '@storybook/react';2import { withInfo } from '@storybook/addon-info';3import { withKnobs, text, boolean, number } from '@storybook/addon-knobs/react';4import { withReadme, withDocs } from 'storybook-readme';5import { action } from '@storybook/addon-actions';6import { withA11y } from '@storybook/addon-a11y';7import { withViewport } from '@storybook/addon-viewport';8import { withTests } from '@storybook/addon-jest';9import { withConsole } from '@storybook/addon-console';10import { withOptions } from '@storybook/addon-options';11import { withBackgrounds } from '@storybook/addon-backgrounds';12import { withPerformance } from 'storybook-addon-performance';13import { withState } from '@dump247/storybook-state';14import { withNotes } from '@storybook/addon-notes';15import { withPropsTable } from 'storybook-addon-react-docgen';16import { withSmartKnobs } from 'storybook-addon-smart-knobs';17import { withSmartKnobs } from 'storybook-addon-smart-knobs';18import { withStorySource } from '@storybook/addon-storysource';19import { withCsf } from 'storybook-addon-csf';20import { withCssResources } from '@storybook/addon-cssresources';21import { withTests } from '@storybook/addon-jest';22import { withLinks } from '@storybook/addon-links';23import { withI18n } from 'storybook-addon-i18n';24import { withI18n } from 'storybook-addon-i18n';25import { wit

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storiesOf } from 'storybook-root';2const stories = storiesOf('test', module);3stories.add('test', () => <div>test</div>);4import { storiesOf } from 'storybook-root';5const stories = storiesOf('test2', module);6stories.add('test2', () => <div>test2</div>);7import { storiesOf } from 'storybook-root';8const stories = storiesOf('test3', module);9stories.add('test3', () => <div>test3</div>);10import { storiesOf } from 'storybook-root';11const stories = storiesOf('test4', module);12stories.add('test4', () => <div>test4</div>);13import { storiesOf } from 'storybook-root';14const stories = storiesOf('test5', module);15stories.add('test5', () => <div>test5</div>);16import { storiesOf } from 'storybook-root';17const stories = storiesOf('test6', module);18stories.add('test6', () => <div>test6</div>);19import { storiesOf } from 'storybook-root';20const stories = storiesOf('test7', module);21stories.add('test7', () => <div>test7</div>);22import { storiesOf } from 'storybook-root';23const stories = storiesOf('test8', module);24stories.add('test8', () => <div>test8</div>);25import { storiesOf } from 'storybook-root';26const stories = storiesOf('test9', module);27stories.add('test9', () => <div>test9</div>);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storyId } from 'storybook-root';2const id = storyId('Button', 'Basic');3describe('Button', () => {4 it('should render', () => {5 cy.visitStorybook();6 cy.get(`[data-testid="${id}"]`).should('exist');7 });8});9const path = require('path');10const root = path.resolve(__dirname, '..');11module.exports = {12 resolve: {13 alias: {14 },15 },16};17{18 "compilerOptions": {19 "paths": {20 }21 }22}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storyId } from 'storybook-root'2console.log(storyId('Test', 'Button'));3"scripts": {4}5module.exports = {6};7import { addParameters } from '@storybook/react';8import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';9import { withA11y } from '@storybook/addon-a11y';10addParameters({11 viewport: {12 },13});14export const decorators = [withA11y];15import { addons } from '@storybook/addons';16import { create } from '@storybook/theming/create';17addons.setConfig({18 theme: create({19 }),20});21module.exports = async ({ config, mode }) => {22 const path = require('path');23 config.resolve.alias['storybook-root'] = path.resolve(__dirname, '../');24 return config;25};26{27 "compilerOptions": {28 }29}30module.exports = {31 {32 targets: {33 },34 },35};36 window.__STORYBOOK_ADDONS_CHANNEL__.on('storybookjs/source-rendered', (source) => {37 if (source && source.includes('storybook-root')) {

Full Screen

Using AI Code Generation

copy

Full Screen

1const storyId = require('storybook-root').storyId;2const story = storyId('My Button', 'with text');3console.log(story);4const storyId = require('storybook-root').storyId;5const story = storyId('My Button', 'with text');6console.log(story);7const storyId = require('storybook-root').storyId;8const story = storyId('My Button', 'with text');9console.log(story);10const storyId = require('storybook-root').storyId;11const story = storyId('My Button', 'with text');12console.log(story);13const storyId = require('storybook-root').storyId;14const story = storyId('My Button', 'with text');15console.log(story);16const storyId = require('storybook-root').storyId;17const story = storyId('My Button', 'with text');18console.log(story);19const storyId = require('storybook-root').storyId;20const story = storyId('My Button', 'with text');21console.log(story);22const storyId = require('storybook-root').storyId;23const story = storyId('My Button', 'with text');24console.log(story);25const storyId = require('storybook-root').storyId;26const story = storyId('My Button', 'with text');27console.log(story);

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 storybook-root 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