@@ -25,7 +25,14 @@ const TestSidebar = ({ long }) => {
2525 /> ;
2626} ;
2727
28+ const clickCheckboxes = ( checkboxes , count ) => {
29+ Array . from ( checkboxes ) . slice ( 0 , count ) . forEach ( ( checkbox ) => {
30+ fireEvent . click ( checkbox ) ;
31+ } ) ;
32+ } ;
2833describe ( 'REPORT PAGE' , ( ) => {
34+ global . URL . createObjectURL = jest . fn ( ) ; //.mockReturnValue('xyz.test');
35+ global . setTimeout = ( cb ) => cb ( ) ;
2936 it ( 'should render the report component with initial loading state' , ( ) => {
3037 render ( < Report /> ) ;
3138 expect ( screen . getByRole ( 'heading' , { name : 'BLAST-ing' } ) ) . toBeInTheDocument ( ) ;
@@ -39,7 +46,7 @@ describe('REPORT PAGE', () => {
3946 } ) ;
4047 it ( 'it should render the report page correctly if there\'s a response provided' , ( ) => {
4148 setMockJSONResult ( { status : 200 , responseJSON : shortResponseJSON } ) ;
42- const { container } = render ( < Report /> ) ;
49+ const { container } = render ( < Report getCharacterWidth = { jest . fn ( ) } /> ) ;
4350 expect ( container . querySelector ( '#results' ) ) . toBeInTheDocument ( ) ;
4451
4552 } ) ;
@@ -63,18 +70,18 @@ describe('REPORT PAGE', () => {
6370 } ) ;
6471
6572 describe ( 'LONG QUERIES (>12)' , ( ) => {
66-
73+ let container ;
74+ beforeEach ( ( ) => {
75+ container = render ( < TestSidebar long /> ) . container ;
76+ } ) ;
6777 it ( 'should not show navigation links for long queries' , ( ) => {
68- const { container } = render ( < TestSidebar long /> ) ;
6978 expect ( container . querySelectorAll ( 'a[href^="#Query_"]' ) . length ) . toBe ( 0 ) ;
7079 } ) ;
7180 it ( 'should show only next button if on first query ' , ( ) => {
72- render ( < TestSidebar long /> ) ;
7381 expect ( nextQueryButton ( ) ) . toBeInTheDocument ( ) ;
7482 expect ( previousQueryButton ( ) ) . not . toBeInTheDocument ( ) ;
7583 } ) ;
7684 it ( 'should show both previous and next buttons if not on first query' , ( ) => {
77- render ( < TestSidebar long /> ) ;
7885 const nextBtn = nextQueryButton ( ) ;
7986 expect ( nextBtn ) . toBeInTheDocument ( ) ;
8087 fireEvent . click ( nextBtn ) ;
@@ -84,7 +91,6 @@ describe('REPORT PAGE', () => {
8491 } ) ;
8592 it ( 'should show only previous button if on last query' , ( ) => {
8693 const { queries } = longResponseJSON ;
87- render ( < TestSidebar long /> ) ;
8894 expect ( nextQueryButton ( ) ) . toBeInTheDocument ( ) ;
8995 expect ( previousQueryButton ( ) ) . not . toBeInTheDocument ( ) ;
9096
@@ -95,5 +101,55 @@ describe('REPORT PAGE', () => {
95101 expect ( previousQueryButton ( ) ) . toBeInTheDocument ( ) ;
96102 } ) ;
97103 } ) ;
104+
105+ describe ( 'DOWNLOAD LINKS' , ( ) => {
106+ let container ;
107+ beforeEach ( ( ) => {
108+ setMockJSONResult ( { status : 200 , responseJSON : shortResponseJSON } ) ;
109+ container = render ( < Report getCharacterWidth = { jest . fn ( ) } /> ) . container ;
110+ } ) ;
111+ describe ( 'ALIGNMENT DOWNLOAD' , ( ) => {
112+ it ( 'should generate a blob url and filename for downloading alignment of all hits on render' , ( ) => {
113+ const alignment_download_link = container . querySelector ( '.download-alignment-of-all' ) ;
114+ const expected_num_hits = container . querySelectorAll ( '.hit-links input[type="checkbox"]' ) . length ;
115+ const file_name = `alignment-${ expected_num_hits } _hits.txt` ;
116+ expect ( alignment_download_link . download ) . toEqual ( file_name ) ;
117+ expect ( alignment_download_link . hred ) . not . toEqual ( '#' ) ;
118+ } ) ;
119+ it ( 'link for downloading alignment of specific number of selected hits should be disabled on initial load' , ( ) => {
120+ const alignment_download_link = container . querySelector ( '.download-alignment-of-selected' ) ;
121+ expect ( alignment_download_link . classList . contains ( 'disabled' ) ) . toBeTruthy ( ) ;
122+
123+ } ) ;
124+ it ( 'should generate a blob url and filename for downloading alignment of specific number of selected hits' , ( ) => {
125+ const alignment_download_link = container . querySelector ( '.download-alignment-of-selected' ) ;
126+ // QUERY ALL HIT LINKS CHECKBOXES
127+ const checkboxes = container . querySelectorAll ( '.hit-links input[type="checkbox"]' ) ;
128+ // SELECT 4 CHECKBOXES
129+ clickCheckboxes ( checkboxes , 4 ) ;
130+ const file_name = 'alignment-4_hits.txt' ;
131+ expect ( alignment_download_link . textContent ) . toEqual ( 'Alignment of 4 selected hit(s)' ) ;
132+ expect ( alignment_download_link . download ) . toEqual ( file_name ) ;
133+ } ) ;
134+ } ) ;
135+
136+ describe ( 'FASTA DOWNLOAD' , ( ) => {
137+ let fasta_download_link ;
138+ beforeEach ( ( ) => {
139+ fasta_download_link = container . querySelector ( '.download-fasta-of-selected' ) ;
140+ } ) ;
141+ it ( 'link for downloading fasta of selected number of hits should be disabled on initial load' , ( ) => {
142+ expect ( fasta_download_link . classList . contains ( 'disabled' ) ) . toBeTruthy ( ) ;
143+ } ) ;
144+
145+ it ( 'link for downloading fasta of specific number of selected hits should be active after selection' , ( ) => {
146+ const checkboxes = container . querySelectorAll ( '.hit-links input[type="checkbox"]' ) ;
147+ // SELECT 5 CHECKBOXES
148+ clickCheckboxes ( checkboxes , 5 ) ;
149+ expect ( fasta_download_link . textContent ) . toEqual ( 'FASTA of 5 selected hit(s)' ) ;
150+ } ) ;
151+ } ) ;
152+ } ) ;
98153 } ) ;
154+
99155} ) ;
0 commit comments