Skip to content

Commit

Permalink
fix: hide NMRium button on non-NMR layouts
Browse files Browse the repository at this point in the history
Co-authored-by: Lan Le <[email protected]>

Refs: #1460
  • Loading branch information
baolanlequang authored Aug 17, 2023
1 parent aa30d08 commit f75d554
Show file tree
Hide file tree
Showing 4 changed files with 382 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { stopBubble } from 'src/utilities/DomHelper';
import ImageModal from 'src/components/common/ImageModal';
import SpectraActions from 'src/stores/alt/actions/SpectraActions';
import LoadingActions from 'src/stores/alt/actions/LoadingActions';
import { BuildSpcInfos, JcampIds, BuildSpcInfosForNMRDisplayer } from 'src/utilities/SpectraHelper';
import { BuildSpcInfos, JcampIds, BuildSpcInfosForNMRDisplayer, isNMRKind } from 'src/utilities/SpectraHelper';
import { hNmrCheckMsg, cNmrCheckMsg, msCheckMsg, instrumentText } from 'src/utilities/ElementUtils';
import { contentToText } from 'src/utilities/quillFormat';
import UIStore from 'src/stores/alt/stores/UIStore';
Expand Down Expand Up @@ -56,13 +56,6 @@ const qCheckMsg = (sample, container) => {
return '';
};

const isNMRKind = (container) => {
if (container.extended_metadata.kind) {
return container.extended_metadata.kind.includes('NMR');
}
return false;
}

