diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-13 18:08:23 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-13 18:08:23 +0300 |
commit | 868e4e69bba7d3ddc2bf4899ee45d6c377a8e536 (patch) | |
tree | 921098180de1fbf8e58cfaeade0d0999177b0ce6 /spec/javascripts | |
parent | 41e8b05e8d06f4b13a984e4a3ad26e9a48294543 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/vue_shared/components/markdown/suggestions_spec.js | 106 | ||||
-rw-r--r-- | spec/javascripts/vue_shared/components/project_selector/project_selector_spec.js | 142 |
2 files changed, 0 insertions, 248 deletions
diff --git a/spec/javascripts/vue_shared/components/markdown/suggestions_spec.js b/spec/javascripts/vue_shared/components/markdown/suggestions_spec.js deleted file mode 100644 index b7de40b4831..00000000000 --- a/spec/javascripts/vue_shared/components/markdown/suggestions_spec.js +++ /dev/null @@ -1,106 +0,0 @@ -import Vue from 'vue'; -import SuggestionsComponent from '~/vue_shared/components/markdown/suggestions.vue'; - -const MOCK_DATA = { - suggestions: [ - { - id: 1, - appliable: true, - applied: false, - current_user: { - can_apply: true, - }, - diff_lines: [ - { - can_receive_suggestion: false, - line_code: null, - meta_data: null, - new_line: null, - old_line: 5, - rich_text: '-test', - text: '-test', - type: 'old', - }, - { - can_receive_suggestion: true, - line_code: null, - meta_data: null, - new_line: 5, - old_line: null, - rich_text: '+new test', - text: '+new test', - type: 'new', - }, - ], - }, - ], - noteHtml: ` - <div class="suggestion"> - <div class="line">-oldtest</div> - </div> - <div class="suggestion"> - <div class="line">+newtest</div> - </div> - `, - isApplied: false, - helpPagePath: 'path_to_docs', -}; - -describe('Suggestion component', () => { - let vm; - let diffTable; - - beforeEach(done => { - const Component = Vue.extend(SuggestionsComponent); - - vm = new Component({ - propsData: MOCK_DATA, - }).$mount(); - - diffTable = vm.generateDiff(0).$mount().$el; - - spyOn(vm, 'renderSuggestions'); - vm.renderSuggestions(); - Vue.nextTick(done); - }); - - describe('mounted', () => { - it('renders a flash container', () => { - expect(vm.$el.querySelector('.js-suggestions-flash')).not.toBeNull(); - }); - - it('renders a container for suggestions', () => { - expect(vm.$refs.container).not.toBeNull(); - }); - - it('renders suggestions', () => { - expect(vm.renderSuggestions).toHaveBeenCalled(); - expect(vm.$el.innerHTML.includes('oldtest')).toBe(true); - expect(vm.$el.innerHTML.includes('newtest')).toBe(true); - }); - }); - - describe('generateDiff', () => { - it('generates a diff table', () => { - expect(diffTable.querySelector('.md-suggestion-diff')).not.toBeNull(); - }); - - it('generates a diff table that contains contents of `oldLineContent`', () => { - expect(diffTable.innerHTML.includes(vm.fromContent)).toBe(true); - }); - - it('generates a diff table that contains contents the suggested lines', () => { - MOCK_DATA.suggestions[0].diff_lines.forEach(line => { - const text = line.text.substring(1); - - expect(diffTable.innerHTML.includes(text)).toBe(true); - }); - }); - - it('generates a diff table with the correct line number for each suggested line', () => { - const lines = diffTable.querySelectorAll('.old_line'); - - expect(parseInt([...lines][0].innerHTML, 10)).toBe(5); - }); - }); -}); diff --git a/spec/javascripts/vue_shared/components/project_selector/project_selector_spec.js b/spec/javascripts/vue_shared/components/project_selector/project_selector_spec.js deleted file mode 100644 index 5d995f06abb..00000000000 --- a/spec/javascripts/vue_shared/components/project_selector/project_selector_spec.js +++ /dev/null @@ -1,142 +0,0 @@ -import Vue from 'vue'; -import { head } from 'lodash'; - -import { GlSearchBoxByType, GlInfiniteScroll } from '@gitlab/ui'; -import { mount, createLocalVue } from '@vue/test-utils'; -import { trimText } from 'spec/helpers/text_helper'; -import ProjectListItem from '~/vue_shared/components/project_selector/project_list_item.vue'; -import ProjectSelector from '~/vue_shared/components/project_selector/project_selector.vue'; - -const localVue = createLocalVue(); - -describe('ProjectSelector component', () => { - let wrapper; - let vm; - loadJSONFixtures('static/projects.json'); - const allProjects = getJSONFixture('static/projects.json'); - const searchResults = allProjects.slice(0, 5); - let selected = []; - selected = selected.concat(allProjects.slice(0, 3)).concat(allProjects.slice(5, 8)); - - const findSearchInput = () => wrapper.find(GlSearchBoxByType).find('input'); - - beforeEach(() => { - jasmine.clock().install(); - jasmine.clock().mockDate(); - - wrapper = mount(Vue.extend(ProjectSelector), { - localVue, - propsData: { - projectSearchResults: searchResults, - selectedProjects: selected, - showNoResultsMessage: false, - showMinimumSearchQueryMessage: false, - showLoadingIndicator: false, - showSearchErrorMessage: false, - }, - attachToDocument: true, - }); - - ({ vm } = wrapper); - }); - - afterEach(() => { - jasmine.clock().uninstall(); - vm.$destroy(); - }); - - it('renders the search results', () => { - expect(wrapper.findAll('.js-project-list-item').length).toBe(5); - }); - - it(`triggers a (debounced) search when the search input value changes`, () => { - spyOn(vm, '$emit'); - const query = 'my test query!'; - const searchInput = findSearchInput(); - - searchInput.setValue(query); - searchInput.trigger('input'); - - expect(vm.$emit).not.toHaveBeenCalledWith(); - jasmine.clock().tick(501); - - expect(vm.$emit).toHaveBeenCalledWith('searched', query); - }); - - it(`debounces the search input`, () => { - spyOn(vm, '$emit'); - const searchInput = findSearchInput(); - - const updateSearchQuery = (count = 0) => { - if (count === 10) { - jasmine.clock().tick(101); - - expect(vm.$emit).toHaveBeenCalledTimes(1); - expect(vm.$emit).toHaveBeenCalledWith('searched', `search query #9`); - } else { - searchInput.setValue(`search query #${count}`); - searchInput.trigger('input'); - - jasmine.clock().tick(400); - updateSearchQuery(count + 1); - } - }; - - updateSearchQuery(); - }); - - it(`includes a placeholder in the search box`, () => { - const searchInput = findSearchInput(); - - expect(searchInput.attributes('placeholder')).toBe('Search your projects'); - }); - - it(`triggers a "bottomReached" event when user has scrolled to the bottom of the list`, () => { - spyOn(vm, '$emit'); - wrapper.find(GlInfiniteScroll).vm.$emit('bottomReached'); - - expect(vm.$emit).toHaveBeenCalledWith('bottomReached'); - }); - - it(`triggers a "projectClicked" event when a project is clicked`, () => { - spyOn(vm, '$emit'); - wrapper.find(ProjectListItem).vm.$emit('click', head(searchResults)); - - expect(vm.$emit).toHaveBeenCalledWith('projectClicked', head(searchResults)); - }); - - it(`shows a "no results" message if showNoResultsMessage === true`, () => { - wrapper.setProps({ showNoResultsMessage: true }); - - return vm.$nextTick().then(() => { - const noResultsEl = wrapper.find('.js-no-results-message'); - - expect(noResultsEl.exists()).toBe(true); - expect(trimText(noResultsEl.text())).toEqual('Sorry, no projects matched your search'); - }); - }); - - it(`shows a "minimum search query" message if showMinimumSearchQueryMessage === true`, () => { - wrapper.setProps({ showMinimumSearchQueryMessage: true }); - - return vm.$nextTick().then(() => { - const minimumSearchEl = wrapper.find('.js-minimum-search-query-message'); - - expect(minimumSearchEl.exists()).toBe(true); - expect(trimText(minimumSearchEl.text())).toEqual('Enter at least three characters to search'); - }); - }); - - it(`shows a error message if showSearchErrorMessage === true`, () => { - wrapper.setProps({ showSearchErrorMessage: true }); - - return vm.$nextTick().then(() => { - const errorMessageEl = wrapper.find('.js-search-error-message'); - - expect(errorMessageEl.exists()).toBe(true); - expect(trimText(errorMessageEl.text())).toEqual( - 'Something went wrong, unable to search projects', - ); - }); - }); -}); |