Skip to content

Commit

Permalink
Fix tests for history (jupyterlab#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
navn-r committed Aug 2, 2021
1 parent c67ebe1 commit 3418e30
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 28 deletions.
4 changes: 2 additions & 2 deletions jupyterlab_git/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ async def test_log_handler(mock_git, jp_fetch, jp_root_dir):
)

# Then
mock_git.log.assert_called_with(str(local_path), 20)
mock_git.log.assert_called_with(str(local_path), 20, None)

assert response.code == 200
payload = json.loads(response.body)
Expand All @@ -301,7 +301,7 @@ async def test_log_handler_no_history_count(mock_git, jp_fetch, jp_root_dir):
)

# Then
mock_git.log.assert_called_with(str(local_path), 25)
mock_git.log.assert_called_with(str(local_path), 25, None)

assert response.code == 200
payload = json.loads(response.body)
Expand Down
2 changes: 1 addition & 1 deletion src/components/HistorySideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const HistorySideBar: React.FunctionComponent<IHistorySideBarProps> = (
})
) : (
<li className={noHistoryFoundStyle}>
{props.trans.__('No history found for the selected file.')}
{props.trans.__('No history found.')}
</li>
)}
</ol>
Expand Down
2 changes: 1 addition & 1 deletion tests/test-components/FileItem.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('FileItem', () => {
const component = shallow(<FileItem {...props} />);
it('should display the full path on hover', () => {
expect(
component.find('[title="some/file/path/file-name Modified"]')
component.find('[title="some/file/path/file-name Modified"]')
).toHaveLength(1);
});
});
Expand Down
3 changes: 3 additions & 0 deletions tests/test-components/GitPanel.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ describe('GitPanel', () => {
},
statusChanged: {
connect: jest.fn()
},
selectedHistoryFileChanged: {
connect: jest.fn()
}
} as any;

Expand Down
57 changes: 54 additions & 3 deletions tests/test-components/HistorySideBar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ import {
import 'jest';

import { PastCommitNode } from '../../src/components/PastCommitNode';
import { GitExtension } from '../../src/model';
import { nullTranslator } from '@jupyterlab/translation';
import { FileItem } from '../../src/components/FileItem';
import { DocumentRegistry } from '@jupyterlab/docregistry';
import { SinglePastCommitInfo } from '../../src/components/SinglePastCommitInfo';

describe('HistorySideBar', () => {
const trans = nullTranslator.load('jupyterlab-git');

const props: IHistorySideBarProps = {
commits: [
{
Expand All @@ -20,12 +27,56 @@ describe('HistorySideBar', () => {
}
],
branches: [],
model: null,
model: {
selectedHistoryFile: null
} as GitExtension,
commands: null,
trans: null
trans
};
test('renders commit nodes', () => {

it('renders the commit nodes', () => {
const historySideBar = shallow(<HistorySideBar {...props} />);
expect(historySideBar.find(PastCommitNode)).toHaveLength(1);
expect(historySideBar.find(SinglePastCommitInfo)).toHaveLength(1);
// Selected history file element
expect(historySideBar.find(FileItem)).toHaveLength(0);
});

it('shows a message if no commits are found', () => {
const propsWithoutCommits: IHistorySideBarProps = { ...props, commits: [] };
const historySideBar = shallow(<HistorySideBar {...propsWithoutCommits} />);
expect(historySideBar.find(PastCommitNode)).toHaveLength(0);

const noHistoryFound = historySideBar.find('li');
expect(noHistoryFound).toHaveLength(1);
expect(noHistoryFound.text()).toEqual('No history found.');
});

it('correctly shows the selected history file', () => {
const propsWithSelectedFile: IHistorySideBarProps = {
...props,
model: {
selectedHistoryFile: {
x: '',
y: '',
to: '/path/to/file',
from: '',
is_binary: null,
status: 'unmodified',
type: {} as DocumentRegistry.IFileType
}
} as GitExtension
};

const historySideBar = shallow(
<HistorySideBar {...propsWithSelectedFile} />
);
const selectedHistoryFile = historySideBar.find(FileItem);
expect(selectedHistoryFile).toHaveLength(1);
expect(selectedHistoryFile.prop('file')).toEqual(
propsWithSelectedFile.model.selectedHistoryFile
);
// Only renders with repository history
expect(historySideBar.find(SinglePastCommitInfo)).toHaveLength(0);
});
});
38 changes: 17 additions & 21 deletions tests/test-components/PastCommitNode.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import * as React from 'react';
import { nullTranslator } from '@jupyterlab/translation';
import { shallow } from 'enzyme';
import { SinglePastCommitInfo } from '../../src/components/SinglePastCommitInfo';
import 'jest';
import * as React from 'react';
import {
PastCommitNode,
IPastCommitNodeProps
IPastCommitNodeProps,
PastCommitNode
} from '../../src/components/PastCommitNode';
import { Git } from '../../src/tokens';
import 'jest';

describe('PastCommitNode', () => {
const trans = nullTranslator.load('jupyterlab-git');

const notMatchingBranches: Git.IBranch[] = [
{
is_current_branch: false,
Expand Down Expand Up @@ -57,7 +59,7 @@ describe('PastCommitNode', () => {
},
branches: branches,
commands: null,
trans: null
trans
};

test('Includes commit info', () => {
Expand All @@ -76,22 +78,16 @@ describe('PastCommitNode', () => {
expect(node.text()).not.toMatch('name2');
});

test('Doesnt include details at first', () => {
const node = shallow(<PastCommitNode {...props} />);
expect(node.find(SinglePastCommitInfo)).toHaveLength(0);
});

test('includes details after click', () => {
const node = shallow(<PastCommitNode {...props} />);
node.simulate('click');
expect(node.find(SinglePastCommitInfo)).toHaveLength(1);
});

test('hides details after collapse', () => {
const node = shallow(<PastCommitNode {...props} />);
test('Toggle show details', () => {
// simulates SinglePastCommitInfo child
const node = shallow(
<PastCommitNode {...props}>
<div id="singlePastCommitInfo"></div>
</PastCommitNode>
);
node.simulate('click');
expect(node.find(SinglePastCommitInfo)).toHaveLength(1);
expect(node.find('div#singlePastCommitInfo')).toHaveLength(1);
node.simulate('click');
expect(node.find(SinglePastCommitInfo)).toHaveLength(0);
expect(node.find('div#singlePastCommitInfo')).toHaveLength(0);
});
});

0 comments on commit 3418e30

Please sign in to comment.