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

Restore JS tests #33

Merged
merged 3 commits into from
Mar 14, 2021
Merged
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
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ node_modules
dist
coverage
**/*.d.ts
tests
lib
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
project: 'tsconfig.eslint.json',
sourceType: 'module'
},
plugins: ['@typescript-eslint'],
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ jobs:
set -eux
python -m pytest --pyargs jupyterlab_pullrequests --cov jupyterlab_pullrequests --cov-report term-missing:skip-covered --no-cov-on-fail

- name: Unit Test JS (known to be broken)
run: jlpm test || echo "TODO"
- name: Unit Test JS
run: jlpm test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


- name: Upload Coverage
run: codecov
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ dmypy.json
.pytest_cache/

.DS_Store
coverage/
9 changes: 6 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ const {
} = jlabConfig;

module.exports = {
coverageDirectory,
moduleFileExtensions,
moduleNameMapper: {...moduleNameMapper, "monaco-editor": "<rootDir>/node_modules/react-monaco-editor"},
moduleNameMapper,
preset,
setupFilesAfterEnv,
setupFiles,
testPathIgnorePatterns,
transform,
automock: false,
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/*.d.ts'],
coverageDirectory: 'coverage',
coverageReporters: ['lcov', 'text'],
reporters: ['default'],
testRegex: 'src/tests/.*.spec.ts[x]?$',
transformIgnorePatterns: ['/node_modules/(?!(@?jupyterlab.*)/)'],
transformIgnorePatterns: ['/node_modules/(?!(@?jupyterlab.*|react-spinners)/)'],
setupFiles: ['<rootDir>/setupJest.js'],
globals: {
'ts-jest': {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"clean:labextension": "rimraf jupyterlab_pullrequests/labextension",
"eslint": "eslint . --ext .ts,.tsx --fix",
"eslint:check": "eslint . --ext .ts,.tsx",
"test": "jest",
"test": "jest --coverage",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤤

"watch": "tsc -w"
},
"dependencies": {
Expand Down
12 changes: 6 additions & 6 deletions src/components/browser/PullRequestItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
linkIcon
} from '@jupyterlab/ui-components';
import { CommandRegistry } from '@lumino/commands';
import React, { useEffect, useState } from 'react';
import React from 'react';
import { BeatLoader } from 'react-spinners';
import { CommandIDs, IFile, IPullRequest } from '../../tokens';
import { requestAPI } from '../../utils';
Expand Down Expand Up @@ -49,21 +49,21 @@ export function PullRequestItem(props: IPullRequestItemProps): JSX.Element {
/**
* Pull request modified files
*/
const [files, setFiles] = useState<IFile[] | null>(null);
const [files, setFiles] = React.useState<IFile[] | null>(null);
/**
* Is the file list expanded?
*/
const [isExpanded, setIsExpanded] = useState<boolean>(false);
const [isExpanded, setIsExpanded] = React.useState<boolean>(false);
/**
* Is the file list being loaded?
*/
const [isLoading, setIsLoading] = useState<boolean>(false);
const [isLoading, setIsLoading] = React.useState<boolean>(false);
/**
* Error message
*/
const [error, setError] = useState<string | null>(null);
const [error, setError] = React.useState<string | null>(null);

