Skip to content

Commit

Permalink
Merge pull request #45 from platformsh/43-copy-revisions
Browse files Browse the repository at this point in the history
43 copy revisions
  • Loading branch information
tylers-username committed Oct 3, 2023
2 parents ce517f9 + 4c19278 commit 14b2387
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 342 deletions.
2 changes: 1 addition & 1 deletion .upsun/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ applications:
# # Step 3: Add a service. Uncomment this section.
# ######################################################################################################################
# relationships:
# redis_session: "redis_persistent:redis"
# redis_session: "redis_persistent:redis"

# services:
# redis_persistent:
Expand Down
6 changes: 3 additions & 3 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Flask==2.0.1
Flask==3.0.0
Flask-Cors==3.0.10
python-dotenv==0.19.1
Flask-Session
redis
gunicorn
redis==4.5.4
gunicorn==21.2.0
24 changes: 1 addition & 23 deletions frontend/src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable testing-library/no-wait-for-multiple-assertions */
/* eslint-disable testing-library/no-node-access */
import { render, screen, waitFor } from "@testing-library/react";
import { render, screen } from "@testing-library/react";
import App from "./App";
import { fetchEnvironment } from "./utility/api";
import { act } from "react-dom/test-utils";
Expand All @@ -18,28 +18,6 @@ describe("<App />", () => {
jest.clearAllMocks();
});

it("should successfully fetch environment data and set the state", async () => {
const mockData = {
type: "staging",
session_storage: "redis",
};

// Use mockImplementationOnce
mockedFetchEnvironment.mockImplementationOnce(() =>
Promise.resolve(mockData),
);

render(<App />);

await screen.findByText(
mockData.type.charAt(0).toUpperCase() + mockData.type.slice(1),
);
expect(
screen.getByText(`User session service: ${mockData.session_storage}`),
).toBeInTheDocument();
expect(screen.getByText(`Scaling: Ready`)).toBeInTheDocument();
});

