Skip to content

Commit

Permalink
Fix package title selection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Cherewaty committed Oct 19, 2017
1 parent e1ad22f commit 30cd158
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/components/customer-resource-show.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ export default function CustomerResourceShow({ customerResource, toggleRequest,

<hr />

<label htmlFor="customer-resource-show-toggle-switch">
<label
data-test-eholdings-customer-resource-show-selected
htmlFor="customer-resource-show-toggle-switch"
>
<h4>{record.isSelected ? 'Selected' : 'Not Selected'}</h4>
<ToggleSwitch
onChange={toggleSelected}
Expand Down
9 changes: 5 additions & 4 deletions src/components/toggle-switch/toggle-switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ const cx = classNames.bind(styles);

export default function ToggleSwitch(props) {
return (
<div className={cx(styles['toggle-switch'], {
'is-pending': props.isPending
})}
<div
data-test-toggle-switch
className={cx(styles['toggle-switch'], {
'is-pending': props.isPending
})}
>
<input
type="checkbox"
Expand All @@ -30,4 +32,3 @@ ToggleSwitch.propTypes = {
isPending: PropTypes.bool,
id: PropTypes.string
};

39 changes: 34 additions & 5 deletions tests/customer-resource-show-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import it from './it-will';
import { describeApplication } from './helpers';
import ResourcePage from './pages/customer-resource-show';

describeApplication('CustomerResourceShow', () => {
describeApplication.only('CustomerResourceShow', () => {
let vendor,
vendorPackage,
resource;
Expand Down Expand Up @@ -76,7 +76,7 @@ describeApplication('CustomerResourceShow', () => {
expect(ResourcePage.isSelected).to.equal(false);
});

describe('selecting a package title to add to my holdings', () => {
describe('successfully selecting a package title to add to my holdings', () => {
beforeEach(function () {
/*
* The expectations in the convergent `it` blocks
Expand All @@ -95,7 +95,7 @@ describeApplication('CustomerResourceShow', () => {
this.server.timing = 0;
});

it('reflects the desired state (YES)', () => {
it('reflects the desired state (Selected)', () => {
expect(ResourcePage.isSelected).to.equal(true);
});

Expand All @@ -116,9 +116,38 @@ describeApplication('CustomerResourceShow', () => {
expect(ResourcePage.isSelecting).to.equal(false);
});
});
});

describe('unsuccessfully selecting a package title to add to my holdings', () => {
beforeEach(function () {
this.server.put('/vendors/:vendorId/packages/:packageId/titles/:titleId', [{
message: 'There was an error',
code: '1000',
subcode: 0
}], 500);

this.server.timing = 50;
return ResourcePage.toggleIsSelected();
});

afterEach(function () {
this.server.timing = 0;
});

it('reflects the desired state (Selected)', () => {
expect(ResourcePage.isSelected).to.equal(true);
});

it('indicates it working to get to desired state', () => {
expect(ResourcePage.isSelecting).to.equal(true);
});

describe('when the request fails', () => {
it('does not change to new state', () => {
it('cannot be interacted with while the request is in flight', () => {
expect(ResourcePage.isSelectedToggleable).to.equal(false);
});

describe('when the request succeeds', () => {
it('reflect the desired state was set', () => {
expect(ResourcePage.isSelected).to.equal(false);
});

Expand Down
4 changes: 2 additions & 2 deletions tests/pages/customer-resource-show.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default {
},

get isSelected() {
return $('[data-test-eholdings-customer-resource-show-selected]').text() === 'Yes';
return $('[data-test-eholdings-customer-resource-show-selected]').text() === 'Selected';
},

toggleIsSelected() {
Expand All @@ -60,7 +60,7 @@ export default {
},

get isSelecting() {
return $('[data-test-eholdings-customer-resource-show-is-selecting]').length > 0;
return $('[data-test-eholdings-customer-resource-show-selected] [data-test-toggle-switch]').attr('class').indexOf('is-pending--') !== -1;
},

get isSelectedToggleable() {
Expand Down

0 comments on commit 30cd158

Please sign in to comment.