|
| 1 | +/** |
| 2 | + * Copyright IBM Corp. 2016, 2018 |
| 3 | + * |
| 4 | + * This source code is licensed under the Apache-2.0 license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +import 'carbon-components/scss/components/combo-box/_combo-box.scss'; |
| 9 | +import 'carbon-components/scss/components/list-box/_list-box.scss'; |
| 10 | +import 'carbon-components/scss/components/text-input/_text-input.scss'; |
| 11 | + |
| 12 | +import React from 'react'; |
| 13 | +import { mount } from '@cypress/react'; |
| 14 | +import ComboBox from './ComboBox'; |
| 15 | + |
| 16 | +describe('ComboBox', () => { |
| 17 | + beforeEach(() => { |
| 18 | + const items = [ |
| 19 | + { |
| 20 | + id: 'option-0', |
| 21 | + text: |
| 22 | + 'An example option that is really long to show what should be done to handle long text', |
| 23 | + }, |
| 24 | + { |
| 25 | + id: 'option-1', |
| 26 | + text: 'Option 1', |
| 27 | + }, |
| 28 | + { |
| 29 | + id: 'option-2', |
| 30 | + text: 'Option 2', |
| 31 | + }, |
| 32 | + { |
| 33 | + id: 'option-3', |
| 34 | + text: 'Option 3', |
| 35 | + }, |
| 36 | + { |
| 37 | + id: 'option-4', |
| 38 | + text: 'Option 4', |
| 39 | + }, |
| 40 | + { |
| 41 | + id: 'option-5', |
| 42 | + text: 'Option 5', |
| 43 | + }, |
| 44 | + ]; |
| 45 | + |
| 46 | + mount( |
| 47 | + <> |
| 48 | + <div style={{ marginBottom: '2rem' }}> |
| 49 | + <ComboBox |
| 50 | + onChange={() => {}} |
| 51 | + id="carbon-combobox" |
| 52 | + items={items} |
| 53 | + itemToString={(item) => (item ? item.text : '')} |
| 54 | + placeholder="Filter..." |
| 55 | + titleText="Default combobox" |
| 56 | + helperText="Optional combobox helper text" |
| 57 | + /> |
| 58 | + </div> |
| 59 | + <div style={{ marginBottom: '2rem' }}> |
| 60 | + <ComboBox |
| 61 | + onChange={() => {}} |
| 62 | + id="carbon-combobox" |
| 63 | + items={items} |
| 64 | + itemToString={(item) => (item ? item.text : '')} |
| 65 | + placeholder="Filter..." |
| 66 | + titleText="Small combobox" |
| 67 | + helperText="Combobox helper text" |
| 68 | + size="sm" |
| 69 | + /> |
| 70 | + </div> |
| 71 | + <div style={{ marginBottom: '2rem' }}> |
| 72 | + <ComboBox |
| 73 | + onChange={() => {}} |
| 74 | + id="carbon-combobox" |
| 75 | + items={items} |
| 76 | + itemToString={(item) => (item ? item.text : '')} |
| 77 | + placeholder="Filter..." |
| 78 | + titleText="Large combobox" |
| 79 | + helperText="Combobox helper text" |
| 80 | + size="lg" |
| 81 | + /> |
| 82 | + </div> |
| 83 | + <div style={{ marginBottom: '2rem' }}> |
| 84 | + <ComboBox |
| 85 | + onChange={() => {}} |
| 86 | + id="carbon-combobox" |
| 87 | + items={items} |
| 88 | + itemToString={(item) => (item ? item.text : '')} |
| 89 | + placeholder="Filter..." |
| 90 | + titleText="Disabled combobox" |
| 91 | + helperText="Combobox helper text" |
| 92 | + disabled |
| 93 | + /> |
| 94 | + </div> |
| 95 | + <div style={{ marginBottom: '2rem' }}> |
| 96 | + <ComboBox |
| 97 | + onChange={() => {}} |
| 98 | + id="carbon-combobox" |
| 99 | + items={items} |
| 100 | + itemToString={(item) => (item ? item.text : '')} |
| 101 | + placeholder="Filter..." |
| 102 | + titleText="Light combobox" |
| 103 | + helperText="Combobox helper text" |
| 104 | + light |
| 105 | + /> |
| 106 | + </div> |
| 107 | + <div style={{ marginBottom: '2rem' }}> |
| 108 | + <ComboBox |
| 109 | + onChange={() => {}} |
| 110 | + id="carbon-combobox" |
| 111 | + items={items} |
| 112 | + itemToString={(item) => (item ? item.text : '')} |
| 113 | + placeholder="Filter..." |
| 114 | + titleText="Combobox with warning state" |
| 115 | + helperText="Combobox helper text" |
| 116 | + warn |
| 117 | + warnText="Warning state message here" |
| 118 | + /> |
| 119 | + </div> |
| 120 | + <div style={{ marginBottom: 8 }}> |
| 121 | + <ComboBox |
| 122 | + onChange={() => {}} |
| 123 | + id="carbon-combobox" |
| 124 | + items={items} |
| 125 | + itemToString={(item) => (item ? item.text : '')} |
| 126 | + placeholder="Filter..." |
| 127 | + titleText="Combobox with invalid state" |
| 128 | + helperText="Combobox with invalid state" |
| 129 | + invalid |
| 130 | + invalidText="Invalid text message here" |
| 131 | + /> |
| 132 | + </div> |
| 133 | + </> |
| 134 | + ); |
| 135 | + }); |
| 136 | + |
| 137 | + it('should render', () => { |
| 138 | + cy.findByText(/Optional/).should('be.visible'); |
| 139 | + |
| 140 | + // snapshots should always be taken _after_ an assertion that |
| 141 | + // a element/component should be visible. This is to ensure |
| 142 | + // the DOM has settled and the element has fully loaded. |
| 143 | + cy.percySnapshot(); |
| 144 | + }); |
| 145 | + |
| 146 | + it('should open on click and display list items', () => { |
| 147 | + cy.findAllByRole('button').first().click(); |
| 148 | + cy.findAllByText(/Option 1/) |
| 149 | + .first() |
| 150 | + .should('be.visible'); |
| 151 | + |
| 152 | + // snapshots should always be taken _after_ an assertion that |
| 153 | + // a element/component should be visible. This is to ensure |
| 154 | + // the DOM has settled and the element has fully loaded. |
| 155 | + cy.percySnapshot(); |
| 156 | + }); |
| 157 | +}); |
0 commit comments