diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-09 09:12:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-09 09:12:08 +0300 |
commit | 06af519348e7254062a7d03ef3e421356ff8c64a (patch) | |
tree | 30873ad43170e6c8b3eadc778a63c08a1ac3231c /spec/frontend | |
parent | 44a883b53a586ff5966adce0aacfaa9d31e80441 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/vue_shared/components/markdown/saved_replies_dropdown_spec.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/frontend/vue_shared/components/markdown/saved_replies_dropdown_spec.js b/spec/frontend/vue_shared/components/markdown/saved_replies_dropdown_spec.js new file mode 100644 index 00000000000..8ad9ad30c1d --- /dev/null +++ b/spec/frontend/vue_shared/components/markdown/saved_replies_dropdown_spec.js @@ -0,0 +1,62 @@ +import Vue from 'vue'; +import VueApollo from 'vue-apollo'; +import savedRepliesResponse from 'test_fixtures/graphql/saved_replies/saved_replies.query.graphql.json'; +import { mountExtended } from 'helpers/vue_test_utils_helper'; +import createMockApollo from 'helpers/mock_apollo_helper'; +import waitForPromises from 'helpers/wait_for_promises'; +import SavedRepliesDropdown from '~/vue_shared/components/markdown/saved_replies_dropdown.vue'; +import savedRepliesQuery from '~/vue_shared/components/markdown/saved_replies.query.graphql'; + +let wrapper; +let savedRepliesResp; + +function createMockApolloProvider(response) { + Vue.use(VueApollo); + + savedRepliesResp = jest.fn().mockResolvedValue(response); + + const requestHandlers = [[savedRepliesQuery, savedRepliesResp]]; + + return createMockApollo(requestHandlers); +} + +function createComponent(options = {}) { + const { mockApollo } = options; + + return mountExtended(SavedRepliesDropdown, { + propsData: { + newSavedRepliesPath: '/new', + }, + apolloProvider: mockApollo, + }); +} + +describe('Saved replies dropdown', () => { + it('fetches data when dropdown gets opened', async () => { + const mockApollo = createMockApolloProvider(savedRepliesResponse); + wrapper = createComponent({ mockApollo }); + + wrapper.findByTestId('saved-replies-dropdown-toggle').trigger('click'); + + await waitForPromises(); + + expect(savedRepliesResp).toHaveBeenCalled(); + }); + + it('adds markdown toolbar attributes to dropdown items', async () => { + const mockApollo = createMockApolloProvider(savedRepliesResponse); + wrapper = createComponent({ mockApollo }); + + wrapper.findByTestId('saved-replies-dropdown-toggle').trigger('click'); + + await waitForPromises(); + + expect(wrapper.findByTestId('saved-reply-dropdown-item').attributes()).toEqual( + expect.objectContaining({ + 'data-md-cursor-offset': '0', + 'data-md-prepend': 'true', + 'data-md-tag': 'Saved Reply Content', + }), + ); + }); +}); |