-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[???] Fix CI not loading the Inter font correctly
- separate font-sensitive specs out to a separate file
- Loading branch information
Showing
3 changed files
with
182 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
/// <reference types="cypress" /> | ||
/// <reference types="cypress-real-events" /> | ||
/// <reference types="../../../cypress/support" /> | ||
|
||
import React from 'react'; | ||
|
||
import { EuiComboBox } from './index'; | ||
|
||
/** | ||
* Font dependent tests - | ||
* CI doesn't have access to the Inter font, so we need to manually include it | ||
* for truncation font calculations to work correctly. | ||
* For some reason Cypress on CI stops correctly loading the font when too many | ||
* tests are added (memory issues?), so we separate out these tests to their own file | ||
*/ | ||
beforeEach(() => { | ||
const linkElem = document.createElement('link'); | ||
linkElem.setAttribute('rel', 'stylesheet'); | ||
linkElem.setAttribute( | ||
'href', | ||
'https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap' | ||
); | ||
document.head.appendChild(linkElem); | ||
cy.wait(1000); // Wait a second to give the font time to load/swap in | ||
}); | ||
|
||
describe('EuiComboBox', () => { | ||
describe('input auto sizing', () => { | ||
it('resizes the width of the input based to fit the search text', () => { | ||
cy.realMount(<EuiComboBox options={[]} />); | ||
cy.get('[data-test-subj="comboBoxSearchInput"]').should( | ||
'have.attr', | ||
'style', | ||
'inline-size: 2px;' | ||
); | ||
|
||
cy.get('[data-test-subj="comboBoxSearchInput"]').realClick(); | ||
cy.realType('lorem ipsum dolor'); | ||
cy.get('[data-test-subj="comboBoxSearchInput"]').should( | ||
'have.attr', | ||
'style', | ||
'inline-size: 119px;' | ||
); | ||
}); | ||
|
||
it('correctly resets the input size when the search value is cleared', () => { | ||
cy.realMount(<EuiComboBox options={[{ label: 'Test 1 2 3' }]} />); | ||
cy.get('[data-test-subj="comboBoxSearchInput"]').realClick(); | ||
|
||
cy.realType('Test 1 2 3'); | ||
cy.get('[data-test-subj="comboBoxSearchInput"]').should( | ||
'have.attr', | ||
'style', | ||
'inline-size: 64px;' | ||
); | ||
|
||
cy.realPress('{downarrow}'); | ||
cy.realPress('Enter'); | ||
cy.get('[data-test-subj="comboBoxSearchInput"]').should( | ||
'have.attr', | ||
'style', | ||
'inline-size: 2px;' | ||
); | ||
}); | ||
|
||
it('does not exceed the maximum possible width of the input wrapper', () => { | ||
cy.realMount(<EuiComboBox options={[]} />); | ||
cy.get('[data-test-subj="comboBoxSearchInput"]').realClick(); | ||
cy.realType( | ||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit......' | ||
); | ||
|
||
cy.get('[data-test-subj="comboBoxSearchInput"]').should( | ||
'have.attr', | ||
'style', | ||
'inline-size: 380px;' | ||
); | ||
cy.get('[data-test-subj="comboBoxSearchInput"]') | ||
.invoke('width') | ||
.should('be.eq', 354); | ||
}); | ||
}); | ||
|
||
describe('truncation', () => { | ||
const sharedProps = { | ||
style: { width: 200 }, | ||
options: [ | ||
{ label: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.' }, | ||
], | ||
}; | ||
|
||
it('defaults to CSS truncation', () => { | ||
cy.realMount(<EuiComboBox {...sharedProps} />); | ||
cy.get('[data-test-subj="comboBoxInput"]').realClick(); | ||
cy.get('.euiTextTruncate').should('not.exist'); | ||
}); | ||
|
||
it('renders EuiTextTruncate when truncationProps are passed', () => { | ||
cy.realMount( | ||
<EuiComboBox | ||
{...sharedProps} | ||
truncationProps={{ truncation: 'middle' }} | ||
/> | ||
); | ||
cy.get('[data-test-subj="comboBoxInput"]').realClick(); | ||
cy.get('.euiTextTruncate').should('exist'); | ||
cy.get('[data-test-subj="truncatedText"]').should( | ||
'have.text', | ||
'Lorem ipsum …piscing elit.' | ||
); | ||
}); | ||
|
||
it('allows individual option truncationProps to override parent truncationProps', () => { | ||
cy.realMount( | ||
<EuiComboBox | ||
{...sharedProps} | ||
truncationProps={{ truncation: 'middle' }} | ||
options={[ | ||
{ | ||
...sharedProps.options[0], | ||
truncationProps: { truncation: 'start', truncationOffset: 5 }, | ||
}, | ||
]} | ||
/> | ||
); | ||
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(<EuiComboBox {...sharedProps} />); | ||
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(<EuiComboBox {...sharedProps} />); | ||
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(<EuiComboBox {...sharedProps} />); | ||
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(<EuiComboBox {...sharedProps} />); | ||
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…'); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters