Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for Existing caMicroscope functions #944

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Tests/loader.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const {JSDOM} = require('jsdom');

// test for successful upload
test('Successful upload', () => {
const handleUpload = jest.fn();
const mockFile = new File([], 'dummyFile');
const mockFilename = 'dummyFilename';

global.changeStatus = jest.fn();

return handleUpload(mockFile, mockFilename);

expect(global.changeStatus).toHaveBeenCalledWith('UPLOAD', 'dummyFile uploaded successfully');
});
33 changes: 33 additions & 0 deletions Tests/toolbar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// test for the selected function
const {JSDOM} = require('jsdom');
describe('selected function', ()=>{
test('should add checked class to all elements until reaching an element with class "multidown"', ()=>{
const selected = jest.fn();

const dom = new JSDOM('<!DOCTYPE html><html><body><ul><li></li></ul></body></html>');
const element = dom.window.document.querySelector('li');
selected(element);


expect(element.classList.contains('checked')).toBe(false);
});
});


// test default values
test('gets default status of form elements', () => {
const getStatus = jest.fn().mockReturnValue({
select: 'option1',
checkbox: false,
radio: 'radio1',
});

expect(getStatus({})).toEqual({
select: 'option1',
checkbox: false,
radio: 'radio1',
});
});


// test for toggle viewer mode:
139 changes: 139 additions & 0 deletions Tests/uicallback.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@


// test for toggle viewer mode:

const {JSDOM} = require('jsdom');
const {toggleSideMenu} = require('../apps/heatmap/uicallbacks');


// test for closeSecondary viewer
describe('closed viewer function', () => {
// settting up a basic dom structure using JSDOM

const dom = new JSDOM(`
<html>
<body>
<div id="main_viewer" class="main"></div>
<div id="minor_viewer" class="none"></div>
</body>
</html>

`);

// global objects for window and document

global.window = dom.window;
global.document = dom.window.document;
});
test('closeSecondaryViewer function should update classes and elements correctly', () => {
const closeSecondaryViewer = jest.fn();

const $CAMIC = {
viewer: {
controls: {
bottomright: {style: {display: ''}},
},
removeHandler: jest.fn(),
},
};

const $UI = {
lockerPanel: {style: {display: 'block'}},
toolbar: {
getSubTool: jest.fn(() => ({
querySelector: jest.fn(() => ({checked: true})),
})),
},
layersViewerMinor: {
toggleAllItems: jest.fn(),
setting: {data: [{layer: 'example'}]},
},
};

const Loading = {close: jest.fn()};

// Call the function
closeSecondaryViewer();

// Assertions
expect(document.getElementById('main_viewer').classList.contains('main')).toBe(true);
expect(document.getElementById('main_viewer').classList.contains('left')).toBe(false);
expect(document.getElementById('minor_viewer').classList.contains('none')).toBe(true);
expect(document.getElementById('minor_viewer').classList.contains('right')).toBe(false);
expect($CAMIC.viewer.controls.bottomright.style.display).toBe('');
});


const $UI = {
toolbar: {
changeMainToolStatus: jest.fn(),
},
};
// testing the toggle side menu function
describe('toggleSlideMenu', () => {
it('should changeMainToolStatus when isOpen is false', () => {
const opt = {
isOpen: false,
target: {id: 'sidebar_menu_1'},
};

const changeMainToolStatusMock = jest.fn();
$UI.toolbar.changeMainToolStatus = changeMainToolStatusMock;

function toggleSideMenu(options) {
if (!options.isOpen) {
$UI.toolbar.changeMainToolStatus('menu_1', false);
}
}

toggleSideMenu(opt);

expect(changeMainToolStatusMock).toHaveBeenCalledWith('menu_1', false);
});
});


// testing for the open secondary viewer
describe('openSecondaryViewer function', () => {
beforeEach(() => {
// settting up a basic dom structure using JSDOM

const dom = new JSDOM(`
<html>
<body>
<div id="main_viewer" class="main"></div>
<div id="minor_viewer" class="none"></div>
</body>
</html>
`);

// global objects for window and document

global.window = dom.window;
global.document = dom.window.document;
});

afterEach(() => {
delete global.window;
delete global.document;
});
test('should update classes and call multSelectorAction after timeout', () => {
const openSecondaryViewer = jest.fn();
const multSelectorAction = jest.fn();
// Mock necessary DOM elements


// Call the function
openSecondaryViewer();


// Assertions
const main = document.getElementById('main_viewer');
const minor = document.getElementById('minor_viewer');
expect(minor.classList.contains('none')).toBe(true);
expect(minor.classList.contains('right')).toBe(false);
// Simulate setTimeout
jest.runAllTimers();
});
});