Skip to content

Commit

Permalink
fix: headers and actions empty variable init
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Aug 11, 2023
1 parent f50ab15 commit 9c850ab
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions __tests__/fileAction.spec.ts
Expand Up @@ -14,9 +14,9 @@ describe('FileActions init', () => {
test('Getting empty uninitialized FileActions', () => {
logger.debug = vi.fn()
const fileActions = getFileActions()
expect(window._nc_fileactions).toBeUndefined()
expect(window._nc_fileactions).toBeDefined()
expect(fileActions).toHaveLength(0)
expect(logger.debug).toHaveBeenCalledTimes(0)
expect(logger.debug).toHaveBeenCalledTimes(1)
})

test('Initializing FileActions', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/fileListHeaders.spec.ts
Expand Up @@ -12,9 +12,9 @@ describe('FileListHeader init', () => {
test('Getting empty uninitialized FileListHeader', () => {
logger.debug = vi.fn()
const headers = getFileListHeaders()
expect(window._nc_filelistheader).toBeUndefined()
expect(window._nc_filelistheader).toBeDefined()
expect(headers).toHaveLength(0)
expect(logger.debug).toHaveBeenCalledTimes(0)
expect(logger.debug).toHaveBeenCalledTimes(1)
})

test('Initializing FileListHeader', () => {
Expand Down
7 changes: 6 additions & 1 deletion lib/fileAction.ts
Expand Up @@ -171,5 +171,10 @@ export const registerFileAction = function(action: FileAction): void {
}

export const getFileActions = function(): FileAction[] {
return window._nc_fileactions || []
if (typeof window._nc_fileactions === 'undefined') {
window._nc_fileactions = []
logger.debug('FileActions initialized')
}

return window._nc_fileactions
}
9 changes: 7 additions & 2 deletions lib/fileListHeaders.ts
Expand Up @@ -92,7 +92,7 @@ export class Header {
export const registerFileListHeaders = function(header: Header): void {
if (typeof window._nc_filelistheader === 'undefined') {
window._nc_filelistheader = []
logger.debug('FileActions initialized')
logger.debug('FileListHeaders initialized')
}

// Check duplicates
Expand All @@ -105,5 +105,10 @@ export const registerFileListHeaders = function(header: Header): void {
}

export const getFileListHeaders = function(): Header[] {
return window._nc_filelistheader || []
if (typeof window._nc_filelistheader === 'undefined') {
window._nc_filelistheader = []
logger.debug('FileListHeaders initialized')
}

return window._nc_filelistheader
}

0 comments on commit 9c850ab

Please sign in to comment.