diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/frontend/helpers | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/frontend/helpers')
-rw-r--r-- | spec/frontend/helpers/dom_shims/create_object_url.js | 3 | ||||
-rw-r--r-- | spec/frontend/helpers/dom_shims/index.js | 1 | ||||
-rw-r--r-- | spec/frontend/helpers/emoji.js | 88 | ||||
-rw-r--r-- | spec/frontend/helpers/experimentation_helper.js | 14 | ||||
-rw-r--r-- | spec/frontend/helpers/keep_alive_component_helper.js | 29 | ||||
-rw-r--r-- | spec/frontend/helpers/keep_alive_component_helper_spec.js | 32 | ||||
-rw-r--r-- | spec/frontend/helpers/local_storage_helper.js | 2 | ||||
-rw-r--r-- | spec/frontend/helpers/local_storage_helper_spec.js | 4 | ||||
-rw-r--r-- | spec/frontend/helpers/startup_css_helper_spec.js | 2 | ||||
-rw-r--r-- | spec/frontend/helpers/vue_test_utils_helper.js | 7 | ||||
-rw-r--r-- | spec/frontend/helpers/wait_for_text.js | 3 |
11 files changed, 181 insertions, 4 deletions
diff --git a/spec/frontend/helpers/dom_shims/create_object_url.js b/spec/frontend/helpers/dom_shims/create_object_url.js new file mode 100644 index 00000000000..94d060cab08 --- /dev/null +++ b/spec/frontend/helpers/dom_shims/create_object_url.js @@ -0,0 +1,3 @@ +URL.createObjectURL = function createObjectURL() { + return 'blob:https://gitlab.com/048c7ac1-98de-4a37-ab1b-0206d0ea7e1b'; +}; diff --git a/spec/frontend/helpers/dom_shims/index.js b/spec/frontend/helpers/dom_shims/index.js index 2ba5701fc77..9b70cb86b8b 100644 --- a/spec/frontend/helpers/dom_shims/index.js +++ b/spec/frontend/helpers/dom_shims/index.js @@ -1,3 +1,4 @@ +import './create_object_url'; import './element_scroll_into_view'; import './element_scroll_by'; import './element_scroll_to'; diff --git a/spec/frontend/helpers/emoji.js b/spec/frontend/helpers/emoji.js new file mode 100644 index 00000000000..e8a93e21818 --- /dev/null +++ b/spec/frontend/helpers/emoji.js @@ -0,0 +1,88 @@ +import MockAdapter from 'axios-mock-adapter'; +import axios from '~/lib/utils/axios_utils'; +import { initEmojiMap, EMOJI_VERSION } from '~/emoji'; + +export const emojiFixtureMap = { + atom: { + moji: '⚛', + description: 'atom symbol', + unicodeVersion: '4.1', + aliases: ['atom_symbol'], + }, + bomb: { + moji: '💣', + unicodeVersion: '6.0', + description: 'bomb', + }, + construction_worker_tone5: { + moji: '👷🏿', + unicodeVersion: '8.0', + description: 'construction worker tone 5', + }, + five: { + moji: '5️⃣', + unicodeVersion: '3.0', + description: 'keycap digit five', + }, + grey_question: { + moji: '❔', + unicodeVersion: '6.0', + description: 'white question mark ornament', + }, + + // used for regression tests + // black_heart MUST come before heart + // custard MUST come before star + black_heart: { + moji: '🖤', + unicodeVersion: '1.1', + description: 'black heart', + }, + heart: { + moji: '❤', + unicodeVersion: '1.1', + description: 'heavy black heart', + }, + custard: { + moji: '🍮', + unicodeVersion: '6.0', + description: 'custard', + }, + star: { + moji: '⭐', + unicodeVersion: '5.1', + description: 'white medium star', + }, +}; + +Object.keys(emojiFixtureMap).forEach(k => { + emojiFixtureMap[k].name = k; + if (!emojiFixtureMap[k].aliases) { + emojiFixtureMap[k].aliases = []; + } +}); + +export async function initEmojiMock() { + const emojiData = Object.fromEntries( + Object.values(emojiFixtureMap).map(m => { + const { name: n, moji: e, unicodeVersion: u, category: c, description: d } = m; + return [n, { c, e, d, u }]; + }), + ); + + const mock = new MockAdapter(axios); + mock.onGet(`/-/emojis/${EMOJI_VERSION}/emojis.json`).reply(200, JSON.stringify(emojiData)); + + await initEmojiMap(); + + return mock; +} + +export function describeEmojiFields(label, tests) { + describe.each` + field | accessor + ${'name'} | ${e => e.name} + ${'alias'} | ${e => e.aliases[0]} + ${'description'} | ${e => e.description} + `(label, tests); +} diff --git a/spec/frontend/helpers/experimentation_helper.js b/spec/frontend/helpers/experimentation_helper.js new file mode 100644 index 00000000000..c08c25155e8 --- /dev/null +++ b/spec/frontend/helpers/experimentation_helper.js @@ -0,0 +1,14 @@ +import { merge } from 'lodash'; + +export function withGonExperiment(experimentKey, value = true) { + let origGon; + + beforeEach(() => { + origGon = window.gon; + window.gon = merge({}, window.gon || {}, { experiments: { [experimentKey]: value } }); + }); + + afterEach(() => { + window.gon = origGon; + }); +} diff --git a/spec/frontend/helpers/keep_alive_component_helper.js b/spec/frontend/helpers/keep_alive_component_helper.js new file mode 100644 index 00000000000..54f40bf9093 --- /dev/null +++ b/spec/frontend/helpers/keep_alive_component_helper.js @@ -0,0 +1,29 @@ +import Vue from 'vue'; + +export function keepAlive(KeptAliveComponent) { + return Vue.extend({ + components: { + KeptAliveComponent, + }, + data() { + return { + view: 'KeptAliveComponent', + }; + }, + methods: { + async activate() { + this.view = 'KeptAliveComponent'; + await this.$nextTick(); + }, + async deactivate() { + this.view = 'div'; + await this.$nextTick(); + }, + async reactivate() { + await this.deactivate(); + await this.activate(); + }, + }, + template: `<keep-alive><component :is="view"></component></keep-alive>`, + }); +} diff --git a/spec/frontend/helpers/keep_alive_component_helper_spec.js b/spec/frontend/helpers/keep_alive_component_helper_spec.js new file mode 100644 index 00000000000..dcccc14f396 --- /dev/null +++ b/spec/frontend/helpers/keep_alive_component_helper_spec.js @@ -0,0 +1,32 @@ +import { mount } from '@vue/test-utils'; +import { keepAlive } from './keep_alive_component_helper'; + +const component = { + template: '<div>Test Component</div>', +}; + +describe('keepAlive', () => { + let wrapper; + + beforeEach(() => { + wrapper = mount(keepAlive(component)); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + it('converts a component to a keep-alive component', async () => { + const { element } = wrapper.find(component); + + await wrapper.vm.deactivate(); + expect(wrapper.find(component).exists()).toBe(false); + + await wrapper.vm.activate(); + + // assert that when the component is destroyed and re-rendered, the + // newly rendered component has the reference to the old component + // (i.e. the old component was deactivated and activated) + expect(wrapper.find(component).element).toBe(element); + }); +}); diff --git a/spec/frontend/helpers/local_storage_helper.js b/spec/frontend/helpers/local_storage_helper.js index cd39b660bfd..0318b80aaef 100644 --- a/spec/frontend/helpers/local_storage_helper.js +++ b/spec/frontend/helpers/local_storage_helper.js @@ -35,7 +35,7 @@ export const createLocalStorageSpy = () => { clear: jest.fn(() => { storage = {}; }), - getItem: jest.fn(key => storage[key]), + getItem: jest.fn(key => (key in storage ? storage[key] : null)), setItem: jest.fn((key, value) => { storage[key] = value; }), diff --git a/spec/frontend/helpers/local_storage_helper_spec.js b/spec/frontend/helpers/local_storage_helper_spec.js index 6b44ea3a4c3..5d9961e7631 100644 --- a/spec/frontend/helpers/local_storage_helper_spec.js +++ b/spec/frontend/helpers/local_storage_helper_spec.js @@ -18,11 +18,11 @@ describe('localStorage helper', () => { localStorage.removeItem('test', 'testing'); - expect(localStorage.getItem('test')).toBeUndefined(); + expect(localStorage.getItem('test')).toBe(null); expect(localStorage.getItem('test2')).toBe('testing'); localStorage.clear(); - expect(localStorage.getItem('test2')).toBeUndefined(); + expect(localStorage.getItem('test2')).toBe(null); }); }); diff --git a/spec/frontend/helpers/startup_css_helper_spec.js b/spec/frontend/helpers/startup_css_helper_spec.js index 7b83f0aefca..1a88e80344e 100644 --- a/spec/frontend/helpers/startup_css_helper_spec.js +++ b/spec/frontend/helpers/startup_css_helper_spec.js @@ -1,4 +1,4 @@ -import { waitForCSSLoaded } from '../../../app/assets/javascripts/helpers/startup_css_helper'; +import { waitForCSSLoaded } from '~/helpers/startup_css_helper'; describe('waitForCSSLoaded', () => { let mockedCallback; diff --git a/spec/frontend/helpers/vue_test_utils_helper.js b/spec/frontend/helpers/vue_test_utils_helper.js index 68326e37ae7..ead898f04d3 100644 --- a/spec/frontend/helpers/vue_test_utils_helper.js +++ b/spec/frontend/helpers/vue_test_utils_helper.js @@ -33,3 +33,10 @@ export const waitForMutation = (store, expectedMutationType) => } }); }); + +export const extendedWrapper = wrapper => + Object.defineProperty(wrapper, 'findByTestId', { + value(id) { + return this.find(`[data-testid="${id}"]`); + }, + }); diff --git a/spec/frontend/helpers/wait_for_text.js b/spec/frontend/helpers/wait_for_text.js new file mode 100644 index 00000000000..6bed8a90a98 --- /dev/null +++ b/spec/frontend/helpers/wait_for_text.js @@ -0,0 +1,3 @@ +import { findByText } from '@testing-library/dom'; + +export const waitForText = async (text, container = document) => findByText(container, text); |