@@ -57,7 +57,7 @@ describe("Fields logic", () => {
5757 await user . click ( toggle ) ;
5858 expect ( submit ) . not . toBeDisabled ( ) ;
5959
60- // fields should be populated
60+ // Fields should be populated
6161 expect ( url ) . toHaveValue ( "https://foodnetwork.com" ) ;
6262
6363 const axiosMock = new MockAdapter ( instance ) ;
@@ -103,7 +103,7 @@ describe("Fields logic", () => {
103103
104104 await user . click ( submit ) ;
105105
106- // if everything submitted correctly then it should be empty input field .
106+ // If submitted correctly, the fields should be reset .
107107 expect ( url ) . toHaveValue ( "" ) ;
108108 expect ( tags ) . toHaveValue ( "" ) ;
109109 expect ( submit ) . toBeDisabled ( ) ;
@@ -171,7 +171,7 @@ describe("Fields logic", () => {
171171 await user . type ( tags , "food" ) ;
172172 expect ( submit ) . not . toBeDisabled ( ) ;
173173
174- // fields should be populated
174+ // Fields should be populated
175175 expect ( url ) . toHaveValue ( "https://foodnetwork.com" ) ;
176176
177177 const axiosMock = new MockAdapter ( instance ) ;
@@ -226,7 +226,7 @@ describe("Fields logic", () => {
226226
227227 await user . click ( submit ) ;
228228
229- // if everything submitted correctly then it should be empty input field .
229+ // If submitted correctly, the fields should be reset .
230230 expect ( url ) . toHaveValue ( "" ) ;
231231 expect ( tags ) . toHaveValue ( "" ) ;
232232 expect ( submit ) . toBeDisabled ( ) ;
@@ -276,3 +276,77 @@ describe("Tags Operations", () => {
276276 expect ( screen . queryByTestId ( "Tag2" ) ) . toEqual ( null ) ;
277277 } ) ;
278278} ) ;
279+
280+ describe ( "Success Toast" , ( ) => {
281+ it ( "displays a green success toast when bookmark is added successfully" , async ( ) => {
282+ render (
283+ < div data-bs-theme = "dark" className = "row pt-3" >
284+ < div className = "col-6 col-sm-12 col-md-12 col-lg-4" >
285+ < NewBookmarkCard />
286+ </ div >
287+ </ div > ,
288+ ) ;
289+
290+ const submit = screen . getByText ( "Submit" ) ;
291+ const tagsInput = screen . getByPlaceholderText ( "Enter a tag" ) ;
292+ const urlInput = screen . getByPlaceholderText ( / d i s c o v e r / i) ;
293+
294+ // Type in the URL (it will be prefixed with "https://")
295+ await user . type ( urlInput , "example.com" ) ;
296+ expect ( urlInput ) . toHaveValue ( "https://example.com" ) ;
297+
298+ // Type a tag and add it
299+ await user . type ( tagsInput , "testtag" ) ;
300+ await user . type ( tagsInput , "{enter}" ) ;
301+
302+ // Setup axios mocks for API calls
303+ const axiosMock = new MockAdapter ( instance ) ;
304+ const SERVER_URL = process . env . NEXT_PUBLIC_SERVER_URL ;
305+ const tagsAPI = SERVER_URL + "/api/tags" ;
306+ const bookmarkAPI = SERVER_URL + "/api/bookmark" ;
307+
308+ const expectedResult = [
309+ {
310+ id : 1 ,
311+ title : "testtag" ,
312+ bookmarks : [ ] ,
313+ } ,
314+ ] ;
315+
316+ const expectedBookmark : Bookmark = {
317+ id : 1 ,
318+ title : "example.com" ,
319+ url : "https://example.com" ,
320+ tags : [
321+ {
322+ id : 1 ,
323+ title : "testtag" ,
324+ } ,
325+ ] ,
326+ screenshotUrl : "" ,
327+ scrapable : true ,
328+ } ;
329+
330+ axiosMock . onPost ( tagsAPI , [ "testtag" ] ) . reply ( ( ) => {
331+ return [ 200 , expectedResult ] ;
332+ } ) ;
333+
334+ axiosMock
335+ . onPost ( bookmarkAPI , {
336+ title : "https://example.com" ,
337+ url : "https://example.com" ,
338+ tagIds : [ 1 ] ,
339+ scrapable : true ,
340+ } )
341+ . reply ( ( ) => {
342+ return [ 200 , expectedBookmark ] ;
343+ } ) ;
344+
345+ await user . click ( submit ) ;
346+
347+ // Wait for the success toast to appear
348+ expect (
349+ await screen . findByText ( "Bookmark added successfully!" )
350+ ) . toBeInTheDocument ( ) ;
351+ } ) ;
352+ } ) ;
0 commit comments