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

deploy app from git #510

Merged
merged 25 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e790fb2
deploy app from git, create option to deploy apps from git repositories
Nov 1, 2024
a4c4772
Merge branch 'main' into git-deploy-app
Nov 4, 2024
77135bf
added condtional on git options for headless state, added tests
Nov 4, 2024
f633168
added new index.js
Nov 4, 2024
5239395
fixed failing test
Nov 4, 2024
7dd2a23
adjusted updated code per comments
Nov 4, 2024
aecc392
updates saved to app-form
Nov 4, 2024
16f3fd6
app-card saved
Nov 4, 2024
32d7893
made updates to code from pr review
Nov 5, 2024
e5753f3
Rearranged the radio options to be below the titles
Nov 5, 2024
932dac1
Merge branch 'main' into git-deploy-app
Nov 7, 2024
752ad49
made updates per/requests; changed helper text, enabled disabled fiel…
Nov 7, 2024
eda4cc6
made updates per/requests; changed helper text, enabled disabled fiel…
Nov 7, 2024
79e1f86
updated index.js
Nov 7, 2024
d7edf77
Merge branch 'main' into git-deploy-app
Nov 8, 2024
4491397
updated form to take in editable config directory and ref
Nov 12, 2024
321be77
updated index
Nov 12, 2024
8c352d2
Merge branch 'main' into git-deploy-app
Nov 12, 2024
4f0578c
updated index.js
Nov 12, 2024
47fc679
updated index.js
Nov 12, 2024
0702f9e
added repository to server endpoint when git repo
Nov 12, 2024
9605785
Merge branch 'main' into git-deploy-app
Nov 14, 2024
3b191c5
fixed keep-alive and public on git repo app
Nov 14, 2024
985ebf6
updated error handling for git clone to use backend messaging
Nov 14, 2024
c7b4330
update Error message to be more generic
Nov 15, 2024
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
62 changes: 31 additions & 31 deletions jhub_apps/static/js/index.js

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions ui/src/components/app-card/app-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { UserState } from '@src/types/user';
import axios from 'axios';
import React, { useEffect, useState } from 'react';
import { useRecoilState } from 'recoil';

import {
currentApp,
currentNotification,
Expand Down Expand Up @@ -122,7 +123,7 @@ export const AppCard = ({
{
id: 'start',
title: 'Start',
onClick: () => {
onClick: async () => {
// Allow admins to start shared apps
if (isShared && !currentUserData?.admin) {
// Show error if it's a shared app
Expand All @@ -140,7 +141,7 @@ export const AppCard = ({
{
id: 'stop',
title: 'Stop',
onClick: () => {
onClick: async () => {
// Allow admins to stop shared apps
if (isShared && !currentUserData?.admin) {
setNotification(
Expand All @@ -157,8 +158,9 @@ export const AppCard = ({
{
id: 'edit',
title: 'Edit',
onClick: () =>
(window.location.href = `${API_BASE_URL}/edit-app?id=${id}`),
onClick: () => {
window.location.href = `${API_BASE_URL}/edit-app?id=${id}`;
},
visible: true,
disabled: isShared || id === '' || !isAppCard,
},
Expand Down
125 changes: 102 additions & 23 deletions ui/src/components/app-form/app-form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { app, environments, frameworks, profiles } from '@src/data/api';
import { currentUser } from '@src/data/user';
import axios from '@src/utils/axios';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { act, fireEvent, render } from '@testing-library/react';
import { act, fireEvent, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import MockAdapter from 'axios-mock-adapter';
import { BrowserRouter } from 'react-router-dom';
import { RecoilRoot } from 'recoil';
import { vi } from 'vitest';
import { currentUser as defaultUser } from '../../store';
import { AppForm } from './app-form';

Expand Down Expand Up @@ -42,7 +43,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand All @@ -60,7 +61,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand All @@ -82,7 +83,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand All @@ -102,7 +103,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand All @@ -128,7 +129,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand All @@ -152,7 +153,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand All @@ -174,7 +175,7 @@ describe('AppForm', () => {
<RecoilRoot initializeState={({ set }) => set(defaultUser, currentUser)}>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand Down Expand Up @@ -220,7 +221,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand Down Expand Up @@ -272,7 +273,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand Down Expand Up @@ -310,7 +311,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand Down Expand Up @@ -364,7 +365,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand Down Expand Up @@ -434,7 +435,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand Down Expand Up @@ -478,7 +479,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm id="app-1" />
<AppForm isEditMode={true} id="app-1" />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand Down Expand Up @@ -520,7 +521,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm id="app-1" />
<AppForm isEditMode={true} id="app-1" />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand Down Expand Up @@ -559,7 +560,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand All @@ -584,7 +585,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand Down Expand Up @@ -624,7 +625,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm id="app-1" />
<AppForm isEditMode={true} id="app-1" />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand Down Expand Up @@ -659,7 +660,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand Down Expand Up @@ -691,7 +692,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand Down Expand Up @@ -725,7 +726,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand All @@ -747,7 +748,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm />
<AppForm isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand Down Expand Up @@ -793,7 +794,7 @@ describe('AppForm', () => {
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm id="app-1" />
<AppForm isEditMode={true} id="app-1" />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
Expand Down Expand Up @@ -821,4 +822,82 @@ describe('AppForm', () => {
expect(window.location.pathname).not.toBe('/edit-app');
}
});

test('sets the branch to customRef or defaults to "main"', async () => {
render(
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm isEditMode={false} deployOption="git" />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
);

const branchField = screen.getByLabelText(/Branch/i);

// Simulate input to test default to 'main'
fireEvent.change(branchField, { target: { value: 'main' } });
expect(branchField).toHaveValue('main');

// Test updating customRef
fireEvent.change(branchField, { target: { value: 'new-branch' } });
expect(branchField).toHaveValue('new-branch');
});

test('sets customRef to an empty string when deployOption is "git" and customRef is empty', async () => {
render(
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm isEditMode={false} deployOption="git" />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
);

const branchField = screen.getByLabelText(/Branch/i);

// Simulate empty customRef for git deployOption
fireEvent.change(branchField, { target: { value: '' } });
expect(branchField).toHaveValue('');
});
test('displays "Invalid GitHub URL format" error when URL is in the wrong format', async () => {
render(
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm isEditMode={false} deployOption="git" />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
);

// Adjust the label text to match the exact rendering, if needed
const gitUrlInput = screen.getByLabelText(/Git Repository URL/i);
fireEvent.change(gitUrlInput, { target: { value: 'invalid-url' } });

const fetchButton = screen.getByText(/Fetch App Configuration/i);
await act(async () => {
fireEvent.click(fetchButton);
});

// Verify if the modal contains the error message
expect(screen.getByRole('dialog')).toHaveTextContent(
'Invalid GitHub URL format.',
);
});

test('renders git-url-input', () => {
render(
<RecoilRoot>
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<AppForm deployOption="git" isEditMode={false} />
</BrowserRouter>
</QueryClientProvider>
</RecoilRoot>,
);
expect(screen.getByTestId('git-url-input')).toBeInTheDocument();
});
});
Loading
Loading