Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

UI - Operator #990

Merged
merged 35 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b41eb06
Improvements for new module Operator
Mar 12, 2021
bf0e571
Merge branch 'main' into feature/ui-operator
Mar 12, 2021
d172d95
Fix tests
Mar 12, 2021
9bd8145
Merge branch 'main' into feature/ui-operator
Mar 12, 2021
46dec27
remove unused test
Mar 15, 2021
ee2d3f2
fix tests
Mar 15, 2021
987de78
change patch path
Mar 16, 2021
3ba579a
improvements for new providers
Mar 18, 2021
5c8ffb8
improvements
Mar 18, 2021
e80608f
improve tests
Mar 19, 2021
4558d17
Merge branch 'main' of https://github.com/zupit/charlescd into featur…
Mar 19, 2021
11109dd
fix form typing
Mar 19, 2021
5715eb1
fix tests
Mar 19, 2021
f6ff2f2
remove unused import
Mar 19, 2021
458ae17
remove unused test
Mar 19, 2021
3ae962e
remove log
Mar 23, 2021
2c39c07
Merge branch 'main' into feature/ui-operator
celiofilhozup Apr 13, 2021
fae8ee9
Merge branch 'main' into feature/ui-operator
Apr 14, 2021
febd29e
fix butler url label
Apr 19, 2021
d444b0b
Merge branch 'main' into feature/ui-operator
Apr 20, 2021
5877bba
Fix localStorage for new workspace interface
Apr 20, 2021
32c24c2
fix git url validations
Apr 22, 2021
7ad24c2
update localStorage workspace
Apr 26, 2021
b3ba0de
Merge branch 'main' of https://github.com/ZupIT/charlescd into featur…
Apr 26, 2021
982a6e9
fix action after clicked workspace
Apr 27, 2021
5e5e9cb
fixes
Apr 27, 2021
2ae70b9
fix change workspace behavior
Apr 28, 2021
2ae68e3
Merge branch 'main' into feature/ui-operator
Apr 28, 2021
2a94f1e
fix tests
Apr 28, 2021
4f2d7d4
Adding DELETE before PATCH
May 3, 2021
98eb3af
Adding PATCH before DELETE
May 3, 2021
911951f
Fix Card.Config after remove
May 3, 2021
99b559e
Merge branch 'main' of https://github.com/ZupIT/charlescd into featur…
May 3, 2021
1b23ba0
Remove unused tests
May 3, 2021
4eafd38
Adding tests for helpers
May 3, 2021
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
4 changes: 0 additions & 4 deletions ui/src/core/components/Icon/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ const Icon = styled.i<WrapperProps>`
cursor: pointer;
transition: 0.2s;
padding: 0;

:hover {
transform: scale(1.1);
}
`};

