pageSize?: number;
query?: string;
selected?: string;
-}): Promise<{ paging: T.Paging; results: Array<{ id: string; name: string; selected: boolean }> }> {
+}): Promise<{
+ paging: T.Paging;
+ results: Array<{ id: string; key: string; name: string; selected: boolean }>;
+}> {
return getJSON('/api/qualitygates/search', data).catch(throwGlobalError);
}
interface State {
lastSearchParams: SearchParams;
listHasBeenTouched: boolean;
- projects: Array<{ id: string; name: string; selected: boolean }>;
+ projects: Array<{ id: string; key: string; name: string; selected: boolean }>;
projectsTotalCount?: number;
selectedProjects: string[];
}
renderElement = (id: string): React.ReactNode => {
const project = find(this.state.projects, { id });
- return project === undefined ? id : project.name;
+ return (
+ <div className="select-list-list-item">
+ {project === undefined ? (
+ id
+ ) : (
+ <>
+ {project.name}
+ <br />
+ <span className="note">{project.key}</span>
+ </>
+ )}
+ </div>
+ );
};
render() {
searchProjects: jest.fn().mockResolvedValue({
paging: { pageIndex: 1, pageSize: 3, total: 55 },
results: [
- { id: 'test1', name: 'test1', selected: false },
- { id: 'test2', name: 'test2', selected: false },
- { id: 'test3', name: 'test3', selected: true }
+ { id: 'test1', key: 'test1', name: 'test1', selected: false },
+ { id: 'test2', key: 'test2', name: 'test2', selected: false },
+ { id: 'test3', key: 'test3', name: 'test3', selected: true }
]
}),
associateGateWithProject: jest.fn().mockResolvedValue({}),
it('should render correctly', async () => {
const wrapper = shallowRender();
await waitAndUpdate(wrapper);
+ expect(wrapper.instance().mounted).toBe(true);
expect(wrapper).toMatchSnapshot();
+ expect(wrapper.instance().renderElement('test1')).toMatchSnapshot();
+ expect(wrapper.instance().renderElement('test_foo')).toMatchSnapshot();
expect(searchProjects).toHaveBeenCalledWith(
expect.objectContaining({
page: 1
wrapper.setState({ lastSearchParams: { selected: Filter.All } as SearchParams });
expect(wrapper.find(SelectList).props().needReload).toBe(false);
+
+ wrapper.instance().componentWillUnmount();
+ expect(wrapper.instance().mounted).toBe(false);
});
it('should handle reload properly', async () => {
}
/>
`;
+
+exports[`should render correctly 2`] = `
+<div
+ className="select-list-list-item"
+>
+ <React.Fragment>
+ test1
+ <br />
+ <span
+ className="note"
+ >
+ test1
+ </span>
+ </React.Fragment>
+</div>
+`;
+
+exports[`should render correctly 3`] = `
+<div
+ className="select-list-list-item"
+>
+ test_foo
+</div>
+`;
renderElement = (key: string): React.ReactNode => {
const project = find(this.state.projects, { key });
- return project === undefined ? key : project.name;
+ return (
+ <div className="select-list-list-item">
+ {project === undefined ? (
+ key
+ ) : (
+ <>
+ {project.name}
+ <br />
+ <span className="note">{project.key}</span>
+ </>
+ )}
+ </div>
+ );
};
render() {
it('should render correctly', async () => {
const wrapper = shallowRender();
await waitAndUpdate(wrapper);
+ expect(wrapper.instance().mounted).toBe(true);
expect(wrapper).toMatchSnapshot();
+ expect(wrapper.instance().renderElement('test1')).toMatchSnapshot();
+ expect(wrapper.instance().renderElement('test_foo')).toMatchSnapshot();
expect(getProfileProjects).toHaveBeenCalled();
wrapper.setState({ listHasBeenTouched: true });
wrapper.setState({ lastSearchParams: { selected: Filter.All } as SearchParams });
expect(wrapper.find(SelectList).props().needReload).toBe(false);
+
+ wrapper.instance().componentWillUnmount();
+ expect(wrapper.instance().mounted).toBe(false);
});
it('should handle reload properly', async () => {
</div>
</Modal>
`;
+
+exports[`should render correctly 2`] = `
+<div
+ className="select-list-list-item"
+>
+ <React.Fragment>
+ test1
+ <br />
+ <span
+ className="note"
+ >
+ test1
+ </span>
+ </React.Fragment>
+</div>
+`;
+
+exports[`should render correctly 3`] = `
+<div
+ className="select-list-list-item"
+>
+ test_foo
+</div>
+`;