const SpectraEditorBtn = ({
sample, spcInfos, hasJcamp, hasChemSpectra,
toggleSpectraModal, confirmRegenerate, confirmRegenerateEdited, hasEditedJcamp,
Expand Down Expand Up @@ -305,8 +298,7 @@ const headerBtnGroup = (
}

const { hasChemSpectra, hasNmriumWrapper } = UIStore.getState();
// const hasNMRium = isNMRKind(container) && hasNmriumWrapper;
const hasNMRium = hasNmriumWrapper;
const hasNMRium = isNMRKind(container) && hasNmriumWrapper;

return (
<div className="upper-btn">
Expand Down
17 changes: 12 additions & 5 deletions app/packs/src/utilities/SpectraHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const extractJcampWithFailedFiles = (container) => {
const isJcamp = acceptables.indexOf(ext.toLowerCase()) >= 0;
const isApp = [
'idle', 'queueing', 'done',
'backup', 'image','non_jcamp',
'backup', 'image', 'non_jcamp',
].indexOf(att.aasm_state) < 0;
if (isJcamp && isApp) {
const file = Object.assign({}, att, {
Expand All @@ -90,7 +90,7 @@ const extractNMRiumFiles = (container) => {
const fns = att.filename.split('.');
const ext = fns[fns.length - 1];
const isNMRium = ext.toLowerCase() === 'nmrium';

if (isNMRium) {
const file = Object.assign({}, att, {
idDt: dt.id,
Expand Down Expand Up @@ -122,7 +122,7 @@ const BuildSpcInfos = (sample, container) => {
const files = extractJcampFiles(container);
if (files.length < 1) return [];
const idAe = extractAnalysesId(sample, container);
return files.map(file => (
return files.map((file) => (
{
value: null,
label: file.filename,
Expand All @@ -143,7 +143,7 @@ const BuildSpcInfosForNMRDisplayer = (sample, container) => {
files.push(...nmriumFiles);
if (files.length < 1) return [];
const idAe = extractAnalysesId(sample, container);
return files.map(file => (
return files.map((file) => (
{
value: null,
label: file.filename,
Expand All @@ -157,4 +157,11 @@ const BuildSpcInfosForNMRDisplayer = (sample, container) => {
));
};

export { BuildSpcInfos, BuildSpcInfosForNMRDisplayer, JcampIds }; // eslint-disable-line
const isNMRKind = (container) => {
if (!(container && container.extended_metadata && container.extended_metadata.kind)) return false;
const { extended_metadata } = container; // eslint-disable-line
const { kind } = extended_metadata; // eslint-disable-line
return kind.toLowerCase().includes('nuclear magnetic resonance');
};

export { BuildSpcInfos, BuildSpcInfosForNMRDisplayer, JcampIds, isNMRKind }; // eslint-disable-line
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import React from 'react';
import expect from 'expect';
import Enzyme, { mount, shallow } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import {
describe, it, beforeEach
} from 'mocha';

import {
HeaderDeleted, HeaderNormal
} from 'src/apps/mydb/elements/details/samples/analysesTab/SampleDetailsContainersAux';

import Container from 'src/models/Container';
import Sample from 'src/models/Sample';

Enzyme.configure({ adapter: new Adapter() });

describe('SampleDetailsContainersAux', () => {
describe('HeaderDeleted', () => {
describe('Render without edit mode', () => {
let container;
beforeEach(() => {
container = Container.buildEmpty();
container.name = 'Just a string';
});

it('Render without kind and status', () => {
const wrapper = shallow(<HeaderDeleted container={container} />);
expect(wrapper.html())
.toEqual(`<div class="analysis-header-delete"><strike>${container.name}</strike><div class="button-right undo-middle"></div></div>`);
});

it('Render with kind', () => {
container.extended_metadata.kind = 'Just a kind string';
const wrapper = shallow(<HeaderDeleted container={container} />);
expect(wrapper.html())
.toEqual(`<div class="analysis-header-delete"><strike>${container.name} - Type: ${container.extended_metadata.kind}</strike><div class="button-right undo-middle"></div></div>`);
});

it('Render with status', () => {
container.extended_metadata.status = 'Just a status string';
const wrapper = shallow(<HeaderDeleted container={container} />);
expect(wrapper.html())
.toEqual(`<div class="analysis-header-delete"><strike>${container.name} - Status: ${container.extended_metadata.status}</strike><div class="button-right undo-middle"></div></div>`);
});

it('Render with kind and status', () => {
container.extended_metadata.kind = 'Just a kind string';
container.extended_metadata.status = 'Just a status string';
const wrapper = shallow(<HeaderDeleted container={container} />);
expect(wrapper.html())
.toEqual(`<div class="analysis-header-delete"><strike>${container.name} - Type: ${container.extended_metadata.kind} - Status: ${container.extended_metadata.status}</strike><div class="button-right undo-middle"></div></div>`);
});
});

describe('Render with edit mode', () => {
const container = Container.buildEmpty();
container.name = 'Just a string';

it('Render without kind and status', () => {
const wrapper = shallow(<HeaderDeleted container={container} mode="edit" />);
expect(wrapper.html())
.toEqual(`<div class="analysis-header-delete"><strike>${container.name}</strike><div class="button-right undo-middle"><button type="button" class="pull-right btn btn-xs btn-danger"><i class="fa fa-undo"></i></button></div></div>`);
});

it('Check on click instance', () => {
const testOnClick = () => {};
const wrapper = mount(<HeaderDeleted container={container} mode="edit" handleUndo={testOnClick} />);
const button = wrapper.find('button');
const onClickProp = button.prop('onClick');
expect(onClickProp).toBeInstanceOf(Function);
});
});
});

describe('HeaderNormal', () => {
describe('Render without edit mode', () => {
let container; let
sample;

beforeEach(() => {
container = Container.buildEmpty();
container.name = 'Just a string';
sample = Sample.buildEmpty();
});

it('Render without status', () => {
const wrapper = shallow(<HeaderNormal container={container} sample={sample} />);
const statusWrapper = shallow(<div className="sub-title">
Status:
{' '}
{container.extended_metadata.status}
{' '}

{' '}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{' '}

</div>);
expect(wrapper.html())
.toEqual(`<div class="analysis-header order"><div class="preview"><div class="preview-table"><img src="/images/wild_card/no_attachment.svg" alt="" style="cursor:default"/></div></div><div class="abstract"><div class="lower-text"><div class="main-title">${container.name}</div><div class="sub-title">Type: </div>${statusWrapper.html()}<div class="desc sub-title"><span style="float:left;margin-right:5px">Content:</span><span></span></div></div></div></div>`);
});
});
});
});
Loading

0 comments on commit f75d554

Please sign in to comment.