|
| 1 | +/// <reference types="cypress" /> |
| 2 | + |
| 3 | +describe('LC/MS layouts', () => { |
| 4 | + const getAppState = () => cy.window().then((win) => (win as any).__spectraStore.getState()) |
| 5 | + |
| 6 | + const openLayout = (buttonText: string) => { |
| 7 | + cy.viewport(2000, 2000) |
| 8 | + cy.visit('http://localhost:3000/') |
| 9 | + cy.contains('button', buttonText).click() |
| 10 | + } |
| 11 | + |
| 12 | + const assertNoNaNInPaths = (selector: string) => { |
| 13 | + cy.get(`${selector} path[d]`).each(($path) => { |
| 14 | + const d = $path.attr('d') || '' |
| 15 | + expect(d).to.not.contain('NaN') |
| 16 | + }) |
| 17 | + } |
| 18 | + |
| 19 | + const assertLcmsViewerIsStable = () => { |
| 20 | + cy.get('.d3Line .d3Svg').should('exist') |
| 21 | + cy.get('.d3Multi .d3SvgMulti').should('exist') |
| 22 | + cy.get('.d3Rect .d3SvgRect').should('exist') |
| 23 | + |
| 24 | + assertNoNaNInPaths('.d3Line .d3Svg') |
| 25 | + assertNoNaNInPaths('.d3Multi .d3SvgMulti') |
| 26 | + assertNoNaNInPaths('.d3Rect .d3SvgRect') |
| 27 | + } |
| 28 | + |
| 29 | + it('OpenLab renders LC/MS line, multi and rect graphs', () => { |
| 30 | + openLayout('LC/MS OpenLab') |
| 31 | + assertLcmsViewerIsStable() |
| 32 | + }) |
| 33 | + |
| 34 | + it('Chemstation renders LC/MS line, multi and rect graphs', () => { |
| 35 | + openLayout('LC/MS Chemstation') |
| 36 | + assertLcmsViewerIsStable() |
| 37 | + }) |
| 38 | + |
| 39 | + it('requests MS page on initial load and TIC click in standalone simulation', () => { |
| 40 | + openLayout('LC/MS OpenLab') |
| 41 | + assertLcmsViewerIsStable() |
| 42 | + |
| 43 | + // Waits until React has run componentDidUpdate (initial_load on __lcmsDemoRequests). |
| 44 | + cy.window().its('__lcmsDemoRequests').should('have.length.above', 0) |
| 45 | + |
| 46 | + cy.window().then((win) => { |
| 47 | + (win as any).__spectraStore.dispatch({ |
| 48 | + type: 'DISPLAY_VIEWER_AT', |
| 49 | + payload: { x: 0.8, y: 0, graphIndex: 1 }, |
| 50 | + }) |
| 51 | + }) |
| 52 | + |
| 53 | + cy.wait(400) |
| 54 | + cy.window().its('__lcmsDemoRequests').should('have.length.above', 1) |
| 55 | + cy.window().then((win) => { |
| 56 | + const requests = (win as any).__lcmsDemoRequests || [] |
| 57 | + const latestRequest = requests[requests.length - 1] |
| 58 | + expect(latestRequest.trigger).to.equal('user_click') |
| 59 | + expect(Number.isFinite(latestRequest.retentionTime)).to.equal(true) |
| 60 | + }) |
| 61 | + |
| 62 | + getAppState().then((stateAfter) => { |
| 63 | + expect(Number.isFinite(stateAfter.hplcMs.tic.currentPageValue)).to.equal(true) |
| 64 | + }) |
| 65 | + }) |
| 66 | + |
| 67 | + it('updates reducer when adding peak and integration action', () => { |
| 68 | + openLayout('LC/MS OpenLab') |
| 69 | + assertLcmsViewerIsStable() |
| 70 | + |
| 71 | + cy.window().then((win) => { |
| 72 | + getAppState().then((stateBefore) => { |
| 73 | + const peaksBefore = stateBefore.hplcMs.uvvis.currentSpectrum?.peaks?.length || 0 |
| 74 | + const integrationsBefore = stateBefore.hplcMs.uvvis.currentSpectrum?.integrations?.length || 0 |
| 75 | + |
| 76 | + cy.get('.btn-sv-bar-addpeak').click() |
| 77 | + cy.get('.d3Line .d3Svg').trigger('click', 600, 350, { which: 1, view: win }) |
| 78 | + |
| 79 | + const selectedWaveLength = stateBefore.hplcMs.uvvis.selectedWaveLength |
| 80 | + const spectrumData = stateBefore.hplcMs.uvvis.currentSpectrum?.data |
| 81 | + const xValues = Array.isArray(spectrumData?.x) ? spectrumData.x : [] |
| 82 | + const yValues = Array.isArray(spectrumData?.y) ? spectrumData.y : [] |
| 83 | + const mid = Math.floor(xValues.length / 2) |
| 84 | + const xL = xValues[Math.max(0, mid - 20)] |
| 85 | + const xU = xValues[Math.min(xValues.length - 1, mid + 20)] |
| 86 | + const hasIntegrationPayload = Number.isFinite(xL) |
| 87 | + && Number.isFinite(xU) |
| 88 | + && xU !== xL |
| 89 | + && xValues.length > 0 |
| 90 | + && yValues.length > 0 |
| 91 | + |
| 92 | + if (hasIntegrationPayload) { |
| 93 | + (win as any).__spectraStore.dispatch({ |
| 94 | + type: 'UPDATE_HPLCMS_INTEGRATIONS', |
| 95 | + payload: { |
| 96 | + spectrumId: selectedWaveLength, |
| 97 | + integration: { |
| 98 | + xExtent: { xL, xU }, |
| 99 | + data: spectrumData, |
| 100 | + }, |
| 101 | + }, |
| 102 | + }) |
| 103 | + } |
| 104 | + |
| 105 | + getAppState().then((stateAfter) => { |
| 106 | + const peaksAfter = stateAfter.hplcMs.uvvis.currentSpectrum?.peaks?.length || 0 |
| 107 | + const integrationsAfter = stateAfter.hplcMs.uvvis.currentSpectrum?.integrations?.length || 0 |
| 108 | + expect(peaksAfter).to.be.greaterThan(peaksBefore) |
| 109 | + expect(integrationsAfter).to.be.at.least(integrationsBefore) |
| 110 | + }) |
| 111 | + }) |
| 112 | + }) |
| 113 | + }) |
| 114 | + |
| 115 | + it('updates reducer when switching wavelength', () => { |
| 116 | + openLayout('LC/MS OpenLab') |
| 117 | + assertLcmsViewerIsStable() |
| 118 | + |
| 119 | + getAppState().then((stateBefore) => { |
| 120 | + const wavelengths = stateBefore.hplcMs.uvvis.listWaveLength || [] |
| 121 | + expect(wavelengths.length).to.be.greaterThan(1) |
| 122 | + const initialWaveLength = stateBefore.hplcMs.uvvis.selectedWaveLength |
| 123 | + const nextWaveLength = wavelengths.find((value) => value !== initialWaveLength) |
| 124 | + expect(nextWaveLength).to.not.equal(undefined) |
| 125 | + |
| 126 | + cy.contains('.MuiFormControl-root', 'Wavelength (nm)') |
| 127 | + .find('.MuiSelect-select') |
| 128 | + .click({ force: true }) |
| 129 | + cy.get('li[role="option"]') |
| 130 | + .contains(new RegExp(`^\\s*${nextWaveLength}\\s*$`)) |
| 131 | + .click({ force: true }) |
| 132 | + |
| 133 | + getAppState().then((stateAfter) => { |
| 134 | + expect(stateAfter.hplcMs.uvvis.selectedWaveLength).to.equal(nextWaveLength) |
| 135 | + expect(stateAfter.hplcMs.uvvis.currentSpectrum).to.not.equal(null) |
| 136 | + }) |
| 137 | + }) |
| 138 | + }) |
| 139 | + |
| 140 | + it('updates TIC polarity on Chemstation', () => { |
| 141 | + openLayout('LC/MS Chemstation') |
| 142 | + assertLcmsViewerIsStable() |
| 143 | + |
| 144 | + getAppState().then((stateBefore) => { |
| 145 | + const available = stateBefore.hplcMs.tic?.available || {} |
| 146 | + const currentPolarity = stateBefore.hplcMs.tic?.polarity |
| 147 | + const polarityOrder = ['positive', 'negative', 'neutral'] |
| 148 | + const nextPolarity = polarityOrder.find((value) => available[value] && value !== currentPolarity) |
| 149 | + if (!nextPolarity) return |
| 150 | + |
| 151 | + const uiLabelByPolarity: Record<string, string> = { |
| 152 | + positive: 'PLUS', |
| 153 | + negative: 'MINUS', |
| 154 | + neutral: 'NEUTRAL', |
| 155 | + } |
| 156 | + const nextLabel = uiLabelByPolarity[nextPolarity] |
| 157 | + |
| 158 | + cy.contains('.MuiFormControl-root', 'TIC') |
| 159 | + .find('.MuiSelect-select') |
| 160 | + .click({ force: true }) |
| 161 | + cy.get('li[role="option"]').contains(new RegExp(`^\\s*${nextLabel}\\s*$`)).click({ force: true }) |
| 162 | + |
| 163 | + getAppState().then((stateAfter) => { |
| 164 | + expect(stateAfter.hplcMs.tic.polarity).to.equal(nextPolarity) |
| 165 | + }) |
| 166 | + }) |
| 167 | + }) |
| 168 | + |
| 169 | + it('keeps zoom usable after leaving LC/MS', () => { |
| 170 | + openLayout('LC/MS OpenLab') |
| 171 | + assertLcmsViewerIsStable() |
| 172 | + |
| 173 | + cy.contains('button', 'NMR 1H').click() |
| 174 | + cy.get('.d3Line .d3Svg').should('exist') |
| 175 | + |
| 176 | + cy.window().then((win) => { |
| 177 | + cy.get('.btn-sv-bar-zoomin').click() |
| 178 | + cy.get('.d3Line .brush').should('exist') |
| 179 | + cy.get('.d3Line .d3Svg') |
| 180 | + .trigger('mousedown', 400, 100, { which: 1, view: win, force: true }) |
| 181 | + .trigger('mousemove', { clientX: 800, clientY: 1000, view: win, force: true }) |
| 182 | + .trigger('mouseup', { view: win, force: true }) |
| 183 | + |
| 184 | + cy.get('.btn-sv-bar-zoomreset').click() |
| 185 | + }) |
| 186 | + }) |
| 187 | +}) |
0 commit comments