@@ -25,6 +25,11 @@ 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' , ( ) => {
2934 global . URL . createObjectURL = jest . fn ( ) ; //.mockReturnValue('xyz.test');
3035 global . setTimeout = ( cb ) => cb ( ) ;
@@ -65,18 +70,18 @@ describe('REPORT PAGE', () => {
6570 } ) ;
6671
6772 describe ( 'LONG QUERIES (>12)' , ( ) => {
68-
73+ let container ;
74+ beforeEach ( ( ) => {
75+ container = render ( < TestSidebar long /> ) . container ;
76+ } ) ;
6977 it ( 'should not show navigation links for long queries' , ( ) => {
70- const { container } = render ( < TestSidebar long /> ) ;
7178 expect ( container . querySelectorAll ( 'a[href^="#Query_"]' ) . length ) . toBe ( 0 ) ;
7279 } ) ;
7380 it ( 'should show only next button if on first query ' , ( ) => {
74- render ( < TestSidebar long /> ) ;
7581 expect ( nextQueryButton ( ) ) . toBeInTheDocument ( ) ;
7682 expect ( previousQueryButton ( ) ) . not . toBeInTheDocument ( ) ;
7783 } ) ;
7884 it ( 'should show both previous and next buttons if not on first query' , ( ) => {
79- render ( < TestSidebar long /> ) ;
8085 const nextBtn = nextQueryButton ( ) ;
8186 expect ( nextBtn ) . toBeInTheDocument ( ) ;
8287 fireEvent . click ( nextBtn ) ;
@@ -86,7 +91,6 @@ describe('REPORT PAGE', () => {
8691 } ) ;
8792 it ( 'should show only previous button if on last query' , ( ) => {
8893 const { queries } = longResponseJSON ;
89- render ( < TestSidebar long /> ) ;
9094 expect ( nextQueryButton ( ) ) . toBeInTheDocument ( ) ;
9195 expect ( previousQueryButton ( ) ) . not . toBeInTheDocument ( ) ;
9296
@@ -98,61 +102,52 @@ describe('REPORT PAGE', () => {
98102 } ) ;
99103 } ) ;
100104
101- describe ( 'ALIGNMENT DOWNLOAD' , ( ) => {
102- it ( 'should generate a blob url and filename for downloading alignment of all hits on render' , ( ) => {
103- setMockJSONResult ( { status : 200 , responseJSON : shortResponseJSON } ) ;
104- const { container } = render ( < Report getCharacterWidth = { jest . fn ( ) } /> ) ;
105- const alignment_download_link = container . querySelector ( '.download-alignment-of-all' ) ;
106- const expected_num_hits = container . querySelectorAll ( '.hit-links input[type="checkbox"]' ) . length ;
107- const file_name = `alignment-${ expected_num_hits } _hits.txt` ;
108- expect ( alignment_download_link . download ) . toEqual ( file_name ) ;
109- expect ( alignment_download_link . hred ) . not . toEqual ( '#' ) ;
110- } ) ;
111- it ( 'link for downloading alignment of specific number of selected hits should be disabled on initial load' , ( ) => {
105+ describe ( 'DOWNLOAD LINKS' , ( ) => {
106+ let container ;
107+ beforeEach ( ( ) => {
112108 setMockJSONResult ( { status : 200 , responseJSON : shortResponseJSON } ) ;
113- const { container } = render ( < Report getCharacterWidth = { jest . fn ( ) } /> ) ;
114- const alignment_download_link = container . querySelector ( '.download-alignment-of-selected' ) ;
115- expect ( alignment_download_link . classList . contains ( 'disabled' ) ) . toBeTruthy ( ) ;
116-
109+ container = render ( < Report getCharacterWidth = { jest . fn ( ) } /> ) . container ;
117110 } ) ;
118- it ( 'should generate a blob url and filename for downloading alignment of specific number of selected hits' , ( ) => {
119- setMockJSONResult ( { status : 200 , responseJSON : shortResponseJSON } ) ;
120- const { container } = render ( < Report getCharacterWidth = { jest . fn ( ) } /> ) ;
121- const alignment_download_link = container . querySelector ( '.download-alignment-of-selected' ) ;
122-
123- // QUERY ALL HIT LINKS CHECKBOXES
124- const checkboxes = container . querySelectorAll ( '.hit-links input[type="checkbox"]' ) ;
125- // SELECT 4 CHECKBOXES
126- Array . from ( checkboxes ) . slice ( 0 , 4 ) . forEach ( ( checkbox ) => {
127- fireEvent . click ( checkbox ) ;
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 ) ;
128133 } ) ;
129- const file_name = 'alignment-4_hits.txt' ;
130- expect ( alignment_download_link . textContent ) . toEqual ( 'Alignment of 4 selected hit(s)' ) ;
131- expect ( alignment_download_link . download ) . toEqual ( file_name ) ;
132- } ) ;
133- } ) ;
134-
135- describe ( 'FASTA DOWNLOAD' , ( ) => {
136- it ( 'link for downloading fasta of specific number of selected hits should be disabled on initial load' , ( ) => {
137- setMockJSONResult ( { status : 200 , responseJSON : shortResponseJSON } ) ;
138- const { container } = render ( < Report getCharacterWidth = { jest . fn ( ) } /> ) ;
139- const fasta_download_link = container . querySelector ( '.download-fasta-of-selected' ) ;
140- expect ( fasta_download_link . classList . contains ( 'disabled' ) ) . toBeTruthy ( ) ;
141-
142134 } ) ;
143-
144- it ( 'link for downloading fasta of specific number of selected hits should be active after selection' , ( ) => {
145- setMockJSONResult ( { status : 200 , responseJSON : shortResponseJSON } ) ;
146- const { container } = render ( < Report getCharacterWidth = { jest . fn ( ) } /> ) ;
147- const fasta_download_link = container . querySelector ( '.download-fasta-of-selected' ) ;
148-
149- // QUERY ALL HIT LINKS CHECKBOXES
150- const checkboxes = container . querySelectorAll ( '.hit-links input[type="checkbox"]' ) ;
151- // SELECT 5 CHECKBOXES
152- Array . from ( checkboxes ) . slice ( 0 , 5 ) . forEach ( ( checkbox ) => {
153- fireEvent . click ( checkbox ) ;
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)' ) ;
154150 } ) ;
155- expect ( fasta_download_link . textContent ) . toEqual ( 'FASTA of 5 selected hit(s)' ) ;
156151 } ) ;
157152 } ) ;
158153 } ) ;
0 commit comments