/// <reference types="cypress" />

import makeFakeUser from '../../factories/user';

describe('JamTracks Page', () => {
  beforeEach(() => {
    const currentUser = makeFakeUser();
    cy.stubAuthenticate({ id: currentUser.id });
    cy.visit('/my-jamtracks');
  });

  it('should display the My JamTracks page', () => {
    cy.get('.card-header h5').should('contain', 'My JamTracks');
  });

  it('should display the search bar', () => {
    cy.get('input[type="search"]').should('exist');
  });

  describe('filter', () => { 
    beforeEach(() => {
      cy.intercept('GET', /\S+\/jamtracks\/purchased\?page=1\&\S+/, { fixture: 'my_jamtracks_page1' }).as('getMyJamTracks_page1');
    });

    it('should display the JamTracks', () => {
      cy.get('input[type="search"]').type('ba');
      cy.wait('@getMyJamTracks_page1');
      cy.get('[data-testid=myJamTrackList]').should('contain', 'Back in Black by AC DC');
    });

    it('clicking on a JamTrack should navigate to the JamTrack page', () => {
      cy.get('input[type="search"]').type('ba');
      cy.wait('@getMyJamTracks_page1');
      cy.get('[data-testid=myJamTrackList] a').first().click();
      cy.url().should('include', '/jamtrack/1');
    });
   })
  
  

});