From 998ecb1e20192e99acd4e2cb1ded0a27a8cc18ee Mon Sep 17 00:00:00 2001 From: Cee Chen Date: Mon, 18 Sep 2023 12:27:08 -0700 Subject: [PATCH] Add tests --- src/components/combo_box/combo_box.spec.tsx | 91 +++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/src/components/combo_box/combo_box.spec.tsx b/src/components/combo_box/combo_box.spec.tsx index 3266c16d207..54ce0f22617 100644 --- a/src/components/combo_box/combo_box.spec.tsx +++ b/src/components/combo_box/combo_box.spec.tsx @@ -37,6 +37,97 @@ describe('EuiComboBox', () => { }); }); + describe('truncation', () => { + const sharedProps = { + style: { width: 200 }, + options: [ + { label: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.' }, + ], + }; + + it('defaults to end truncation', () => { + cy.realMount(); + cy.get('[data-test-subj="comboBoxInput"]').realClick(); + cy.get('[data-test-subj="truncatedText"]').should( + 'have.text', + 'Lorem ipsum dolor sit a…' + ); + }); + + it('allows customizing truncationProps', () => { + cy.realMount( + + ); + cy.get('[data-test-subj="comboBoxInput"]').realClick(); + cy.get('[data-test-subj="truncatedText"]').should( + 'have.text', + 'Lorem ipsum …piscing elit.' + ); + }); + + it('allows individual option truncationProps to override parent truncationProps', () => { + cy.realMount( + + ); + cy.get('[data-test-subj="comboBoxInput"]').realClick(); + cy.get('[data-test-subj="truncatedText"]').should( + 'have.text', + 'Lorem…tur adipiscing elit.' + ); + }); + + describe('when searching', () => { + it('uses start & end truncation position', () => { + cy.realMount(); + cy.get('[data-test-subj="comboBoxInput"]').realClick(); + cy.realType('sit'); + cy.get('[data-test-subj="truncatedText"]').should( + 'have.text', + '…sum dolor sit amet, co…' + ); + }); + + it('does not truncate the start when the found search is near the start', () => { + cy.realMount(); + cy.get('[data-test-subj="comboBoxInput"]').realClick(); + cy.realType('ipsum'); + cy.get('[data-test-subj="truncatedText"]').should( + 'have.text', + 'Lorem ipsum dolor sit a…' + ); + }); + + it('does not truncate the end when the found search is near the end', () => { + cy.realMount(); + cy.get('[data-test-subj="comboBoxInput"]').realClick(); + cy.realType('eli'); + cy.get('[data-test-subj="truncatedText"]').should( + 'have.text', + '…nsectetur adipiscing elit.' + ); + }); + + it('marks the full available text if the search input is longer than the truncated text', () => { + cy.realMount(); + cy.get('[data-test-subj="comboBoxInput"]').realClick(); + cy.realType('Lorem ipsum dolor sit amet'); + cy.get('.euiMark').should('have.text', '…rem ipsum dolor sit am…'); + }); + }); + }); + describe('Backspace to delete last pill', () => { const options = [ { label: 'Item 1' },