I am trying to write the test cases for the buttons enable or disable.
<button type="button" id="addBtn" className={`btn border-0 create-job-btn ${enabled ? 'add-btn' : 'jd-button'}`} disabled={!enabled} >Add/Paste Jd</button>
<span className="pl-1 pr-1"> or </span>
<button type="button" id="uploadBtn" className={`btn border-0 create-job-btn ${enabled ? "upload-btn" : "jd-button"}`} disabled={!enabled} >Upload Jd File</button>
Now, what I tried is,
it('should have buttons', () => {
const wrapper = shallow(<SelectCriteraNewJob />);
expect(wrapper.find('button#addBtn')).toBeTruthy();
expect(wrapper.find('button#uploadBtn')).toBeTruthy();
});
Now Here,
const enabled = (!!selectedTechnology && selectedTechnology.length > 0) && (!!userCompany && userCompany.length > 0)
So, I am confused in writting the test cases for the buttons enable and disable
.
So, can any one help me with this ? Thanks.
Observing what your component renders, there seems to be three things to test:
The primary test case is the 'enabled' case. Testing classNames or not is up to you, it's mostly not necessary to test inline styles or css classes.
It seems that both buttons are disabled if
userCompany
and/orselectedTechnology
aren't given, and if they're both given, both buttons are enabled.You can observe the 'disabled' prop of the html buttons, according to the state & prop you have given to the component.