|
1 | 1 | import React from 'react'; |
2 | | -import PrimerTableRow from './PrimerTableRow'; |
3 | | -import { mockPrimerDetails, mockPCRDetails, mockPrimer } from '../../../tests/mockPrimerDetailsData'; |
| 2 | +import PrimerList from './PrimerList'; |
| 3 | +import store from '../../store'; |
| 4 | +import { cloningActions } from '../../store/cloning'; |
| 5 | +import { Provider } from 'react-redux'; |
| 6 | + |
| 7 | +const { setConfig, setPrimers, setGlobalPrimerSettings } = cloningActions; |
| 8 | + |
| 9 | +const mockReply = { |
| 10 | + statusCode: 200, body: { |
| 11 | + melting_temperature: 60, gc_content: .5, homodimer: { |
| 12 | + melting_temperature: 0, |
| 13 | + deltaG: 0, |
| 14 | + figure: "dummy_figure" |
| 15 | + }, |
| 16 | + hairpin: { |
| 17 | + melting_temperature: 0, |
| 18 | + deltaG: 0, |
| 19 | + figure: "dummy_figure" |
| 20 | + }, |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +describe('PrimerList', () => { |
| 25 | + beforeEach(() => { |
| 26 | + store.dispatch(setConfig({ backendUrl: 'http://127.0.0.1:8000' })); |
| 27 | + }); |
| 28 | + it('displays the right information', () => { |
| 29 | + store.dispatch(setPrimers([ |
| 30 | + { id: 1, name: 'P1', sequence: 'TCATTAAAGTTAACG' }, |
| 31 | + ])); |
| 32 | + |
| 33 | + cy.mount( |
| 34 | + <Provider store={store}> |
| 35 | + <PrimerList /> |
| 36 | + </Provider> |
| 37 | + ); |
| 38 | + cy.get('td.name').contains('P1'); |
| 39 | + cy.get('td.length').contains('15'); |
| 40 | + cy.get('td.gc-content').contains('27'); |
| 41 | + cy.get('td.melting-temperature').contains('37.5'); |
| 42 | + cy.get('td.sequence').contains('TCATTAAAGTTAACG'); |
| 43 | + }); |
| 44 | + |
| 45 | + it('caches primer details across re-renders and re-renders on global settings change', () => { |
| 46 | + let calls = 0; |
| 47 | + store.dispatch(setPrimers([ |
| 48 | + { id: 1, name: 'P1', sequence: 'AAA' }, |
| 49 | + ])); |
| 50 | + cy.intercept('POST', 'http://127.0.0.1:8000/primer_details*', (req) => { |
| 51 | + calls += 1; |
| 52 | + const respReply = calls === 1 ? mockReply : { |
| 53 | + statusCode: 200, body: { |
| 54 | + ...mockReply.body, |
| 55 | + melting_temperature: calls === 1 ? 60 : 70, |
| 56 | + } |
| 57 | + } |
| 58 | + expect(req.body).to.deep.equal({ |
| 59 | + sequence: 'AAA', |
| 60 | + settings: { |
| 61 | + primer_dna_conc: calls === 1 ? 50 : 100, |
| 62 | + primer_salt_monovalent: 50, |
| 63 | + primer_salt_divalent: 1.5, |
| 64 | + }, |
| 65 | + }); |
| 66 | + req.reply(respReply); |
| 67 | + }).as('primerDetails'); |
| 68 | + |
| 69 | + // First mount triggers two network calls (one per unique primer sequence) |
| 70 | + cy.mount( |
| 71 | + <Provider store={store}> |
| 72 | + <PrimerList /> |
| 73 | + </Provider>) |
| 74 | + cy.contains('Loading...').should('not.exist'); |
| 75 | + cy.wait('@primerDetails'); |
| 76 | + cy.then(() => { |
| 77 | + expect(calls).to.equal(1); |
| 78 | + cy.mount( |
| 79 | + <Provider store={store}> |
| 80 | + <PrimerList /> |
| 81 | + </Provider>) |
| 82 | + cy.then(() => { |
| 83 | + expect(calls).to.equal(1); |
| 84 | + }); |
| 85 | + store.dispatch(setGlobalPrimerSettings({ primer_dna_conc: 100 })) |
| 86 | + cy.wait('@primerDetails'); |
| 87 | + cy.then(() => { |
| 88 | + expect(calls).to.equal(2); |
| 89 | + cy.get('td.melting-temperature').contains('70'); |
| 90 | + }); |
| 91 | + |
| 92 | + }); |
| 93 | + |
| 94 | + }); |
| 95 | +}); |
0 commit comments