useEffect(() => {
React.useEffect(() => {
setFiles(null);
setIsExpanded(false);
setIsLoading(false);
Expand Down
12 changes: 8 additions & 4 deletions src/components/discussion/Discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ export class Discussion extends Panel {
latestWidget.parent = null;
latestWidget.dispose();

this.addWidget(
this._inputShown ? this.createCommentInput() : this.createReplyButton()
);
if (this._inputShown) {
this.addWidget(this.createCommentInput());
} else if (this._thread.singleton !== true) {
this.addWidget(this.createReplyButton());
}
}
}

Expand Down Expand Up @@ -141,7 +143,9 @@ export class Discussion extends Panel {
if (this._inputShown) {
this.addWidget(this.createCommentInput());
} else {
this.addWidget(this.createReplyButton());
if (this._thread.singleton !== true) {
this.addWidget(this.createReplyButton());
}
}
}

Expand Down
32 changes: 32 additions & 0 deletions src/tests/Browser.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { shallow } from 'enzyme';
import 'jest';
import * as React from 'react';
import * as samplePRs from './sample-responses/samplepr.json';
import { IBrowserProps, Browser } from '../components/browser/Browser';

// Unit tests for PullRequestTab
describe('Browser', () => {
const DEFAULT_PROPS: IBrowserProps = {
commands: {} as any,
docRegistry: {} as any,
prGroups: [
{ name: 'group1', pullRequests: (samplePRs as any).default },
{ name: 'group2', pullRequests: (samplePRs as any).default }
]
};

// Test render
describe('#render()', () => {
const component = shallow(<Browser {...DEFAULT_PROPS} />);
it('should be a div', () => {
expect(component.find('div')).toHaveLength(1);
expect(component.find('.jp-PullRequestBrowser')).toHaveLength(1);
});
it('should have a list', () => {
expect(component.find('ul')).toHaveLength(1);
});
it('should have two BrowserGroup', () => {
expect(component.find('BrowserGroup')).toHaveLength(2);
});
});
});
84 changes: 84 additions & 0 deletions src/tests/BrowserGroup.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { shallow } from 'enzyme';
import 'jest';
import * as React from 'react';
import {
BrowserGroup,
IBrowserGroupProps
} from '../components/browser/BrowserGroup';
import { PullRequestItem } from '../components/browser/PullRequestItem';
import * as samplePRs from './sample-responses/samplepr.json';

// Unit tests for BrowserGroup
describe('BrowserGroup', () => {
const DEFAULT_PROPS: IBrowserGroupProps = {
commands: {} as any,
docRegistry: {} as any,
group: { name: 'group1', pullRequests: (samplePRs as any).default }
};

// Test render
describe('#render()', () => {
it('should be a list item', () => {
const component = shallow(<BrowserGroup {...DEFAULT_PROPS} />);
expect(component.find('li')).toHaveLength(1);
expect(component.find('.jp-PullRequestBrowserGroup')).toHaveLength(1);
});

it('should have a header with text props.header', () => {
const component = shallow(<BrowserGroup {...DEFAULT_PROPS} />);
expect(component.find('header h2')).toHaveLength(1);
expect(
component.contains([<h2 key={1}>{DEFAULT_PROPS.group.name}</h2>])
).toEqual(true);
});

it('should load group', () => {
const component = shallow(<BrowserGroup {...DEFAULT_PROPS} />);

expect(component.find('.jp-PullRequestBrowserGroupError')).toHaveLength(
0
);
expect(component.find('ul')).toHaveLength(1);
expect(component.find('.jp-PullRequestBrowserGroupList')).toHaveLength(1);
});

it('should load list item prs', () => {
const component = shallow(<BrowserGroup {...DEFAULT_PROPS} />);
expect(component.find(PullRequestItem)).toHaveLength(1);
});

it('should not have a group if there is an error', () => {
const component = shallow(
<BrowserGroup
{...DEFAULT_PROPS}
group={{
name: 'error',
pullRequests: [],
error: 'There is an error'
}}
/>
);
expect(component.find('ul')).toHaveLength(0);
expect(component.find('.jp-PullRequestBrowserGroupList')).toHaveLength(0);
});

it('should display error if one exists', () => {
const error = 'There is an error';
const component = shallow(
<BrowserGroup
{...DEFAULT_PROPS}
group={{
name: 'error',
pullRequests: [],
error
}}
/>
);

expect(component.find('.jp-PullRequestBrowserGroupError')).toHaveLength(
1
);
expect(component.contains(error)).toEqual(true);
});
});
});
Loading