From 92aacf69004a0c2f3c25009769a192c844db920d Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Fri, 8 Mar 2019 17:35:02 -0300 Subject: [PATCH] Write more component tests - test the default props values - test that is open changes when focused on or on blur - test that the input is clearable, failing still --- components/SearchInput.spec.js | 55 +++++++++++++++++++++++----- cypress/integration/common/search.js | 5 ++- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/components/SearchInput.spec.js b/components/SearchInput.spec.js index 2d1ffbda8..0ec6f006b 100644 --- a/components/SearchInput.spec.js +++ b/components/SearchInput.spec.js @@ -12,6 +12,7 @@ describe('SearchInput.vue', () => { let wrapper let mocks let propsData + let data beforeEach(() => { propsData = {} @@ -29,23 +30,59 @@ describe('SearchInput.vue', () => { expect(Wrapper().is('div')).toBe(true) }) - it('defaults to an empty value', () => { - expect(Wrapper().vm.value).toBe('') - }) - it('has id "nav-search"', () => { expect(Wrapper().contains('#nav-search')).toBe(true) }) + it('defaults to an empty value', () => { + expect(Wrapper().vm.value).toBe('') + }) + it('defaults to id "nav-search"', () => { expect(Wrapper().vm.id).toBe('nav-search') }) - it('changes searchValue as a user inputs a value', () => { + it('default to a 300 millisecond delay from the time the user stops typing to when the search starts', () => { + expect(Wrapper().vm.delay).toEqual(300) + }) + + it('defaults to an empty array as results', () => { + expect(Wrapper().vm.results).toEqual([]) + }) + + it('defaults to pending false, as in the search is not pending', () => { + expect(Wrapper().vm.pending).toBe(false) + }) + + it('accepts values as a string', () => { + propsData = { value: 'abc' } const wrapper = Wrapper() - let input = wrapper.find('input') - input.setValue('abc') - expect(wrapper.vm.searchValue).toBe('abc') + // expect(wrapper.vm._data.searchValue).toEqual('abc') + expect(wrapper.vm.value).toEqual('abc') + }) + + it('opens the select dropdown when focused on', () => { + const wrapper = Wrapper() + const select = wrapper.find('.ds-select') + select.trigger('focus') + expect(wrapper.vm.isOpen).toBe(true) + select.trigger('blur') + expect(wrapper.vm.isOpen).toBe(false) + // expect(wrapper.find('.ds-select-dropdown').text()).toContain( + // ' What are you searching for?' + // ) + }) + + it('is clearable', () => { + const wrapper = Wrapper() + const select = wrapper.find('.ds-select') + select.trigger('focus') + const input = wrapper.find('input') + input.setValue('Volu') + input.trigger('keydown.esc') + // const clearIcon = wrapper.find('.search-clear-btn') + // clearIcon.trigger('click') + expect(input.element.value).toBe('') }) }) -}) \ No newline at end of file +}) diff --git a/cypress/integration/common/search.js b/cypress/integration/common/search.js index 47edae695..4809e8a13 100644 --- a/cypress/integration/common/search.js +++ b/cypress/integration/common/search.js @@ -42,7 +42,10 @@ When('I select an entry', () => { }) Then("I should be on the post's page", () => { - cy.location('pathname').should('eq', '/post/101-essays-that-will-change-the-way-you-think/') + cy.location('pathname').should( + 'eq', + '/post/101-essays-that-will-change-the-way-you-think/' + ) }) Then(