From c8f524f11b2eb819d3d63aad9c64c97acf47e0f5 Mon Sep 17 00:00:00 2001 From: Stuart Clark Date: Tue, 13 Aug 2024 12:27:57 +1000 Subject: [PATCH] chore(#693): update druxt-menu tests --- packages/menu/src/nuxt/index.js | 2 +- .../{nuxtStorybook.js => nuxt/storybook.js} | 0 packages/menu/test/nuxt/index.test.js | 44 +++++++++++++++++++ .../storybook.test.js} | 2 +- packages/menu/test/nuxtModule.test.js | 43 ------------------ 5 files changed, 46 insertions(+), 45 deletions(-) rename packages/menu/src/{nuxtStorybook.js => nuxt/storybook.js} (100%) create mode 100644 packages/menu/test/nuxt/index.test.js rename packages/menu/test/{nuxtStorybook.test.js => nuxt/storybook.test.js} (86%) delete mode 100644 packages/menu/test/nuxtModule.test.js diff --git a/packages/menu/src/nuxt/index.js b/packages/menu/src/nuxt/index.js index bed6c4c8f..f5d7113cc 100644 --- a/packages/menu/src/nuxt/index.js +++ b/packages/menu/src/nuxt/index.js @@ -1,6 +1,6 @@ import { addPluginTemplate, defineNuxtModule, installModule } from '@nuxt/kit' import { join, resolve } from 'path' -// import DruxtMenuStorybook from '../nuxtStorybook' +// import DruxtMenuStorybook from './storybook' /** * The Nuxt.js module function. diff --git a/packages/menu/src/nuxtStorybook.js b/packages/menu/src/nuxt/storybook.js similarity index 100% rename from packages/menu/src/nuxtStorybook.js rename to packages/menu/src/nuxt/storybook.js diff --git a/packages/menu/test/nuxt/index.test.js b/packages/menu/test/nuxt/index.test.js new file mode 100644 index 000000000..f88cb8890 --- /dev/null +++ b/packages/menu/test/nuxt/index.test.js @@ -0,0 +1,44 @@ +import DruxtMenuNuxtModule from '../../src/nuxt' + +jest.mock('../../src/nuxt/storybook') + +jest.mock('@nuxt/kit', () => ({ + addPluginTemplate: jest.fn(), + defineNuxtModule: (module) => module, + installModule: jest.fn(), +})) + +import { addPluginTemplate, installModule } from '@nuxt/kit' + +const nuxtMock = { + hook: jest.fn((hook, fn) => { + const arg = { + 'components:dirs': [], + 'storybook:config': { stories: [] } + } + return fn(arg[hook]) + }), +} + +test('Nuxt module', async () => { + // Use module with defaults. + await DruxtMenuNuxtModule.setup({}, nuxtMock) + expect(addPluginTemplate).toHaveBeenCalled() + + // Expect JSON:API Menu Items tp be enabled. + expect(installModule).toHaveBeenLastCalledWith('druxt/nuxt', { + baseUrl: undefined, + menu: { + jsonApiMenuItems: true + } + }) + + // Use overridden options; Drupal content menu items. + await DruxtMenuNuxtModule.setup({}, { ...nuxtMock, options: { druxt: { menu: { jsonApiMenuItems: false }}} }) + expect(installModule).toHaveBeenLastCalledWith('druxt/nuxt', { + baseUrl: undefined, + menu: { + jsonApiMenuItems: false + } + }) +}) diff --git a/packages/menu/test/nuxtStorybook.test.js b/packages/menu/test/nuxt/storybook.test.js similarity index 86% rename from packages/menu/test/nuxtStorybook.test.js rename to packages/menu/test/nuxt/storybook.test.js index 7f659896b..c961de7fb 100644 --- a/packages/menu/test/nuxtStorybook.test.js +++ b/packages/menu/test/nuxt/storybook.test.js @@ -1,4 +1,4 @@ -import DruxtMenuStorybook from '../src/nuxtStorybook' +import DruxtMenuStorybook from '../../src/nuxt/storybook' jest.mock('axios') diff --git a/packages/menu/test/nuxtModule.test.js b/packages/menu/test/nuxtModule.test.js deleted file mode 100644 index 4684133a1..000000000 --- a/packages/menu/test/nuxtModule.test.js +++ /dev/null @@ -1,43 +0,0 @@ -import { DruxtMenuNuxtModule } from '../src/nuxtModule' - -jest.mock('../src/nuxtStorybook') - -const mock = { - addModule: jest.fn(), - addPlugin: jest.fn(), - nuxt: { - hook: jest.fn((hook, fn) => { - const arg = { - 'components:dirs': [], - 'storybook:config': { stories: [] } - } - return fn(arg[hook]) - }), - }, - options: { - druxt: {} - } -} - -test('Nuxt module', async () => { - // Use module with defaults. - await DruxtMenuNuxtModule.call(mock) - expect(mock.addPlugin).toHaveBeenCalled() - - // Expect JSON:API Menu Items tp be enabled. - expect(mock.addModule).toHaveBeenLastCalledWith(['druxt', { - baseUrl: undefined, - menu: { - jsonApiMenuItems: true - } - }]) - - // Use overridden options; Drupal content menu items. - await DruxtMenuNuxtModule.call({ ...mock, options: { druxt: { menu: { jsonApiMenuItems: false }}} }) - expect(mock.addModule).toHaveBeenLastCalledWith(['druxt', { - baseUrl: undefined, - menu: { - jsonApiMenuItems: false - } - }]) -})