Skip to content

Commit 4805702

Browse files
committed
create test cases for alignment and fasta downloads
1 parent 517d00c commit 4805702

4 files changed

Lines changed: 65 additions & 5 deletions

File tree

public/js/tests/report.spec.js

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const TestSidebar = ({ long }) => {
2626
};
2727

2828
describe('REPORT PAGE', () => {
29-
global.URL.createObjectURL = jest.fn();
29+
global.URL.createObjectURL = jest.fn();//.mockReturnValue('xyz.test');
30+
global.setTimeout = (cb) => cb();
3031
it('should render the report component with initial loading state', () => {
3132
render(<Report />);
3233
expect(screen.getByRole('heading', { name: 'BLAST-ing' })).toBeInTheDocument();
@@ -40,7 +41,7 @@ describe('REPORT PAGE', () => {
4041
});
4142
it('it should render the report page correctly if there\'s a response provided', () => {
4243
setMockJSONResult({ status: 200, responseJSON: shortResponseJSON });
43-
const { container } = render(<Report />);
44+
const { container } = render(<Report getCharacterWidth={jest.fn()} />);
4445
expect(container.querySelector('#results')).toBeInTheDocument();
4546

4647
});
@@ -96,5 +97,64 @@ describe('REPORT PAGE', () => {
9697
expect(previousQueryButton()).toBeInTheDocument();
9798
});
9899
});
100+
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', () => {
112+
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+
117+
});
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);
128+
});
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+
142+
});
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);
154+
});
155+
expect(fasta_download_link.textContent).toEqual('FASTA of 5 selected hit(s)');
156+
});
157+
});
99158
});
159+
100160
});

public/js/visualisation_helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import _ from 'underscore';
2-
2+
import d3 from 'd3';
33
export function get_colors_for_evalue(evalue, hits) {
44
var colors = d3.scale
55
.log()

public/sequenceserver-report.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/sequenceserver-search.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)