Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: bhCurrencyInput to validate currencies #95

Merged

Conversation

jniles
Copy link
Collaborator

@jniles jniles commented Feb 10, 2016

Component: bhCurrencyInput

This PR adds a currency input component (bhCurrencyInput) that uses the CurrencyService to validate currency inputs automatically. It takes in four bindings:

  • model (two-way binding)
    The ng-model for the input. These changes are reflected in the parent
    controller
  • currencyId (one-way binding)
    The currency id selected to validate the currency input with. This is
    selected elsewhere, but bound so that changes will propigate to
    change the validation state.
  • form (one-way binding)
    The parent form in which the input resides. Used for validation
    triggers.
  • validationTrigger (one-way binding)
    The trigger for when to show error messages.

The developer is expected to provide all of the above options. The currency input should be used in the form like this:

<bh-currency-input
  model="ctrl.model"
  currency-id="ctrl.currencyId"
  form="ParentControllerFormName"
  validation-trigger="ParentControllerFormName.$submitted">
</bh-currency-input>

Test Hooks

This PR also includes test hooks for developers to rapidly use the input in tests, without having to know the underlying details. You should be able to use it as follows:

// import from shared components file
var components = require('../shared/components');

it('works like a charm', function () {

  // sets the input value to an amount
  components.currencyInput.set(1500);

  // retrieves the value from the component.
  expect(components.currencyInput.get()).to.eventually.equal(1500);
});

Currency API

To keep with our current model of consuming APIs, this PR also introduces a /currencies API , which includes two methods:

  • GET /currencies
  • GET /currencies/:id

This new API replaces the previous route /finance/currencies and all client-side routes have been migrated to using /currencies. I've included integration tests as proof of work.

Closes #72. Closes #90.

@jniles
Copy link
Collaborator Author

jniles commented Feb 10, 2016

@IMA-WorldHealth/local-contributors, all those working on components may want to look at this code for inspiration. It demonstrates:

  1. Angular v1.5's angular.component() instead of using a directive.
  2. How to write a test wrapper for a component and use in an e2e test (cash.spec.js)
  3. How to document your component's usage, both in modules and in e2e tests.

@sfount, let me know if there is anything I can clear up in the PR text or the tests.

@jniles jniles force-pushed the bh-currency-input-component branch 3 times, most recently from 5bc818a to 3620be2 Compare February 11, 2016 08:30
@jniles
Copy link
Collaborator Author

jniles commented Feb 11, 2016

@sfount, could I get a review?

@jniles jniles mentioned this pull request Feb 11, 2016
This commit adds a currency input crmponent (bhCurrencyInput) that uses
the CurrencyService to validate currency inputs automatically.  It takes
in four bindings:
  - model (two-way binding)
  The ng-model for the input.  These changes are reflected in the parent
  controller
  - currencyId (one-way binding)
  The currency id selected to validate the currency input with.  This is
  selected elsewhere, but bound so that changes will propigate to
  change the validation state.
  - form (one-way binding)
  The parent form in which the input resides.  Used for validation
  triggers.
  - validationTrigger (one-way binding)
  The trigger for when to show error messages.

The developer is expected to provide all of the above options.  The
currency input should be used in the form like this:

<pre>
<bh-currency-input model="ctrl.model" currency-id="ctrl.currencyId"
form="ParentControllerFormName"
validation-trigger="ParentControllerFormName.$submitted">
</bh-currency-input>
</pre>
This commit includes a wrapper for the bhCurrencyInput component to
allow developers to rapidly set and get the value without having to know
the appropriate selectors for it.

USAGE:
```js

var components = require('../shared/components');

it('works like a charm', function () {
  components.currencyInput.set(1500);
  expect(components.currencyInput.get()).to.eventually.equal(true);
});

```
* Sets the value of the currency input.
*/
set : function set(value) {
var elm = element(by.css(this.selector));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This idea of test utilities for directives is an excellent idea going forward. Very cleanly implemented.

sfount added a commit that referenced this pull request Feb 11, 2016
Feat: bhCurrencyInput to validate currencies
@sfount sfount merged commit 4e59b32 into Third-Culture-Software:master Feb 11, 2016
@jniles jniles deleted the bh-currency-input-component branch February 11, 2016 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants