Skip to content

Commit

Permalink
Add/update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmooney committed Oct 30, 2024
1 parent 38c077f commit eb753bb
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/__tests__/test-components/SubModuleMenu.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { nullTranslator } from '@jupyterlab/translation';
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import 'jest';
import * as React from 'react';
import {
ISubModuleMenuProps,
SubModuleMenu
} from '../../components/SubModuleMenu';
import { GitExtension } from '../../model';
import { IGitExtension } from '../../tokens';
import { DEFAULT_REPOSITORY_PATH } from '../utils';

jest.mock('../../git');
jest.mock('@jupyterlab/apputils');

const SUBMODULES = [
{
name: 'cli/bench'
},
{
name: 'test/util'
}
];

async function createModel() {
const model = new GitExtension();
model.pathRepository = DEFAULT_REPOSITORY_PATH;

await model.ready;
return model;
}

describe('SubModuleMenu', () => {
let model: GitExtension;
const trans = nullTranslator.load('jupyterlab_git');

beforeEach(async () => {
jest.restoreAllMocks();

model = await createModel();
});

function createProps(
props?: Partial<ISubModuleMenuProps>
): ISubModuleMenuProps {
return {
model: model as IGitExtension,
trans: trans,
subModules: SUBMODULES,
...props
};
}

describe('render', () => {
it('should display a list of submodules', () => {
render(<SubModuleMenu {...createProps()} />);

const submodules = SUBMODULES;
expect(screen.getAllByRole('listitem').length).toEqual(submodules.length);

// Should contain the submodule names...
for (let i = 0; i < submodules.length; i++) {
expect(
screen.getByText(submodules[i].name, { exact: true })
).toBeDefined();
}
});
});
});
1 change: 1 addition & 0 deletions src/__tests__/test-components/Toolbar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('Toolbar', () => {
execute: jest.fn()
} as any,
trans: trans,
subModules: model.subModules,
...props
};
}
Expand Down

0 comments on commit eb753bb

Please sign in to comment.