From bb5a6cc54e7f7d5bd26b400f790b059a1a7a77b5 Mon Sep 17 00:00:00 2001 From: Stuart Clark Date: Tue, 13 Aug 2024 10:17:49 +1000 Subject: [PATCH] chore(#693): remove deprecated code --- packages/druxt/src/mixins/component.js | 79 ------------------ packages/druxt/src/mixins/index.js | 10 --- packages/druxt/test/class.test.js | 88 -------------------- packages/druxt/test/mixins/component.test.js | 71 ---------------- 4 files changed, 248 deletions(-) delete mode 100644 packages/druxt/src/mixins/component.js delete mode 100644 packages/druxt/src/mixins/index.js delete mode 100644 packages/druxt/test/class.test.js delete mode 100644 packages/druxt/test/mixins/component.test.js diff --git a/packages/druxt/src/mixins/component.js b/packages/druxt/src/mixins/component.js deleted file mode 100644 index bf58dcb73..000000000 --- a/packages/druxt/src/mixins/component.js +++ /dev/null @@ -1,79 +0,0 @@ -import { DruxtClass } from 'druxt' -import DruxtWrapper from 'druxt/dist/components/DruxtWrapper.vue' - -/** - * @name DruxtComponentMixin - * @deprecated - * @private - */ -const DruxtComponentMixin = { - components: { DruxtWrapper }, - - /** - * @property {Component} component - The wrapper component and propsData to be rendered. - */ - data: () => ({ - component: { - is: 'DruxtWrapper', - options: [], - propsData: {}, - }, - }), - - props: { - wrapper: { - type: Object, - default: () => ({ - component: 'div', - propsData: {}, - }) - } - }, - - /** - * The Nuxt Fetch hook. - * - * Loads the Druxt module data and applies a wrapper component as required. - * - * **Important:** If your component has an existing `fetch` method, you must manually invoke - * the `DruxtComponentMixin.fetch()` hook. - * - * @see {@link https://nuxtjs.org/api/pages-fetch/} - * - * @example @lang vue Manually invoking DruxtComponentMixin.fetch(). - * - */ - async fetch() { - console.warn('DruxtComponentMixin is deprecated in favour of DruxtModule.') - - // @todo - check for this.$druxt plugin. - const druxt = new DruxtClass() - const moduleData = await druxt.getModuleData(this) - - this.component.propsData = moduleData.propsData || {} - - if (!moduleData.componentOptions) { - return - } - - const options = druxt.getComponents(this, moduleData.componentOptions, true) - this.component.options = options.map(item => item.pascal) - const available = options.filter(item => item.global) - if (!available.length) { - return - } - - this.component.is = available[0].pascal - }, -} - -export { DruxtComponentMixin } diff --git a/packages/druxt/src/mixins/index.js b/packages/druxt/src/mixins/index.js deleted file mode 100644 index edfa328e8..000000000 --- a/packages/druxt/src/mixins/index.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Vue.js Mixin to add support for the Wrapper system to a Druxt module. - * - * @type {object} - * @exports DruxtComponentMixin - * - * @deprecated - * @private - */ - export { DruxtComponentMixin } from './component' diff --git a/packages/druxt/test/class.test.js b/packages/druxt/test/class.test.js deleted file mode 100644 index 013494e6d..000000000 --- a/packages/druxt/test/class.test.js +++ /dev/null @@ -1,88 +0,0 @@ -import { createLocalVue, mount } from '@vue/test-utils' - -import { DruxtClass } from '../src/class' - -// Setup local vue instance. -const localVue = createLocalVue() - -const componentOptions = [ - ['one', 'two', 'three'], - ['one', 'three'] -] - -// Mock Druxt module. -const DruxtTestModule = { - render: () => ({}), - druxt: () => ({ - componentOptions, - propsData: {} - }) -} - -// Mock Druxt module wrapper. -const DruxtTestModuleOneTwoThree = { render: () => ({}) } - -let druxt -let wrapper - -describe('DruxtJS Class', () => { - beforeEach(() => { - druxt = new DruxtClass() - - // Mount vm. - wrapper = mount(DruxtTestModule, { localVue, stubs: { DruxtTestModuleOneTwoThree } }) - wrapper.vm.$options.druxt = DruxtTestModule.druxt - }) - - test('getComponents', () => { - let components - - // Get global matches, expect no results. - expect(druxt.getComponents(wrapper.vm, componentOptions).length).toBe(0) - - // Get all matches, expect 4 results. - components = druxt.getComponents(wrapper.vm, componentOptions, true) - expect(components.length).toBe(4) - expect(components[0].pascal).toBe('OneTwoThree') - expect(components[1].pascal).toBe('OneTwo') - expect(components[2].pascal).toBe('OneThree') - expect(components[3].pascal).toBe('One') - - // Get all matches with custom prefix, expect 4 results. - components = druxt.getComponents(wrapper.vm, componentOptions, true, 'custom-prefix') - expect(components.length).toBe(4) - expect(components[0].prefix).toBe('custom-prefix') - expect(components[0].pascal).toBe('CustomPrefixOneTwoThree') - - // Get global matches with module name prefix, expect 1 result. - wrapper.vm.$options.name = 'DruxtTestModule' - components = druxt.getComponents(wrapper.vm, componentOptions) - expect(components.length).toBe(1) - expect(components[0]).toStrictEqual({ - global: true, - kebab: 'druxt-test-module-one-two-three', - parts: ['one', 'two', 'three'], - pascal: 'DruxtTestModuleOneTwoThree', - prefix: 'druxt-test-module' - }) - }) - - test('getModuleData', async () => { - // Invoke with no vm. - expect(await druxt.getModuleData()).toBe(false) - - // Invoke with vm. - expect(await druxt.getModuleData(wrapper.vm)).toStrictEqual({ - componentOptions: [ - ['one', 'two', 'three'], - ['one', 'three'] - ], - propsData: {} - }) - - // Invoke with vm name set. - wrapper.vm.$options.name = 'DruxtTestModule' - const moduleData = await druxt.getModuleData(wrapper.vm) - expect(moduleData.name).toBe('druxt-test-module') - }) -}) diff --git a/packages/druxt/test/mixins/component.test.js b/packages/druxt/test/mixins/component.test.js deleted file mode 100644 index 38eaaaa32..000000000 --- a/packages/druxt/test/mixins/component.test.js +++ /dev/null @@ -1,71 +0,0 @@ -import { createLocalVue, mount } from '@vue/test-utils' - -import { DruxtClass } from '../../src/class' -import { DruxtComponentMixin } from '../../src/mixins/component' - -// Setup local vue instance. -const localVue = createLocalVue() - -// Mock Druxt module. -const DruxtTestModule = { - mixins: [DruxtComponentMixin], - druxt: () => ({ - componentOptions: [['wrapper']], - propsData: {} - }), - render: () => ({}), -} - -// Mock Druxt module wrapper. -const DruxtTestModuleWrapper = { render: () => ({}) } - -let wrapper - -describe('DruxtComponentMixin', () => { - beforeEach(() => { - wrapper = mount(DruxtTestModule, { - localVue, - stubs: { DruxtTestModuleWrapper }, - mocks: { - $druxt: new DruxtClass('https://demo-api.druxtjs.org') - } - }) - }) - - test('data', () => { - expect(wrapper.vm.component).toStrictEqual({ - is: 'DruxtWrapper', - options: [], - propsData: {} - }) - }) - - test('fetch', async () => { - // No componentOptions, expect default values. - wrapper.vm.$options.druxt = () => ({}) - await DruxtComponentMixin.fetch.call(wrapper.vm) - expect(wrapper.vm.component).toStrictEqual({ - is: 'DruxtWrapper', - options: [], - propsData: {} - }) - - // No matching global component, expect default values. - wrapper.vm.$options.druxt = DruxtTestModule.druxt - await DruxtComponentMixin.fetch.call(wrapper.vm) - expect(wrapper.vm.component).toStrictEqual({ - is: 'DruxtWrapper', - options: ['Wrapper'], - propsData: {} - }) - - // Expect matching global component. - wrapper.vm.$options.name = 'DruxtTestModule' - await DruxtComponentMixin.fetch.call(wrapper.vm) - expect(wrapper.vm.component).toStrictEqual({ - is: 'DruxtTestModuleWrapper', - options: ['DruxtTestModuleWrapper'], - propsData: {} - }) - }) -})