Skip to content
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
16 changes: 15 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ env:
CI: true
jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
environment:
name: ${{ matrix.environment-name }}
strategy:
fail-fast: true
matrix:
environment-name: ["ESS PodSpaces"]
os: [ubuntu-latest]
# Workspaces support was added from npm 7, so Node 14 isn't supported to
# build this library.
Expand All @@ -27,3 +30,14 @@ jobs:
# not being installed.
- run: npm ci
- run: npm run build
- run: npx playwright install --with-deps
- run: npm run e2e:test:setup
- run: npm t
env:
E2E_DEMO_CLIENT_APP_URL: http://localhost:3001
E2E_TEST_USER: ${{ secrets.E2E_TEST_USER }}
E2E_TEST_PASSWORD: ${{ secrets.E2E_TEST_PASSWORD }}
E2E_TEST_IDP: ${{ secrets.E2E_TEST_IDP }}
E2E_TEST_OWNER_CLIENT_ID: ${{ secrets.E2E_TEST_OWNER_CLIENT_ID }}
E2E_TEST_OWNER_CLIENT_SECRET: ${{ secrets.E2E_TEST_OWNER_CLIENT_SECRET }}
E2E_TEST_ENVIRONMENT: ${{ matrix.environment-name }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,5 @@ dist

# TernJS port file
.tern-port

test-results/
6 changes: 6 additions & 0 deletions e2e/browser/test-app/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: ["../../../.eslintrc.js", "next/core-web-vitals"],
parserOptions: {
project: "./tsconfig.json",
},
};
35 changes: 35 additions & 0 deletions e2e/browser/test-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
46 changes: 46 additions & 0 deletions e2e/browser/test-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, in the root of the project, run:

```bash
npm run build
```

Then, on the `test-app` directory, run:

```bash
npm ci
```

Then run the development server:

```bash
npm run dev
# or
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
109 changes: 109 additions & 0 deletions e2e/browser/test-app/components/appContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//
// Copyright 2022 Inrupt Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
// Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

// Disabling the following prevents from having to install before linting from
// the root.
// eslint-disable-next-line import/no-unresolved
import React, { useState, useEffect } from "react";
import {
login,
logout,
handleIncomingRedirect,
getDefaultSession,
ISessionInfo,
} from "@inrupt/solid-client-authn-browser";
import SolidClient from "../solidClient";

const REDIRECT_URL = window.location.href;
const APP_NAME = "Solid client browser-based tests app";
const DEFAULT_ISSUER = "https://login.inrupt.com/";

export default function AppContainer() {
const [sessionInfo, setSessionInfo] = useState<ISessionInfo>();
const [issuer, setIssuer] = useState<string>(DEFAULT_ISSUER);

useEffect(() => {
handleIncomingRedirect().then(setSessionInfo).catch(console.error);
}, []);

const handleLogin = async () => {
try {
// Login will redirect the user away so that they can log in the OIDC issuer,
// and back to the provided redirect URL (which should be controlled by your app).
await login({
redirectUrl: REDIRECT_URL,
oidcIssuer: issuer,
clientName: APP_NAME,
});
} catch (err) {
console.error(err);
}
};

const handleLogout = async () => {
await logout();
setSessionInfo(undefined);
};

return (
<>
<h1>{APP_NAME}</h1>
<p>
{sessionInfo?.isLoggedIn
? `Logged in as ${sessionInfo.webId}`
: "Not logged in yet"}
</p>
<form>
<input
data-testid="identityProviderInput"
type="text"
value={issuer}
onChange={(e) => {
setIssuer(e.target.value);
}}
/>
<button
data-testid="loginButton"
onClick={async (e) => {
e.preventDefault();
await handleLogin();
}}
>
Log In
</button>
<button
data-testid="logoutButton"
onClick={async (e) => {
e.preventDefault();
await handleLogout();
}}
>
Log Out
</button>
</form>
{sessionInfo?.isLoggedIn ? (
<SolidClient session={getDefaultSession()} />
) : (
<></>
)}
</>
);
}
149 changes: 149 additions & 0 deletions e2e/browser/test-app/components/solidClient/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
//
// Copyright 2022 Inrupt Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
// Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

// Disabling the following prevents from having to install before linting from
// the root.
// eslint-disable-next-line import/no-unresolved
import { useEffect, useState } from "react";
import {
createContainerInContainer,
getSourceIri,
deleteContainer,
getPodUrlAll,
} from "@inrupt/solid-client";
import { getDefaultSession, Session } from "@inrupt/solid-client-authn-browser";

interface CreateResourceButtonProps {
parentContainerUrl?: string;
handleCreateContainer: (containerUrl: string) => void;
}

const CreateResourceButton = ({
parentContainerUrl,
handleCreateContainer,
}: CreateResourceButtonProps) => {
return parentContainerUrl === undefined ? (
<></>
) : (
<button
onClick={async (e) => {
e.preventDefault();
handleCreateContainer(
getSourceIri(
await createContainerInContainer(parentContainerUrl, {
fetch: getDefaultSession().fetch,
})
)
);
}}
data-testid="createContainer"
>
Create container
</button>
);
};

interface DeleteResourceButtonProps {
childContainerUrl?: string;
handleDeleteContainer: () => void;
}

const DeleteResourceButton = ({
childContainerUrl,
handleDeleteContainer,
}: DeleteResourceButtonProps) => {
return childContainerUrl === undefined ? (
<></>
) : (
<button
onClick={async (e) => {
e.preventDefault();
if (childContainerUrl !== undefined) {
await deleteContainer(childContainerUrl, {
fetch: getDefaultSession().fetch,
});
handleDeleteContainer();
}
}}
data-testid="deleteContainer"
>
Delete container
</button>
);
};

export default function SolidClient({ session }: { session: Session }) {
const [parentContainerUrl, setParentContainerUrl] = useState<string>();
const [childContainerUrl, setChildContainerUrl] = useState<
string | undefined
>();

const handleCreateContainer = (containerUrl: string) =>
setChildContainerUrl(containerUrl);
const handleDeleteContainer = () => setChildContainerUrl(undefined);

useEffect(() => {
if (session.info.webId !== undefined) {
getPodUrlAll(session.info.webId as string, {
fetch: session.fetch,
})
.then((pods) => {
if (pods.length === 0) {
throw new Error("No pod root in webid profile");
}
setParentContainerUrl(pods[0]);
})
.catch(console.error);
}
}, [session]);

return (
<>
<p>
Parent container:{" "}
<em>
<span data-testid="parentContainerUrl">
{parentContainerUrl ?? "None"}
</span>
</em>
</p>
<p>
Child container:{" "}
<em>
<span data-testid="childContainerUrl">
{childContainerUrl ?? "None"}
</span>
</em>
</p>
{childContainerUrl ? (
<DeleteResourceButton
childContainerUrl={childContainerUrl}
handleDeleteContainer={handleDeleteContainer}
/>
) : (
<CreateResourceButton
parentContainerUrl={parentContainerUrl}
handleCreateContainer={handleCreateContainer}
/>
)}
</>
);
}
5 changes: 5 additions & 0 deletions e2e/browser/test-app/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
6 changes: 6 additions & 0 deletions e2e/browser/test-app/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
};

module.exports = nextConfig;
Loading