Skip to content

Commit

Permalink
[???] Fix CI not loading the Inter font correctly
Browse files Browse the repository at this point in the history
- separate font-sensitive specs out to a separate file
  • Loading branch information
cee-chen committed Nov 1, 2023
1 parent ff2c50d commit 7f49976
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 158 deletions.
2 changes: 2 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ export default defineConfig({
video: false,
videoCompression: 32, // more time to process, but a smaller file to upload as an artifact
},

experimentalMemoryManagement: true, // We're starting to see Chromium Renderer crashes
});
180 changes: 180 additions & 0 deletions src/components/combo_box/combo_box.font.spec.tsx
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…');
});
});
});
});
158 changes: 0 additions & 158 deletions src/components/combo_box/combo_box.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,6 @@ import {
type EuiComboBoxOptionOption,
} from './index';

// CI doesn't have access to the Inter font, so we need to manually include it
// for truncation font calculations to work correctly
before(() => {
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('focus management', () => {
it('keeps focus on the input box when clicking a disabled item', () => {
Expand All @@ -57,62 +44,6 @@ 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: 121px;'
);
});

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: 67px;'
);

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: 387px;'
);
cy.get('[data-test-subj="comboBoxSearchInput"]')
.invoke('width')
.should('be.eq', 354);
});
});

describe('inputPopoverProps', () => {
it('allows setting a minimum popover width', () => {
cy.mount(
Expand Down Expand Up @@ -144,95 +75,6 @@ describe('EuiComboBox', () => {
});
});

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…');
});
});
});

describe('selection', () => {
const defaultOptions: Array<EuiComboBoxOptionOption<{}>> = [
{ label: 'Item 1' },
Expand Down

0 comments on commit 7f49976

Please sign in to comment.