From 32ad43834699322b6620f8d560c16ee2d5e0e8d7 Mon Sep 17 00:00:00 2001 From: Adam Stone Date: Wed, 15 Jun 2022 20:59:19 -0400 Subject: [PATCH] feat: Auto-focus and select file name for create new spec modal (#22284) * feat: Auto-focus and select file name for create new spec modal * feat: Add comment for regex * feat: Remove comma; add new line * feat: Remove unnecessary function * feat: Remove unnecessary logic * feat: Reference prop value rather than input ref value * feat: Add component test for unhappy path Co-authored-by: Zachary Williams --- packages/app/src/specs/CreateSpecModal.cy.tsx | 88 +++++++++++++++++++ .../src/specs/generators/EmptyGenerator.vue | 29 +++++- 2 files changed, 116 insertions(+), 1 deletion(-) diff --git a/packages/app/src/specs/CreateSpecModal.cy.tsx b/packages/app/src/specs/CreateSpecModal.cy.tsx index ea0b567c83ae..2b79f7108c3f 100644 --- a/packages/app/src/specs/CreateSpecModal.cy.tsx +++ b/packages/app/src/specs/CreateSpecModal.cy.tsx @@ -64,6 +64,94 @@ describe('', () => { }) }) +describe('Modal Text Input', () => { + it('focuses text input and selects file name by default', () => { + const show = ref(true) + + cy.mount(() => (
+ show.value = false} + /> +
)) + + cy.focused().as('specNameInput') + + // focused should yield the input element since it should be auto-focused + cy.get('@specNameInput').invoke('val').should('equal', 'cypress/e2e/ComponentName.cy.js') + + // only the file name should be focused, so backspacing should erase the whole file name + cy.get('@specNameInput').type('{backspace}') + + cy.get('@specNameInput').invoke('val').should('equal', 'cypress/e2e/.cy.js') + }) + + it('focuses text input but does not select if default file name does not match regex', () => { + const show = ref(true) + + cy.mount(() => (
+ show.value = false} + /> +
)) + + cy.focused().as('specNameInput') + + // focused should yield the input element since it should be auto-focused + cy.get('@specNameInput').invoke('val').should('equal', 'this/path/does/not/produce/regex/match-') + + // nothing should be selected, so backspacing should only delete the last character in the file path + cy.get('@specNameInput').type('{backspace}') + + cy.get('@specNameInput').invoke('val').should('equal', 'this/path/does/not/produce/regex/match') + }) +}) + describe('playground', () => { it('can be opened and closed via the show prop', () => { const show = ref(false) diff --git a/packages/app/src/specs/generators/EmptyGenerator.vue b/packages/app/src/specs/generators/EmptyGenerator.vue index ff54e2b1bf65..e06ab095568a 100644 --- a/packages/app/src/specs/generators/EmptyGenerator.vue +++ b/packages/app/src/specs/generators/EmptyGenerator.vue @@ -4,6 +4,7 @@