Guest User

Untitled

a guest
Jan 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. <ltng:require scripts="{!join(',',$Resource.Constants,$Resource.Utils)}" afterScriptsLoaded="{!c.load}"/>
  2.  
  3. <aura:attribute name="currencyOptions" type="OppActionOverrideController.CurrencyOption[]" description="List of currency options with user's preferred currency set to default"/>
  4. <aura:attribute name="someOtherThing" type="String" description="This is just an example of something else to render"/>
  5.  
  6. <aura:attribute name="showCurrencyField" type="Boolean" default="false" description="Value set in the load() callback"/>
  7. <aura:attribute name="showSomeOtherField" type="Boolean" default="false" description="Value set in the load() callback"/>
  8.  
  9. <div class="slds-grid slds-wrap">
  10. <aura:if isTrue="{!v.showCurrencyField}">
  11. <div class="slds-form-element">
  12. <ui:inputSelect aura:id="selectedCurrency" label="Currency" required="true">
  13. <aura:iteration items="{!v.currencyOptions}" var="curr">
  14. <ui:inputSelectOption text="{!curr.isoCode}" label="{!curr.isoCode}" value="{!curr.isDefault}"/>
  15. </aura:iteration>
  16. </ui:inputSelect>
  17. </div>
  18. </aura:if>
  19.  
  20. <aura:if isTrue="{!v.showSomeOtherField}">
  21. <div aura:id="someOtherField">foobar</div>
  22. </aura:if>
  23. </div>
  24.  
  25. load: function (component, event, handler) {
  26. var action = component.get("c.getComponentData");
  27. action.setCallback(this, function(response) {
  28. // ....do some validation, if response is successful....
  29.  
  30. // set up currency options
  31. component.set('v.showCurrencyField', true);
  32. component.set('v.currencyOptions', currencyOptions);
  33.  
  34. // set other things
  35. component.set('v.showSomeOtherField', true);
  36. component.set('v.someOtherThing', 'hello');
  37. });
  38. $A.enqueueAction(action);
  39. }
  40.  
  41. afterEach(function() {
  42. $T.clearRenderedTestComponents();
  43. });
  44.  
  45. describe("Rendering the component", function() {
  46. var getComponentDataPayload = {
  47. currencyOptions: [
  48. {isoCode: "USD", isDefault: true},
  49. {isoCode: "EUR", isDefault: false},
  50. {isoCode: "GBP", isDefault: false},
  51. ]
  52. };
  53. var renderedComponent = null;
  54.  
  55. beforeEach(function(done) {
  56. renderedComponent = null;
  57.  
  58. $T.createComponent("c:MyComponent", {}, true)
  59. .then(function(component) {
  60. // I assign the component to a separate var so that it can be referenced in specs below, allows me to use a beforeEach instead of having this code in every spec
  61. renderedComponent = component;
  62.  
  63. spyOn($A, "enqueueAction").and.callFake(function(action) {
  64. var callback = action.getCallback("SUCCESS");
  65. // The utility function here just takes the payload data and wraps it with the proper getState() and getReturnValue(), etc.
  66. callback.fn.apply(callback.s, [TestUtils.getMockedServerActionResult(true, "", getComponentDataPayload)]);
  67. done();
  68. });
  69. }).catch(funtion(e) {
  70. done.fail(e);
  71. });
  72. });
  73.  
  74. it("renders the currency options", function(done) {
  75. expect(renderedComponent.find("selectedCurrency")).toBeDefined();
  76. done();
  77. });
  78.  
  79. it("renders some other field", function(done) {
  80. expect(renderedComponent.find("someOtherField")).toBeDefined();
  81. done();
  82. });
  83. });
Add Comment
Please, Sign In to add comment