Skip to content

Commit

Permalink
tests: widgets-loader: Update to add mini-widgets test
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
  • Loading branch information
patrickelectric committed Mar 27, 2024
1 parent 8302124 commit 3a0680a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/tests/libs/widgets-loader.test.ts
@@ -1,10 +1,25 @@
import { expect, test } from 'vitest'

import { MiniWidgetType } from '@/types/miniWidgets'
import { WidgetType } from '@/types/widgets'

test('Test widgets exist', async () => {
await enum_to_files_checker(WidgetType, '@/components/widgets/${name}.vue')
})

test('Test mini-widgets exist', async () => {
await enum_to_files_checker(MiniWidgetType, '@/components/mini-widgets/${name}.vue')
})

/**
* Test helper to verify if all enums names matches with a file list in a path
* @param {T} enum_type Enum type with values as filenames
* @param {string} path_template Path template as string, where name should be used as filename
*/
async function enum_to_files_checker<T>(enum_type: T, path_template: string): Promise<void> {
const loader = await Promise.allSettled(
Object.values(WidgetType).map((name) => import(`@/components/widgets/${name}.vue`))
/* eslint-disable @typescript-eslint/no-unused-vars */
Object.values(enum_type).map((name) => import(eval('`' + path_template + '`'))) // Please, have marcy of my soul
)
const found_all_files = loader.every((file) => {
if (file.status == 'fulfilled') {
Expand All @@ -17,4 +32,4 @@ test('Test widgets exist', async () => {
return !failed_to_find
})
expect(found_all_files).toBe(true)
})
}

0 comments on commit 3a0680a

Please sign in to comment.