import FileTreeCreateNameInput from '../../../../../../frontend/js/features/file-tree/components/file-tree-create/file-tree-create-name-input' import FileTreeCreateNameProvider from '../../../../../../frontend/js/features/file-tree/contexts/file-tree-create-name' describe('', function () { it('renders an empty input', function () { cy.mount( ) cy.findByLabelText('File Name') cy.findByPlaceholderText('File Name') }) it('renders a custom label and placeholder', function () { cy.mount( ) cy.findByLabelText('File name in this project') cy.findByPlaceholderText('Enter a file name…') }) it('uses an initial name', function () { cy.mount( ) cy.findByLabelText('File Name').should('have.value', 'test.tex') }) it('focuses the name', function () { cy.spy(window, 'requestAnimationFrame').as('requestAnimationFrame') cy.mount( ) cy.findByLabelText('File Name').as('input') cy.get('@input').should('have.value', 'test.tex') cy.get('@requestAnimationFrame').should('have.been.calledOnce') // https://github.com/jsdom/jsdom/issues/2995 // "window.getSelection doesn't work with selection of element" // const selection = window.getSelection().toString() // expect(selection).to.equal('test') // wait for the selection to update // eslint-disable-next-line cypress/no-unnecessary-waiting cy.wait(100) cy.get('@input').then(element => { expect(element.get(0).selectionStart).to.equal(0) expect(element.get(0).selectionEnd).to.equal(4) }) }) it('disables the input when in flight', function () { cy.mount( ).then(({ rerender }) => { cy.findByLabelText('File Name').should('not.be.disabled') rerender( ) cy.findByLabelText('File Name').should('be.disabled') rerender( ) cy.findByLabelText('File Name').should('not.be.disabled') }) }) })