-
Notifications
You must be signed in to change notification settings - Fork 378
Add new tag feature #1264
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
Merged
Merged
Add new tag feature #1264
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
6fc6ab8
Add new tag feature
DenisaCG a967541
remove debugging parts
DenisaCG 57922cf
cosmetic changes
DenisaCG 6ee8f5e
Apply cosmetic suggestions from code review
DenisaCG c55984e
fix dialog box scroll behavior and add tests
DenisaCG a2129db
change to function components
DenisaCG 3596235
fix states
DenisaCG 4e87d10
remove GitGraph when filtering and fix endpoint for creating a new tag
DenisaCG b1e78b1
add refresh tags list functionality
DenisaCG b889fe6
code improvements
DenisaCG bb06641
Apply suggestions from code review
DenisaCG 8234004
Update src/components/NewTagDialog.tsx
DenisaCG 0b71410
tests improvements
DenisaCG dca0d78
add useCallback hooks
DenisaCG edde7d6
fix TagMenu test
DenisaCG f705eb7
Apply suggestions from code review
DenisaCG a4e8f1e
fix TagMenu test
DenisaCG a4ecef9
Merge branch 'new-tag' of https://github.com/DenisaCG/jupyterlab-git …
DenisaCG 5168bce
lint files
DenisaCG b416142
delete unnecessary code
DenisaCG 527a907
Apply suggestions from code review
DenisaCG 979e188
fix switch tag test
DenisaCG 1e75b97
Merge branch 'new-tag' of https://github.com/DenisaCG/jupyterlab-git …
DenisaCG 6497df3
change all files to the new name for creating a new tag function
DenisaCG 6b2fa05
fix test_tag.py
DenisaCG 7bec388
Skip browser check for now
fcollonval File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DenisaCG marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| import { mount, shallow } from 'enzyme'; | ||
| import 'jest'; | ||
| import * as React from 'react'; | ||
| import { TagMenu, ITagMenuProps } from '../../components/TagMenu'; | ||
| import * as git from '../../git'; | ||
| import { Logger } from '../../logger'; | ||
| import { GitExtension } from '../../model'; | ||
| import { IGitExtension } from '../../tokens'; | ||
| import { listItemClass } from '../../style/BranchMenu'; | ||
| import { | ||
| mockedRequestAPI, | ||
| defaultMockedResponses, | ||
| DEFAULT_REPOSITORY_PATH | ||
| } from '../utils'; | ||
| import ClearIcon from '@material-ui/icons/Clear'; | ||
| import { nullTranslator } from '@jupyterlab/translation'; | ||
|
|
||
| jest.mock('../../git'); | ||
| jest.mock('@jupyterlab/apputils'); | ||
|
|
||
| const TAGS = [ | ||
| { | ||
| name: '1.0.0' | ||
| }, | ||
| { | ||
| name: 'feature-1' | ||
| }, | ||
| { | ||
| name: 'feature-2' | ||
| }, | ||
| { | ||
| name: 'patch-007' | ||
| } | ||
| ]; | ||
|
|
||
| async function createModel() { | ||
| const model = new GitExtension(); | ||
| model.pathRepository = DEFAULT_REPOSITORY_PATH; | ||
|
|
||
| await model.ready; | ||
| return model; | ||
| } | ||
|
|
||
| describe('TagMenu', () => { | ||
| let model: GitExtension; | ||
| const trans = nullTranslator.load('jupyterlab_git'); | ||
|
|
||
| beforeEach(async () => { | ||
| jest.restoreAllMocks(); | ||
|
|
||
| const mock = git as jest.Mocked<typeof git>; | ||
| mock.requestAPI.mockImplementation( | ||
| mockedRequestAPI({ | ||
| responses: { | ||
| ...defaultMockedResponses, | ||
| 'tags/delete': { | ||
| body: () => { | ||
| return { code: 0 }; | ||
| } | ||
| }, | ||
| checkout: { | ||
| body: () => { | ||
| return { | ||
| code: 0 | ||
| }; | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| ); | ||
|
|
||
| model = await createModel(); | ||
| }); | ||
|
|
||
| function createProps(props?: Partial<ITagMenuProps>): ITagMenuProps { | ||
| return { | ||
| branching: false, | ||
| pastCommits: [], | ||
| logger: new Logger(), | ||
| model: model as IGitExtension, | ||
| tagsList: TAGS.map(tag => tag.name), | ||
| trans: trans, | ||
| ...props | ||
| }; | ||
| } | ||
|
|
||
| describe('constructor', () => { | ||
| it('should return a new instance', () => { | ||
| const menu = shallow(<TagMenu {...createProps()} />); | ||
| expect(menu.instance()).toBeInstanceOf(TagMenu); | ||
| }); | ||
|
|
||
| it('should set the default menu filter to an empty string', () => { | ||
| const menu = shallow(<TagMenu {...createProps()} />); | ||
| expect(menu.state('filter')).toEqual(''); | ||
| }); | ||
|
|
||
| it('should set the default flag indicating whether to show a dialog to create a new tag to `false`', () => { | ||
| const menu = shallow(<TagMenu {...createProps()} />); | ||
| expect(menu.state('tagDialog')).toEqual(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('render', () => { | ||
| it('should display placeholder text for the menu filter', () => { | ||
| const component = shallow(<TagMenu {...createProps()} />); | ||
| const node = component.find('input[type="text"]').first(); | ||
| expect(node.prop('placeholder')).toEqual('Filter'); | ||
| }); | ||
|
|
||
| it('should set a `title` attribute on the input element to filter a tag menu', () => { | ||
| const component = shallow(<TagMenu {...createProps()} />); | ||
| const node = component.find('input[type="text"]').first(); | ||
| expect(node.prop('title').length > 0).toEqual(true); | ||
| }); | ||
|
|
||
| it('should display a button to clear the menu filter once a filter is provided', () => { | ||
| const component = shallow(<TagMenu {...createProps()} />); | ||
| component.setState({ | ||
| filter: 'foo' | ||
| }); | ||
| const nodes = component.find(ClearIcon); | ||
| expect(nodes.length).toEqual(1); | ||
| }); | ||
|
|
||
| it('should set a `title` on the button to clear the menu filter', () => { | ||
| const component = shallow(<TagMenu {...createProps()} />); | ||
| component.setState({ | ||
| filter: 'foo' | ||
| }); | ||
| const html = component.find(ClearIcon).first().html(); | ||
| expect(html.includes('<title>')).toEqual(true); | ||
| }); | ||
|
|
||
| it('should display a button to create a new tag', () => { | ||
| const component = shallow(<TagMenu {...createProps()} />); | ||
| const node = component.find('input[type="button"]').first(); | ||
| expect(node.prop('value')).toEqual('New Tag'); | ||
| }); | ||
|
|
||
| it('should set a `title` attribute on the button to create a new tag', () => { | ||
| const component = shallow(<TagMenu {...createProps()} />); | ||
| const node = component.find('input[type="button"]').first(); | ||
| expect(node.prop('title').length > 0).toEqual(true); | ||
| }); | ||
|
|
||
| it('should not, by default, show a dialog to create a new tag', () => { | ||
| const component = shallow(<TagMenu {...createProps()} />); | ||
| const node = component.find('NewTagDialogBox').first(); | ||
| expect(node.prop('open')).toEqual(false); | ||
| }); | ||
|
|
||
| it('should show a dialog to create a new tag when the flag indicating whether to show the dialog is `true`', () => { | ||
| const component = shallow(<TagMenu {...createProps()} />); | ||
| component.setState({ | ||
| tagDialog: true | ||
| }); | ||
| const node = component.find('NewTagDialogBox').first(); | ||
| expect(node.prop('open')).toEqual(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('switch tag', () => { | ||
| it('should not switch to a specified tag upon clicking its corresponding element when branching is disabled', () => { | ||
| const spy = jest.spyOn(GitExtension.prototype, 'checkoutTag'); | ||
|
|
||
| const component = mount(<TagMenu {...createProps()} />); | ||
| const nodes = component.find( | ||
| `.${listItemClass}[title*="${TAGS[1].name}"]` | ||
fcollonval marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
| nodes.at(0).simulate('click'); | ||
|
|
||
| expect(spy).toHaveBeenCalledTimes(0); | ||
| spy.mockRestore(); | ||
| }); | ||
|
|
||
| it('should switch to a specified tag upon clicking its corresponding element when branching is enabled', () => { | ||
| const spy = jest.spyOn(GitExtension.prototype, 'checkoutTag'); | ||
|
|
||
| const component = mount( | ||
| <TagMenu {...createProps({ branching: true })} /> | ||
| ); | ||
| const nodes = component.find( | ||
| `.${listItemClass}[title*="${TAGS[1].name}"]` | ||
fcollonval marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
| nodes.at(0).simulate('click'); | ||
|
|
||
| expect(spy).toHaveBeenCalledTimes(1); | ||
| expect(spy).toHaveBeenCalledWith(TAGS[1].name); | ||
|
|
||
| spy.mockRestore(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('create tag', () => { | ||
| it('should not allow creating a new tag when branching is disabled', () => { | ||
| const spy = jest.spyOn(GitExtension.prototype, 'setTag'); | ||
|
|
||
| const component = shallow(<TagMenu {...createProps()} />); | ||
|
|
||
| const node = component.find('input[type="button"]').first(); | ||
| node.simulate('click'); | ||
|
|
||
| expect(component.state('tagDialog')).toEqual(false); | ||
| expect(spy).toHaveBeenCalledTimes(0); | ||
| spy.mockRestore(); | ||
| }); | ||
|
|
||
| it('should display a dialog to create a new tag when branching is enabled and the new tag button is clicked', () => { | ||
| const spy = jest.spyOn(GitExtension.prototype, 'setTag'); | ||
|
|
||
| const component = shallow( | ||
| <TagMenu {...createProps({ branching: true })} /> | ||
| ); | ||
|
|
||
| const node = component.find('input[type="button"]').first(); | ||
| node.simulate('click'); | ||
|
|
||
| expect(component.state('tagDialog')).toEqual(true); | ||
| expect(spy).toHaveBeenCalledTimes(0); | ||
| spy.mockRestore(); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.