Invision UI v.19.6.0-0

Getting Started

  • Running Invision UI
  • UI Component Anatomy
  • Authoring SCSS
  • Authoring Presentational Behavior

Component Foundations

  • SCSS Authoring
    • Mixins & Variables
    • Stateful Classes
  • State Guidance
    • Empty/Zero State
    • Loading State
  • Utilities
    • Align
    • Display
    • Flexbox
    • Font Size
    • Layout
    • Offset
    • Position
    • Overflow
    • Size
    • Spacing
    • Text
  • Layout
    • Arrange [Deprectated]
    • Divided Columns
    • Embed Video
    • Full and Center
    • Fill [Deprectated]
    • Grid
    • Media Blocks
    • Panels
    • Vertical Layouts
  • Media Queries
  • Angular Behaviors
    • App Theme Directive
    • Auto Focus Input
    • Filters
    • Popup (modal dialog) Manager
    • Tether (tooltip/dropdown) Manager
    • Resize Sensor
    • Watchers

UI Component Library

  • Content & Containment
    • Active Translation
    • Auto Fit Text
    • Address
    • Basic & Input Table
    • Brand Logo/Slogan
    • Call to Action - Empty State
    • Carousel
    • Cart
    • Choice
    • Collapsible Container
    • Copyright Footer
    • Coupon Redeemer
    • Content
    • Date Relative Display
    • Definition Lists
    • Delimited List
    • Details
    • Expiration Date Display
    • Feature Toggle
    • Form Section Heading
    • Header
    • Heading
    • Heading With Annotation
    • Icons
    • Interaction Details
    • Labeled Balance
    • Link
    • Main Container
    • Metadata Card
    • Metadata List Item
    • Offering QuickView
    • Payment Instrument
    • Preference Dialog
    • Pricing Plan Decoration
    • Product Availability
    • Product Details
    • Product Image
    • Quick Info Panel
    • Remark
    • Renewal Column
    • Richlist Filterbar
    • Richlist Wrapper
    • Scrollable Horizontal List
    • Search Card
    • Search Panel
    • Section
    • Selectable Option
    • Smart Truncate
    • Status Grid
    • Tooltip
  • Data Visualizations
    • Bill Runs
    • Comparison Table
    • Datatable
    • Progress Tracker
    • Schedules
    • Query Builder
  • Dialogs
    • Confirmation Dialog
    • Dialog
    • Rich List Dialog
    • Wait Dialog
  • Forms and Filters
    • Additional Properties
    • Autocomplete
    • 3 Field Date Input
    • Checkbox
    • Credit Card
    • Bulk Action Bar
    • Buttons
    • Confirmation Button
    • Date Picker
    • E-Check
    • Entity Specification
    • External Bill
    • External Gift Card
    • Focus Group
    • Forms
    • Filter Bar
    • Filter Dropdowns
    • Gift Card
    • Grouped Check Filters
    • Inputs
    • Input Select Combo
    • Monetary Input
    • Multi Dropdown Selector
    • Multiple Numeric Input
    • Monetary Range Input
    • Password Unmask Button
    • Select
    • Select Button Or Stepper
    • Select Or Text Input
    • Stepper
    • Tag Dropdown
  • Navigation & Flow
    • Back Banner
    • Back Component
    • Breadcrumbs
    • Details Pager
    • Expandable Section
    • Infinite Scroll
    • Open New Window
    • Pager
    • Fancy Richlist
    • Standard Navigator
    • Status Indicator
    • Step Progress Bar
    • Step Progress Indicator
    • Tab Card
    • Tab Panel
    • Tier Navigator
    • Wizard
  • Notifications
    • Loading Indicator
    • Toast Notifications
  • Deprecated
    • Content Area

Showcase

  • General
    • Simplelist
    • Richlist
    • Primary (side) Navigator
  • Customer Care
    • Case Activity List
    • Customer Care Navigator Component
    • Dashboard
    • Decisions
  • Reporting
    • Content Visualization

Unit Testing

  • Actions
  • Components
  • Selectors
  • Reducers

End-to-end Testing

Statistics

Unit Testing Components

In this section

Overview

Components often contain logic for formatting data either before it is displayed on the screen or before it is sent to the API. Those cases are also good candidates for testing as they use various control flow elements that alter the course of the function.

javascript
makePayment() {
    if (this.isAutoPay ||
        !this.selectedAccount ||
        !this.state.selectedPaymentMethod ||
        this.balanceIsInvalid()) {
        return;
    }

    const request = {
        customerId: this.state.currentCustomerId,
        request: {
            AccountNumber: this.selectedAccount.AccountNumber,
            PaymentInstrumentIds: [this.state.selectedPaymentMethod.Id],
            Amount: this.selectCurrentBalance === 'true'
                ? this.state.totalBalance
                : parseFloat(this.formApi.customDollarAmount.$modelValue)
        }
    };

    return this.actions.chargePaymentInstrument(request).then(() => {
        if (this.state.eWalletError) {
            uiNotificationService.error(i18n.translate(LocaleKeys.MAKE_PAYMENT.PAYMENT_FAILURE), null, { timeOut: NOTIFICATION_TIME_LENGTH });
            this.actions.resetIsMakingPayment();
        } else {
            this.actions.unregisterUnsavedChanges('CustomerMakePaymentController.formApi');
            this.goBack();
        }
    });
};

The above example is the function that actually charges a payment instrument for a subscriber. This is code block has lots of items that make it a good candidate for testing. To start with, there are several conditions in which the function should return before doing any processing (such as if autoPay is enabled, or there is no selected payment method.)

Beyond that, there is logic in place to determine what the balance should be (either the total balance or the custom dollar amount).

Finally, once the API call is made, one of two things can happen:

  1. An error is displayed an the form is reset
  2. No error is displayed and the user is redirected to the previous page If any of those behaviors don't happen, then make payment will have a bug.

Tests exist in the make.payment.component.spec.js file inside the customer care project.

javascript
describe('When making a payment', () => {
    function addPaymentStateToControl(controller, opts = {}) {
        controller.state.selectedPaymentMethod = { Id: 2 };
        controller.selectedAccount = { AccountNumber: '123' };
        controller.state.totalBalance = 100.00;
        controller.selectCurrentBalance = opts.selectCurrentBalance || 'true';
    }
    it('Should call the chargePaymentInstrument action', () => {
        const ctrl = createController();
        addPaymentStateToControl(ctrl);
        ctrl.makePayment();
        expect(fakeActions.chargePaymentInstrument.called).to.be.true;
    });
    it('Should use the customer id when charging', () => {
        const ctrl = createController();
        addPaymentStateToControl(ctrl);
        ctrl.makePayment();
        const request = fakeActions.chargePaymentInstrument.args[0][0];
        expect(request.customerId).to.eql(1);
    });
...
});

There are more tests for that function (represented by the ellipsis) but this shows examples of how the functionality is tested. Verifying that a user was charged, and verifying that the correct customer id was passed to the action.