it("uses production intro for production when no changes have been made", async () => {
const mockData = {
type: "production",
Expand Down
363 changes: 197 additions & 166 deletions frontend/src/App.tsx

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions frontend/src/components/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ test("renders header component", () => {
expect(logoComponent).toBeInTheDocument();

// Assert that the text "Demo project" is rendered
const demoProjectText = screen.getAllByText("Demo project");
const demoProjectText = screen.getAllByText("Demo Guide Project");
expect(demoProjectText).toHaveLength(2);

// Assert that the "Powered by Platform.sh" text is rendered
const poweredByText = screen.getAllByText("Powered by Platform.sh");
expect(poweredByText).toHaveLength(2);

// Assert that the share button component is rendered
const shareButtonComponent = screen.getByText(/share/i);
expect(shareButtonComponent).toBeInTheDocument();
Expand Down
10 changes: 2 additions & 8 deletions frontend/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ function Header() {
title="Powered by Upsun"
/>
<span className="hidden md:inline-block font-sans-strong text-sm font-medium">
Demo project
</span>
<span className="hidden md:inline-block font-sans-strong text-sm font-normal pl-[1.5rem] pr-[1.125rem] border-l-[1px] border-upsun-black-900">
Powered by Platform.sh
Demo Guide Project
</span>
</div>
<div className="pull-right">
Expand All @@ -24,10 +21,7 @@ function Header() {
</div>
<div className="w-full md:hidden pt-3">
<span className="font-sans-strong text-sm font-medium">
Demo project
</span>
<span className="font-sans-strong text-sm font-normal pl-[1.5rem] pr-[1.125rem] border-l-[1px] border-upsun-black-900">
Powered by Platform.sh
Demo Guide Project
</span>
</div>
</header>
Expand Down
36 changes: 1 addition & 35 deletions frontend/src/components/Sidebar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { render, screen, within } from "@testing-library/react";
import { render, screen } from "@testing-library/react";
import Sidebar from "./Sidebar";

jest.mock("../assets/utility/production.svg", () => {
Expand Down Expand Up @@ -56,38 +56,4 @@ describe("<Sidebar />", () => {
expect(screen.getByText("staging-svg")).toBeInTheDocument();
expect(screen.getByText("Staging")).toBeInTheDocument();
});

test("environment status section renders file as session service when set", () => {
const props = {
environment: "Production",
sessionStorageType: "file",
};

render(<Sidebar {...props} />);

const storageSection = screen.getByTestId("status-session-storage");
expect(
within(storageSection).getByText("status-incomplete-svg"),
).toBeInTheDocument();
expect(
within(storageSection).getByText("User session service: file"),
).toBeInTheDocument();
});

test("environment status section renders redis as session service when set", () => {
const props = {
environment: "Production",
sessionStorageType: "redis",
};

render(<Sidebar {...props} />);

const storageSection = screen.getByTestId("status-session-storage");
expect(
within(storageSection).getByText("status-complete-svg"),
).toBeInTheDocument();
expect(
within(storageSection).getByText("User session service: redis"),
).toBeInTheDocument();
});
});
86 changes: 0 additions & 86 deletions frontend/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import CopyButton from "./CopyButton";
import { ReactComponent as ProductionIcon } from "../assets/utility/production.svg";
import { ReactComponent as StagingIcon } from "../assets/utility/staging.svg";
import { ReactComponent as StatusCompleteIcon } from "../assets/utility/status_complete.svg";
import { ReactComponent as StatusIncompleteIcon } from "../assets/utility/status_incomplete.svg";

interface SidebarProps {
environment: string | null;
Expand All @@ -25,89 +22,6 @@ const Sidebar: React.FC<SidebarProps> = ({
<h1>{environment}</h1>
</div>
</section>
<section className="w-1/2 sm:w-full">
<div className="environment-status flex flex-col gap-4">
<h2>Environment Status</h2>
<ul className="p-0 list-none flex flex-col gap-2">
<li
data-testid="status-session-storage"
className="flex flex-row items-center"
>
<div className="w-4 h-4 flex justify-center">
{sessionStorageType && sessionStorageType === "redis" ? (
<StatusCompleteIcon className="w-auto h-auto" />
) : (
<StatusIncompleteIcon className="w-auto h-auto" />
)}
</div>
<span className="pl-3.5">
User session service:{" "}
{sessionStorageType ? sessionStorageType : ""}
</span>
</li>
<li
data-testid="status-scaling-ready"
className="flex flex-row items-center"
>
<div className="w-4 h-4 flex justify-center">
{/* Upsun is always ready to scale! 🥇 */}
<StatusCompleteIcon className="w-auto h-auto" />
</div>
<span className="pl-3.5">Scaling: Ready</span>
</li>
</ul>
</div>
</section>
<section className="w-1/2 sm:w-full">
<div className="quick-commands flex flex-col gap-4">
<h2>Quick Commands</h2>

<ul className="p-0 list-none flex flex-col gap-2">

<li
data-testid="command-project-info"
className="flex flex-row items-center"
>
<div className="w-4 h-4 flex justify-center">
<StatusIncompleteIcon className="w-auto h-auto" />
</div>
<span className="pl-3.5">
<CopyButton className="hidden sm:inline-block w" copyText="upsun project:info">
<code className="px-4">upsun project:info</code>
</CopyButton>
</span>
</li>

<li
data-testid="command-resources-get"
className="flex flex-row items-center"
>
<div className="w-4 h-4 flex justify-center">
<StatusIncompleteIcon className="w-auto h-auto" />
</div>
<span className="pl-3.5">
<CopyButton className="hidden sm:inline-block w" copyText="upsun resources:get">
<code className="px-4">upsun resources:get</code>
</CopyButton>
</span>
</li>

<li
data-testid="command-relationships"
className="flex flex-row items-center"
>
<div className="w-4 h-4 flex justify-center">
<StatusIncompleteIcon className="w-auto h-auto" />
</div>
<span className="pl-3.5">
<CopyButton className="hidden sm:inline-block w" copyText="upsun relationships">
<code className="px-4">upsun relationships</code>
</CopyButton>
</span>
</li>
</ul>
</div>
</section>
</aside>
);
};
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,10 @@
}

.code-block > span > code {
display: block;
font-family: "Overpass Mono", monospace !important;
font-size: 0.75rem !important;
line-height: 1.25rem !important;
@apply block !font-mono !text-xs w-full text-left;
}

a {
color: var(--upsun-colors-yellow-400);
text-decoration: underline;
@apply text-upsun-yellow-400 underline
}
}
39 changes: 39 additions & 0 deletions frontend/src/utility/api.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { fetchEnvironment, EnvironmentResponseType, ENVIRONMENT_API_URI } from './api'; // Replace 'your-file-path' with the actual path

describe('fetchEnvironment', () => {
beforeEach(() => {
jest.resetAllMocks();
});

it('fetches environment successfully', async () => {
const mockData: EnvironmentResponseType = {
"session_storage": "some-file-storage",
"type": "some-environment"
};

global.fetch = jest.fn().mockImplementationOnce(() =>
Promise.resolve({
ok: true,
json: () => Promise.resolve(mockData),
} as Response)
);

const result = await fetchEnvironment();

expect(result).toEqual(mockData);
expect(fetch).toHaveBeenCalledTimes(1);
expect(fetch).toHaveBeenCalledWith(ENVIRONMENT_API_URI);
expect(result.session_storage).toBe(mockData.session_storage);
expect(result.type).toBe(mockData.type);
});

it('fetches environment and fails with an error', async () => {
global.fetch = jest.fn().mockImplementationOnce(() =>
Promise.resolve({
ok: false,
} as Response)
);

await expect(fetchEnvironment()).rejects.toThrow('Failed to fetch environment');
});
});
3 changes: 1 addition & 2 deletions frontend/src/utility/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { API_BASE_URL } from "../config";

type EnvironmentResponseType = {
export type EnvironmentResponseType = {
"session_storage": "redis" | "file" | string,
"type": "production" | "staging" | "development" | string
}
Expand All @@ -11,7 +11,6 @@ export const ENVIRONMENT_API_URI = `${API_BASE_URL}/${ENVIRONMENT_PATH}`;
export const fetchEnvironment = async (): Promise<EnvironmentResponseType> => {
const response = await fetch(ENVIRONMENT_API_URI);
if (!response.ok) {
console.log(response)
throw new Error('Failed to fetch environment');
}
const data = await response.json();
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
"start:backend": "cd backend && ./scripts/start.sh",
"start:frontend": "cd frontend && npm run build && npm run start",
"start": "clear && cross-env FORCE_COLOR=1 npm-run-all -l -p start:*",
"preinstall": "cross-env FORCE_COLOR=1 npm-run-all -l preinstall:*",
"preinstall:req-platform": "./utils/setup_platform.sh",
"postinstall": "cross-env FORCE_COLOR=1 npm-run-all -l postinstall:*",
"postinstall:backend": "cd backend && ./scripts/build.sh",
"postinstall:frontend": "cd frontend && npm install",
Expand All @@ -35,10 +33,7 @@
"cross-env": "^7.0.3",
"npm-run-all": "^4.1.5"
},
"otherDependencies": {
"platform": "4.10.0 (Wrapped)"
},
"engines": {
"node": "v18.16"
"node": ">=18.0.0"
}
}

0 comments on commit 14b2387

Please sign in to comment.