@@ -29,6 +29,44 @@ Fulfill the user stories below and get all the tests to pass to complete the lab
29291 . When you click the ` #close-list-button ` , you should run your function to hide the ` #bookmark-list-section ` and display the main section.
30301 . When you click the ` #delete-bookmark-button ` , you should delete the bookmark corresponding to the selected radio button and appropriate category from the local storage and update the displayed bookmark list.
3131
32+ # --before-all--
33+
34+ ``` js
35+ const getHidden = (notMain ) => {
36+ const mainSection = document .querySelector (" #main-section" );
37+ const formSection = document .querySelector (" #form-section" );
38+ const bookmarkListSection = document .querySelector (" #bookmark-list-section" );
39+ if (notMain === " form" ) {
40+ if (mainSection .classList .contains (" hidden" ) && ! formSection .classList .contains (" hidden" )) {
41+ return " main"
42+ } else if (! mainSection .classList .contains (" hidden" ) && formSection .classList .contains (" hidden" )) {
43+ return notMain;
44+ }
45+ } else if (notMain === " bookmark list" ) {
46+ if (mainSection .classList .contains (" hidden" ) && ! bookmarkListSection .classList .contains (" hidden" )) {
47+ return " main"
48+ } else if (! mainSection .classList .contains (" hidden" ) && bookmarkListSection .classList .contains (" hidden" )) {
49+ return notMain;
50+ }
51+ }
52+ }
53+
54+ const originalLocalStorage = JSON .parse (localStorage .getItem (" bookmarks" )) || [];
55+ const temp = originalLocalStorage;
56+ function resetLocalStorage () {
57+ localStorage .setItem (" bookmarks" , JSON .stringify (temp));
58+ }
59+
60+ function setLocalStorage () {
61+ localStorage .setItem (" bookmarks" , JSON .stringify ([{name: " example1" , category: " news" , url: " example1.com" }, {name: " example2" , category: " entertainment" , url: " example2.com" }, {name: " example3" , category: " work" , url: " example3.com" }, {name: " example4" , category: " news" , url: " example4.com" }]));
62+ }
63+
64+ function clearCategoryList () {
65+ const categoryList = document .getElementById (" category-list" );
66+ categoryList .innerHTML = " " ;
67+ }
68+ ```
69+
3270# --hints--
3371
3472You should have a ` getBookmarks ` function.
@@ -106,6 +144,8 @@ assert.notEqual(hidden, hiddenAfterCall);
106144When you click ` #add-bookmark-button ` , you should update the inner text of ` .category-name ` to be the value of the selected option from ` #category-dropdown ` .
107145
108146``` js
147+ const addBookMarkButtonTest = document .getElementById (" add-bookmark-button" );
148+ const categoryDropdownTest = document .getElementById (" category-dropdown" );
109149addBookMarkButtonTest .dispatchEvent (new Event (" click" ));
110150const categoryName = document .querySelector (" .category-name" ).innerText ;
111151assert .strictEqual (categoryName .toLowerCase (), categoryDropdownTest .value .toLowerCase ());
@@ -114,6 +154,7 @@ assert.strictEqual(categoryName.toLowerCase(), categoryDropdownTest.value.toLowe
114154When you click ` #add-bookmark-button ` , you should call ` displayOrCloseForm ` to display the form section and hide the main section.
115155
116156``` js
157+ const addBookMarkButtonTest = document .getElementById (" add-bookmark-button" );
117158assert .strictEqual (getHidden (" form" ), " form" );
118159addBookMarkButtonTest .dispatchEvent (new Event (" click" ));
119160assert .strictEqual (getHidden (" form" ), " main" );
@@ -122,6 +163,7 @@ assert.strictEqual(getHidden("form"), "main");
122163When you click ` #close-form-button ` , you should call ` displayOrCloseForm ` to hide the form section and display the main section.
123164
124165``` js
166+ const closeFormButtonTest = document .getElementById (" close-form-button" );
125167assert .strictEqual (getHidden (" form" ), " main" );
126168closeFormButtonTest .dispatchEvent (new Event (" click" ));
127169assert .strictEqual (getHidden (" form" ), " form" );
@@ -131,6 +173,10 @@ When you click `#add-bookmark-button-form`, you should update the `bookmarks` ke
131173
132174``` js
133175setLocalStorage ();
176+ const addBookmarkButtonFormTest = document .getElementById (" add-bookmark-button-form" );
177+ const categoryDropdownTest = document .getElementById (" category-dropdown" );
178+ const bookmarkNameTest = document .getElementById (" name" );
179+ const bookmarkURLTest = document .getElementById (" url" );
134180try {
135181 bookmarkNameTest .value = " test example5" ;
136182 bookmarkURLTest .value = " test example5.com" ;
@@ -152,6 +198,9 @@ try {
152198When you click ` #add-bookmark-button-form ` , you should reset the value of ` #name ` and ` #url ` to an empty string.
153199
154200``` js
201+ const addBookmarkButtonFormTest = document .getElementById (" add-bookmark-button-form" );
202+ const bookmarkNameTest = document .getElementById (" name" );
203+ const bookmarkURLTest = document .getElementById (" url" );
155204try {
156205 bookmarkNameTest .value = " test example2" ;
157206 bookmarkURLTest .value = " test example2.com" ;
@@ -168,6 +217,10 @@ try {
168217When you click ` #add-bookmark-button-form ` , you should run ` displayOrCloseForm ` to hide the form section and show the main section.
169218
170219``` js
220+ const addBookmarkButtonFormTest = document .getElementById (" add-bookmark-button-form" );
221+ const addBookMarkButtonTest = document .getElementById (" add-bookmark-button" );
222+ const bookmarkNameTest = document .getElementById (" name" );
223+ const bookmarkURLTest = document .getElementById (" url" );
171224try {
172225 bookmarkNameTest .value = " test example3" ;
173226 bookmarkURLTest .value = " test example3.com" ;
@@ -199,6 +252,8 @@ assert.notEqual(hidden, hiddenAfterCall)
199252When you click ` #view-category-button ` , you should update the inner text of ` .category-name ` to be the value of the selected option from ` #category-dropdown ` .
200253
201254``` js
255+ const viewCategoryButtonTest = document .getElementById (" view-category-button" );
256+ const categoryDropdownTest = document .getElementById (" category-dropdown" );
202257viewCategoryButtonTest .dispatchEvent (new Event (" click" ));
203258const categoryName = document .querySelector (" .category-name" ).innerText ;
204259assert .strictEqual (categoryName .toLowerCase (), categoryDropdownTest .value .toLowerCase ());
@@ -208,6 +263,8 @@ When you click `#view-category-button`, you should add a `p` element with the te
208263
209264``` js
210265try {
266+ const viewCategoryButtonTest = document .getElementById (" view-category-button" );
267+ const categoryDropdownTest = document .getElementById (" category-dropdown" );
211268 setLocalStorage ()
212269 categoryDropdownTest .value = " miscellaneous" ;
213270 viewCategoryButtonTest .dispatchEvent (new Event (" click" ));
@@ -223,6 +280,8 @@ When you click the `#view-category-button`, you should modify the `#category-lis
223280
224281``` js
225282try {
283+ const viewCategoryButtonTest = document .getElementById (" view-category-button" );
284+ const categoryDropdownTest = document .getElementById (" category-dropdown" );
226285 setLocalStorage ();
227286 categoryDropdownTest .value = " news" ;
228287 viewCategoryButtonTest .dispatchEvent (new Event (" click" ));
@@ -243,6 +302,8 @@ Each radio button added to `#category-list`'s inner HTML should have a correspon
243302
244303``` js
245304setLocalStorage ();
305+ const viewCategoryButtonTest = document .getElementById (" view-category-button" );
306+ const categoryDropdownTest = document .getElementById (" category-dropdown" );
246307try {
247308 categoryDropdownTest .value = " news" ;
248309 viewCategoryButtonTest .dispatchEvent (new Event (" click" ));
@@ -259,6 +320,8 @@ Each `label` element should contain an anchor element with the bookmark name as
259320
260321``` js
261322setLocalStorage ();
323+ const viewCategoryButtonTest = document .getElementById (" view-category-button" );
324+ const categoryDropdownTest = document .getElementById (" category-dropdown" );
262325try {
263326 categoryDropdownTest .value = " news" ;
264327 viewCategoryButtonTest .dispatchEvent (new Event (" click" ));
@@ -276,6 +339,8 @@ try {
276339When you click ` #close-list-button ` , you should hide ` #bookmark-list-section ` and display the main section.
277340
278341``` js
342+ const viewCategoryButtonTest = document .getElementById (" view-category-button" );
343+ const closeListButtonTest = document .getElementById (" close-list-button" );
279344viewCategoryButtonTest .dispatchEvent (new Event (" click" ));
280345assert .strictEqual (getHidden (" bookmark list" ), " main" );
281346closeListButtonTest .dispatchEvent (new Event (" click" ));
@@ -286,6 +351,9 @@ When you click the `#close-list-button` and then open any category, the `#catego
286351
287352``` js
288353setLocalStorage ();
354+ const viewCategoryButtonTest = document .getElementById (" view-category-button" );
355+ const closeListButtonTest = document .getElementById (" close-list-button" );
356+ const categoryDropdownTest = document .getElementById (" category-dropdown" );
289357try {
290358 categoryDropdownTest .value = " miscellaneous" ;
291359 viewCategoryButtonTest .dispatchEvent (new Event (" click" ));
@@ -328,6 +396,9 @@ When you click the `#delete-bookmark-button`, you should delete the bookmark cor
328396
329397``` js
330398setLocalStorage ();
399+ const viewCategoryButtonTest = document .getElementById (" view-category-button" );
400+ const deleteBookmarkButtonTest = document .getElementById (" delete-bookmark-button" );
401+ const categoryDropdownTest = document .getElementById (" category-dropdown" );
331402try {
332403 categoryDropdownTest .value = " news" ;
333404 viewCategoryButtonTest .dispatchEvent (new Event (" click" ));
@@ -361,53 +432,6 @@ try {
361432
362433# --seed--
363434
364- ## --after-user-code--
365-
366- ``` js
367- const viewCategoryButtonTest = document .getElementById (" view-category-button" );
368- const closeListButtonTest = document .getElementById (" close-list-button" );
369- const closeFormButtonTest = document .getElementById (" close-form-button" );
370- const addBookMarkButtonTest = document .getElementById (" add-bookmark-button" );
371- const addBookmarkButtonFormTest = document .getElementById (" add-bookmark-button-form" );
372- const deleteBookmarkButtonTest = document .getElementById (" delete-bookmark-button" );
373- const bookmarkNameTest = document .getElementById (" name" );
374- const categoryDropdownTest = document .getElementById (" category-dropdown" );
375- const bookmarkURLTest = document .getElementById (" url" );
376- const mainSection = document .querySelector (" #main-section" );
377- const formSection = document .querySelector (" #form-section" );
378- const bookmarkListSection = document .querySelector (" #bookmark-list-section" );
379- const getHidden = (notMain ) => {
380- if (notMain === " form" ) {
381- if (mainSection .classList .contains (" hidden" ) && ! formSection .classList .contains (" hidden" )) {
382- return " main"
383- } else if (! mainSection .classList .contains (" hidden" ) && formSection .classList .contains (" hidden" )) {
384- return notMain;
385- }
386- } else if (notMain === " bookmark list" ) {
387- if (mainSection .classList .contains (" hidden" ) && ! bookmarkListSection .classList .contains (" hidden" )) {
388- return " main"
389- } else if (! mainSection .classList .contains (" hidden" ) && bookmarkListSection .classList .contains (" hidden" )) {
390- return notMain;
391- }
392- }
393- }
394-
395- const originalLocalStorage = JSON .parse (localStorage .getItem (" bookmarks" )) || [];
396- const temp = originalLocalStorage;
397- function resetLocalStorage () {
398- localStorage .setItem (" bookmarks" , JSON .stringify (temp));
399- }
400-
401- function setLocalStorage () {
402- localStorage .setItem (" bookmarks" , JSON .stringify ([{name: " example1" , category: " news" , url: " example1.com" }, {name: " example2" , category: " entertainment" , url: " example2.com" }, {name: " example3" , category: " work" , url: " example3.com" }, {name: " example4" , category: " news" , url: " example4.com" }]));
403- }
404-
405- function clearCategoryList () {
406- const categoryList = document .getElementById (" category-list" );
407- categoryList .innerHTML = " " ;
408- }
409- ```
410-
411435## --seed-contents--
412436
413437``` js
0 commit comments