From ddbf3a20f490169b2323e1ccd8e7230f12212b1f Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 10 Mar 2022 02:02:20 -0600 Subject: [PATCH] explorer: add more UI tests --- src/explorer/Explorer.test.tsx | 45 +++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/src/explorer/Explorer.test.tsx b/src/explorer/Explorer.test.tsx index 1343ec50..b75155ea 100644 --- a/src/explorer/Explorer.test.tsx +++ b/src/explorer/Explorer.test.tsx @@ -4,23 +4,36 @@ import userEvent from '@testing-library/user-event'; import React from 'react'; import { testRender } from '../../test'; +import { + fileStorageArchiveAllFiles, + fileStorageDeleteFile, + fileStorageExportFile, +} from '../fileStorage/actions'; import Explorer from './Explorer'; describe('archive button', () => { it('should be enabled if there are files', () => { - const [explorer] = testRender(, { + const [explorer, dispatch] = testRender(, { fileStorage: { fileNames: ['test.file'] }, }); - expect(explorer.getByTitle('Backup all files')).toBeEnabled(); + const button = explorer.getByTitle('Backup all files'); + expect(button).toBeEnabled(); + + userEvent.click(button); + expect(dispatch).toHaveBeenCalledWith(fileStorageArchiveAllFiles()); }); it('should be disabled if there are no files', () => { - const [explorer] = testRender(, { + const [explorer, dispatch] = testRender(, { fileStorage: { fileNames: [] }, }); - expect(explorer.getByTitle('Backup all files')).toBeDisabled(); + const button = explorer.getByTitle('Backup all files'); + expect(button).toBeDisabled(); + + userEvent.click(button); + expect(dispatch).not.toHaveBeenCalled(); }); }); @@ -54,4 +67,28 @@ describe('list item', () => { userEvent.click(button); expect(button).not.toHaveFocus(); }); + + it('should dispatch delete action when button is clicked', async () => { + const [explorer, dispatch] = testRender(, { + fileStorage: { fileNames: ['test.file'] }, + }); + + const button = explorer.getByTitle('Delete test.file'); + + userEvent.click(button); + + expect(dispatch).toHaveBeenCalledWith(fileStorageDeleteFile('test.file')); + }); + + it('should dispatch export action when button is clicked', async () => { + const [explorer, dispatch] = testRender(, { + fileStorage: { fileNames: ['test.file'] }, + }); + + const button = explorer.getByTitle('Export test.file'); + + userEvent.click(button); + + expect(dispatch).toHaveBeenCalledWith(fileStorageExportFile('test.file')); + }); });