> div > div {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/core/components/Modal/Wizard/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export const WizardItems = [
{
icon: 'empty-circles',
name: 'cdConfig',
menu: 'CD configuration',
title: 'CD configuration',
menu: 'Deployment configuration',
title: 'Deployment configuration',
backgroundColor: 'cdConfig',
size: '220px',
subtitle:
Expand Down
1 change: 1 addition & 0 deletions ui/src/core/providers/base/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface FetchProps {
save?: Function;
update?: Function;
remove?: Function;
status?: FetchStatuses;
}

const renewTokenByCb = (fn: () => Promise<Response>, isLoginRequest: boolean) =>
Expand Down
24 changes: 0 additions & 24 deletions ui/src/core/providers/cdConfiguration.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
* limitations under the License.
*/

import { render, screen } from 'unit-test/testUtils';
import FormCDConfiguration from '../Sections/CDConfiguration/Form';
import { DeploymentConfiguration } from 'modules/Settings/Credentials/Sections/DeploymentConfiguration/interfaces';
import { deleteRequest, postRequest } from './base';

const mockOnFinish = jest.fn();
const endpoint = '/moove/v2/configurations/deployment';
export const configPath = '/deploymentConfigurationId';

test('render CD Configuration form', async () => {
render(
<FormCDConfiguration onFinish={mockOnFinish}/>
);
export const create = (deploymentConfiguration: DeploymentConfiguration) =>
postRequest(`${endpoint}`, deploymentConfiguration);

const input = await screen.findByTestId('input-text-name');

expect(input).toBeInTheDocument();
});
export const removeDeploymentConfiguration = (id: string) =>
deleteRequest(`${endpoint}/${id}`);
4 changes: 2 additions & 2 deletions ui/src/core/providers/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export const updateName = (value: string) =>
export const addConfig = (path: string, value: string) =>
patchRequest(`${endpoint}/${getWorkspaceId()}`, 'replace', path, value);

export const delConfig = (path: string) =>
patchRequest(`${endpoint}/${getWorkspaceId()}`, 'remove', path);
export const delConfig = (path: string, value: string) =>
patchRequest(`${endpoint}/${getWorkspaceId()}`, 'remove', path, value);

export const testGitConnection = (data: GitConnectionTest) =>
baseRequest(`${mooveEndpoint}/configurations/git/connection-status`, data, {
Expand Down
29 changes: 24 additions & 5 deletions ui/src/core/utils/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,37 @@
* limitations under the License.
*/

import { Workspace } from 'modules/Users/interfaces/User';
import { Workspace } from 'modules/Workspaces/interfaces/Workspace';

const WORKSPACE_KEY = 'workspace';
const WORKSPACE = 'workspace';

export const getWorkspaceId = () => localStorage.getItem(WORKSPACE_KEY);
export const getWorkspaceId = () => {
const workspace = JSON.parse(localStorage.getItem(WORKSPACE)) as Workspace;
return workspace?.id;
};

export const clearWorkspace = () => {
localStorage.removeItem(WORKSPACE);
}

export const getWorkspace = (): Workspace => {
const ws = {
id: ''
} as Workspace;

export const clearWorkspace = () => localStorage.removeItem(WORKSPACE_KEY);
try {
const workspace : Workspace = JSON.parse(localStorage.getItem(WORKSPACE));
return workspace || ws;

} catch (e) {
return ws;
}
}

export const saveWorkspace = (workspace: Workspace) => {
clearWorkspace();

if (workspace) {
localStorage.setItem(WORKSPACE_KEY, workspace?.id);
localStorage.setItem(WORKSPACE, JSON.stringify(workspace));
}
};
4 changes: 2 additions & 2 deletions ui/src/modules/Main/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import Text from 'core/components/Text';
import { getProfileByKey } from 'core/utils/profile';
import { setUserAbilities } from 'core/utils/abilities';
import {
saveWorkspace,
getWorkspaceId,
clearWorkspace
clearWorkspace,
saveWorkspace
} from 'core/utils/workspace';
import { Workspace } from 'modules/Users/interfaces/User';
import { ExpandClick } from './Types';
Expand Down
157 changes: 71 additions & 86 deletions ui/src/modules/Modules/Comparation/Form/__tests__/helpers.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,164 +14,149 @@
* limitations under the License.
*/

import { waitFor } from 'unit-test/testUtils';
import { Helm } from "modules/Modules/interfaces/Helm";
import { githubProvider, gitlabProvider } from "modules/Settings/Credentials/Sections/CDConfiguration/constants";
import { validFields, createGitApi, destructHelmUrl, getHelmFieldsValidations } from "../helpers"
import {
validFields, createGitApi,
createGithubApi, destructHelmUrl,
validateSlash
} from "../helpers"

const githubProvider = 'GITHUB';
const gitlabProvider = 'GITLAB';

const invalidEmptyStringObject: Record<string, any> = {
key1: "",
};

const invalidNullObject: Record<string, any> = {
key1: undefined
};

const validObject: Record<string, any> = {
key1: "fake-value",
};

test("empty strings validFields", () => {
test("should empty strings validFields", () => {
const objectIsValid = validFields(invalidEmptyStringObject)

expect(objectIsValid).toBeFalsy()
});

test("undefined validFields", () => {
test("should undefined validFields", () => {
const objectIsValid = validFields(invalidEmptyStringObject)

expect(objectIsValid).toBeFalsy()
});

test("valid string validFields", () => {
test("should valid string validFields", () => {
const objectIsValid = validFields(validObject)

expect(objectIsValid).toBeTruthy()
});

test("createGitApi return github with all data", () => {
const helmData: Helm = {
helmBranch: "main",
helmOrganization: "zupit",
helmPath: "examplepath",
helmRepository: "examplerepo"
}
test("should validateSlash starts with '/'", () => {
const fieldName = 'field';
const validated = validateSlash('/github.com', fieldName);

const githubApi = createGitApi(helmData, githubProvider)
expect(githubApi).toBe("https://api.github.com/repos/zupit/examplerepo/contents/examplepath?ref=main")
})
expect(validated).toBe(`the ${fieldName} field should not start with "/"`);
});

test("createGitHubApi return github without path", () => {
const helmData: Helm = {
helmBranch: "main",
helmOrganization: "zupit",
helmRepository: "examplerepo"
}
test("should validateSlash ends with '/'", () => {
const fieldName = 'field';
const validated = validateSlash('https://github.com/', fieldName);

const githubApi = createGitApi(helmData, githubProvider)
expect(githubApi).toBe("https://api.github.com/repos/zupit/examplerepo/contents?ref=main")
})
expect(validated).toBe(`the ${fieldName} field should not ends with "/"`);
});

test("createGitApi return github without branch", () => {
test("should createGitApi [gitlab] without branch", () => {
const helmData: Helm = {
helmOrganization: "zupit",
helmRepository: "examplerepo"
helmProjectId: "123456",
helmUrl: "https://gitlab.com"
}

const githubApi = createGitApi(helmData, githubProvider)
expect(githubApi).toBe("https://api.github.com/repos/zupit/examplerepo/contents?ref=main")
const gitlabApi = createGitApi(helmData, gitlabProvider)
expect(gitlabApi).toBe("https://gitlab.com/api/v4/projects/123456/repository?ref=main")
})

test("createGitApi return gitlab with all data", () => {
test("should createGitApi [github] without branch", () => {
const helmData: Helm = {
helmBranch: "main",
helmOrganization: "zupit",
helmPath: "examplepath",
helmRepository: "examplerepo",
helmGitlabUrl: "https://examplegitlab.com"
helmUrl: "https://api.github.com"
}

const gitlabApi = createGitApi(helmData, gitlabProvider)
expect(gitlabApi).toBe("https://examplegitlab.com/api/v4/projects/zupit%2Fexamplerepo/repository/files/examplepath?ref=main")
const gitlabApi = createGitApi(helmData, githubProvider);
expect(gitlabApi).toBe("https://api.github.com/repos/zupit/examplerepo/contents?ref=main");
})

test("createGitLabApi return github without path", () => {
test("createGithubApi default", () => {
const helmData: Helm = {
helmBranch: "main",
helmOrganization: "zupit",
helmRepository: "examplerepo",
helmGitlabUrl: "https://examplegitlab.com"

helmUrl: 'https://api.github.com',
helmOrganization: 'zupit',
helmRepository: 'examplerepo',
helmPath: '',
helmBranch: 'main',
}

const gitlabApi = createGitApi(helmData, gitlabProvider)
expect(gitlabApi).toBe("https://examplegitlab.com/api/v4/projects/zupit%2Fexamplerepo/repository/files?ref=main")
const githubUrl = createGithubApi(helmData);
expect(githubUrl).toBe("https://api.github.com/repos/zupit/examplerepo/contents?ref=main");
})

test("createGitApi return github without branch", () => {
test("createGithubApi without branch", () => {
const helmData: Helm = {
helmOrganization: "zupit",
helmRepository: "examplerepo",
helmGitlabUrl: "https://examplegitlab.com"
helmUrl: 'https://api.github.com',
helmOrganization: 'zupit',
helmRepository: 'examplerepo',
helmPath: '',
helmBranch: '',
}

const gitlabApi = createGitApi(helmData, gitlabProvider)
expect(gitlabApi).toBe("https://examplegitlab.com/api/v4/projects/zupit%2Fexamplerepo/repository/files?ref=main")
const githubUrl = createGithubApi(helmData);
expect(githubUrl).toBe("https://api.github.com/repos/zupit/examplerepo/contents?ref=main");
})

test("destructHelmUrl github with full url", () => {
const setValue = jest.fn()
const fullUrl = "https://api.github.com/repos/zupit/examplerepo/contents/examplepath?ref=main"

destructHelmUrl(fullUrl, githubProvider, setValue)
expect(setValue).toHaveBeenCalledWith("helmOrganization", "zupit")
expect(setValue).toHaveBeenCalledWith("helmRepository", "examplerepo")
expect(setValue).toHaveBeenCalledWith("helmPath", "examplepath")
expect(setValue).toHaveBeenCalledWith("helmBranch", "main")
expect(setValue).toHaveBeenCalledWith("helmUrl", "https://api.github.com", {"shouldValidate": true});
expect(setValue).toHaveBeenCalledWith("helmOrganization", "zupit", {"shouldValidate": true});
expect(setValue).toHaveBeenCalledWith("helmRepository", "examplerepo", {"shouldValidate": true});
waitFor(() => expect(setValue).toHaveBeenCalledWith("helmPath", "examplepath", {"shouldValidate": true}));
waitFor(() => expect(setValue).toHaveBeenCalledWith("helmBranch", "main", {"shouldValidate": true}));
expect(setValue).toBeCalledTimes(5);
})

test("destructHelmUrl github without path", () => {
const setValue = jest.fn()
const fullUrl = "https://api.github.com/repos/zupit/examplerepo/contents?ref=main"

destructHelmUrl(fullUrl, githubProvider, setValue)
expect(setValue).toHaveBeenCalledWith("helmOrganization", "zupit")
expect(setValue).toHaveBeenCalledWith("helmRepository", "examplerepo")
expect(setValue).toHaveBeenCalledWith("helmBranch", "main")
expect(setValue).toHaveBeenCalledWith("helmUrl", "https://api.github.com", {"shouldValidate": true});
expect(setValue).toHaveBeenCalledWith("helmOrganization", "zupit", {"shouldValidate": true});
expect(setValue).toHaveBeenCalledWith("helmRepository", "examplerepo", {"shouldValidate": true});
expect(setValue).toHaveBeenCalledWith("helmBranch", "main", {"shouldValidate": true});
expect(setValue).toBeCalledTimes(5);
})


test("destructHelmUrl gitlab with full url", () => {
const setValue = jest.fn()
const fullUrl = "https://examplegitlab.com/api/v4/projects/zupit%2Fexamplerepo/repository/files/examplepath?ref=main"
const fullUrl = "https://gitlab.com/api/v4/projects/123456/repository?path=examplepath&ref=main"

destructHelmUrl(fullUrl, gitlabProvider, setValue)
expect(setValue).toHaveBeenCalledWith("helmOrganization", "zupit")
expect(setValue).toHaveBeenCalledWith("helmRepository", "examplerepo")
expect(setValue).toHaveBeenCalledWith("helmPath", "examplepath")
expect(setValue).toHaveBeenCalledWith("helmBranch", "main")
expect(setValue).toHaveBeenCalledWith("helmGitlabUrl", "https://examplegitlab.com")
expect(setValue).toBeCalledTimes(5)
expect(setValue).toHaveBeenCalledWith("helmUrl", "https://gitlab.com", {"shouldValidate": true});
expect(setValue).toHaveBeenCalledWith("helmProjectId", "123456", {"shouldValidate": true});
expect(setValue).toHaveBeenCalledWith("helmPath", "examplepath", {"shouldValidate": true});
expect(setValue).toHaveBeenCalledWith("helmBranch", "main", {"shouldValidate": true});
expect(setValue).toBeCalledTimes(4);
})

test("destructHelmUrl github without path", () => {
test("destructHelmUrl gitlab without path", () => {
const setValue = jest.fn()
const fullUrl = "https://examplegitlab.com/api/v4/projects/zupit%2Fexamplerepo/repository/files?ref=main"
const fullUrl = "https://gitlab.com/api/v4/projects/123456/repository?ref=main"

destructHelmUrl(fullUrl, gitlabProvider, setValue)
expect(setValue).toHaveBeenCalledWith("helmOrganization", "zupit")
expect(setValue).toHaveBeenCalledWith("helmRepository", "examplerepo")
expect(setValue).toHaveBeenCalledWith("helmBranch", "main")
expect(setValue).toBeCalledTimes(4)
});

test('should retun validation with required true', () => {
const result = getHelmFieldsValidations('some name');

expect(result.required).toHaveProperty('value', true);
expect(result.required).toHaveProperty('message', 'This field is required');
});

test('should retun validation with required false', () => {
const result = getHelmFieldsValidations('some name', false);
expect(result.required).toBe(null);
});
expect(setValue).toHaveBeenCalledWith("helmUrl", "https://gitlab.com", {"shouldValidate": true});
expect(setValue).toHaveBeenCalledWith("helmProjectId", "123456", {"shouldValidate": true});
expect(setValue).toHaveBeenCalledWith("helmBranch", "main", {"shouldValidate": true});
expect(setValue).toBeCalledTimes(4);
})
Loading