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

Add namespace to create environment form #361

Merged
merged 6 commits into from
Mar 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const EnvironmentCreate = ({ environmentNotification }: IEnvCreate) => {
return (
<Box sx={{ padding: "14px 12px" }}>
<EnvironmentDetailsHeader
namespace={newEnvironment.namespace}
onUpdateName={handleChangeName}
showEditButton={true}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ import {
interface IEnvironmentDetailsHeaderProps {
/**
* @param envName name of the selected environment
* @param namespace namespace of the environment
* @param onUpdateName change environment name
*/
envName?: string;
namespace?: string;
showEditButton: boolean | undefined;
onUpdateName: (value: string) => void;
}

export const EnvironmentDetailsHeader = ({
envName = "",
namespace,
onUpdateName,
showEditButton = true
}: IEnvironmentDetailsHeaderProps) => {
Expand All @@ -34,7 +37,8 @@ export const EnvironmentDetailsHeader = ({
sx={{
display: "flex",
alignItems: "center",
justifyContent: "space-between",
justifyContent:
mode === EnvironmentDetailsModes.CREATE ? "start" : "space-between",
marginBottom: "15px"
}}
>
Expand Down Expand Up @@ -64,9 +68,28 @@ export const EnvironmentDetailsHeader = ({
)}
{mode === EnvironmentDetailsModes.CREATE && (
<>
{namespace && (
<>
<TextField
label="Namespace"
value={namespace}
disabled
size="small"
/>
<div
gabalafou marked this conversation as resolved.
Show resolved Hide resolved
aria-hidden
style={{
borderRight: `2px solid ${palette.secondary.main}`,
transform: "skew(-15deg)",
margin: "0 1rem",
height: "1.6rem"
}}
/>
</>
)}
<TextField
autoFocus
placeholder="Environment name"
label="Environment name"
sx={{
backgroundColor: palette.grey[100],
minWidth: "450px",
Expand All @@ -76,11 +99,10 @@ export const EnvironmentDetailsHeader = ({
}}
inputProps={{
style: {
padding: "8px 15px",
fontSize: "15px",
color: palette.common.black
}
}}
size="small"
onChange={e => onUpdateName(e.target.value)}
/>
{/* <StyledButtonPrimary>Archive</StyledButtonPrimary> */}
Expand Down
25 changes: 23 additions & 2 deletions test/environmentDetails/EnvironmentDetailsHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("<EnvironmentDetailsHeader />", () => {
});
});

it("should render component in create mode", () => {
it("should render component in create mode without namespace", () => {
const mockOnUpdateName = jest.fn();
const component = render(
mockTheme(
Expand All @@ -70,9 +70,30 @@ describe("<EnvironmentDetailsHeader />", () => {
store.dispatch(modeChanged(EnvironmentDetailsModes.CREATE));
});

const input = component.getByPlaceholderText("Environment name");
const input = component.getByLabelText("Environment name");
const newEnvName = "My new environment name";
fireEvent.change(input, { target: { value: newEnvName } });
expect(mockOnUpdateName).toHaveBeenCalledWith(newEnvName);
expect(component.queryByText("Namespace")).not.toBeInTheDocument();
});

it("should render component in create mode with namespace", () => {
const mockOnUpdateName = jest.fn();
const component = render(
mockTheme(
Copy link
Contributor

Choose a reason for hiding this comment

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

For my own understanding: why use mockTheme instead of <MockTheme> for that component here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. Two things:

  1. I'm not super familiar with MUI or testing MUI. I was just patterning after what's already in this test file.
  2. The function mockTheme is not written as a functional React component, but it could be.

The utility function is so lightweight that I'm thinking it might be better to replace the call to mockTheme() everywhere with:

import { condaStoreTheme } from "../src/theme";
// ...
<ThemeProvider theme={condaStoreTheme}>
  <Provider store={store}>
    <ComponentUnderTest />
  </Provider>
</ThemeProvider>

<Provider store={store}>
<EnvironmentDetailsHeader
envName={undefined}
namespace="test-namespace"
onUpdateName={mockOnUpdateName}
showEditButton={true}
/>
</Provider>
)
);
act(() => {
store.dispatch(modeChanged(EnvironmentDetailsModes.CREATE));
});
expect(component.getByLabelText("Namespace")).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion test/playwright/test_ux.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _create_new_environment(page, screenshot=False):
if screenshot:
page.screenshot(path="test-results/conda-store-new-env.png")
# fill in the env name
page.get_by_placeholder("Environment name").fill(new_env_name)
page.get_by_label("Environment name").fill(new_env_name)
# fill in the description
page.get_by_placeholder("Enter here the description of your environment").fill("description")
# click the + to add a package
Expand Down
Loading