Skip to content

Commit

Permalink
fix(tests): Add test case for getFileListHeaders and `getFileAction…
Browse files Browse the repository at this point in the history
…s` reactivity

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux authored and skjnldsv committed Aug 11, 2023
1 parent eddc1fb commit 23548bb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
24 changes: 23 additions & 1 deletion __tests__/fileAction.spec.ts
@@ -1,5 +1,6 @@
/* eslint-disable no-new */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable no-new */
import { beforeEach, describe, expect, test, vi } from 'vitest'

import { getFileActions, registerFileAction, FileAction } from '../lib/fileAction'
Expand Down Expand Up @@ -40,6 +41,27 @@ describe('FileActions init', () => {
expect(logger.debug).toHaveBeenCalled()
})

test('getFileActions() returned array is reactive', () => {
logger.debug = vi.fn()

const actions = getFileActions()
// is empty for now
expect(actions).toHaveLength(0)

const action = new FileAction({
id: 'test',
displayName: () => 'Test',
iconSvgInline: () => '<svg></svg>',
exec: async () => true,
})

registerFileAction(action)

// Now the array changed as it should be reactive
expect(actions).toHaveLength(1)
expect(actions[0]).toStrictEqual(action)
})

test('Duplicate FileAction gets rejected', () => {
logger.error = vi.fn()
const action = new FileAction({
Expand Down
27 changes: 25 additions & 2 deletions __tests__/fileListHeaders.spec.ts
@@ -1,10 +1,11 @@
/* eslint-disable no-new */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable no-new */
import { describe, expect, test, beforeEach, vi } from 'vitest'

import { Folder } from '../lib/files/folder'
import { Header, getFileListHeaders, registerFileListHeaders } from '../lib/fileListHeaders'
import logger from '../lib/utils/logger'
import { Folder } from '../lib/files/folder'

describe('FileListHeader init', () => {

Expand Down Expand Up @@ -42,6 +43,28 @@ describe('FileListHeader init', () => {
expect(logger.debug).toHaveBeenCalled()
})

test('getFileListHeaders() returned array is reactive', () => {
logger.debug = vi.fn()

const headers = getFileListHeaders()
// is empty for now
expect(headers).toHaveLength(0)

const header = new Header({
id: 'test',
order: 1,
enabled: () => true,
render: () => {},
updated: () => {},
})

registerFileListHeaders(header)

// Now the array changed as it should be reactive
expect(headers).toHaveLength(1)
expect(headers[0]).toStrictEqual(header)
})

test('Duplicate Header gets rejected', () => {
logger.error = vi.fn()
const header = new Header({
Expand Down

0 comments on commit 23548bb

Please sign in to comment.