Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ltng:require scripts="{!join(',',$Resource.Constants,$Resource.Utils)}" afterScriptsLoaded="{!c.load}"/>
- <aura:attribute name="currencyOptions" type="OppActionOverrideController.CurrencyOption[]" description="List of currency options with user's preferred currency set to default"/>
- <aura:attribute name="someOtherThing" type="String" description="This is just an example of something else to render"/>
- <aura:attribute name="showCurrencyField" type="Boolean" default="false" description="Value set in the load() callback"/>
- <aura:attribute name="showSomeOtherField" type="Boolean" default="false" description="Value set in the load() callback"/>
- <div class="slds-grid slds-wrap">
- <aura:if isTrue="{!v.showCurrencyField}">
- <div class="slds-form-element">
- <ui:inputSelect aura:id="selectedCurrency" label="Currency" required="true">
- <aura:iteration items="{!v.currencyOptions}" var="curr">
- <ui:inputSelectOption text="{!curr.isoCode}" label="{!curr.isoCode}" value="{!curr.isDefault}"/>
- </aura:iteration>
- </ui:inputSelect>
- </div>
- </aura:if>
- <aura:if isTrue="{!v.showSomeOtherField}">
- <div aura:id="someOtherField">foobar</div>
- </aura:if>
- </div>
- load: function (component, event, handler) {
- var action = component.get("c.getComponentData");
- action.setCallback(this, function(response) {
- // ....do some validation, if response is successful....
- // set up currency options
- component.set('v.showCurrencyField', true);
- component.set('v.currencyOptions', currencyOptions);
- // set other things
- component.set('v.showSomeOtherField', true);
- component.set('v.someOtherThing', 'hello');
- });
- $A.enqueueAction(action);
- }
- afterEach(function() {
- $T.clearRenderedTestComponents();
- });
- describe("Rendering the component", function() {
- var getComponentDataPayload = {
- currencyOptions: [
- {isoCode: "USD", isDefault: true},
- {isoCode: "EUR", isDefault: false},
- {isoCode: "GBP", isDefault: false},
- ]
- };
- var renderedComponent = null;
- beforeEach(function(done) {
- renderedComponent = null;
- $T.createComponent("c:MyComponent", {}, true)
- .then(function(component) {
- // 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
- renderedComponent = component;
- spyOn($A, "enqueueAction").and.callFake(function(action) {
- var callback = action.getCallback("SUCCESS");
- // The utility function here just takes the payload data and wraps it with the proper getState() and getReturnValue(), etc.
- callback.fn.apply(callback.s, [TestUtils.getMockedServerActionResult(true, "", getComponentDataPayload)]);
- done();
- });
- }).catch(funtion(e) {
- done.fail(e);
- });
- });
- it("renders the currency options", function(done) {
- expect(renderedComponent.find("selectedCurrency")).toBeDefined();
- done();
- });
- it("renders some other field", function(done) {
- expect(renderedComponent.find("someOtherField")).toBeDefined();
- done();
- });
- });
Add Comment
Please, Sign In to add comment