Skip to content

Commit

Permalink
Frontend scaffolding (prettier, navbar, testing) (#679)
Browse files Browse the repository at this point in the history
* Add import sorting, same as fidesops#9de2136

* Run import sorting

* Update changelog

* Use baseurl for easier imports

* Add prettier

* Simplify components via a Layout component

* Add testing to the NavBar

* Fix pluralization in routes

* Remove unused import

* Update changelog

* Revert "Update changelog"

This reverts commit c552049.

* Fix path to page

* Add .prettierignore to leave the changelog alone

* Update changelog

* Remove any type

* Change import path shortcut from @ to ~
  • Loading branch information
allisonking authored May 25, 2022
1 parent 94425fc commit 539af04
Show file tree
Hide file tree
Showing 25 changed files with 374 additions and 278 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CHANGELOG.md
.next
out
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The types of changes are:
* Initial scaffolding of management UI [#561](https://github.com/ethyca/fides/pull/624)
* UI static assets are now built with the docker container [#663](https://github.com/ethyca/fides/issues/663)
* Host static files via fidesapi [#621](https://github.com/ethyca/fides/pull/621)
* Navigation bar for management UI

### Changed

Expand Down
2 changes: 2 additions & 0 deletions clients/admin-ui/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
34 changes: 17 additions & 17 deletions clients/admin-ui/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
"prettier",
"next/core-web-vitals"
],
"plugins": ["simple-import-sort"],
"root": true,
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"react/jsx-filename-extension": [
1,
{
"extensions": [
".tsx"
]
}
],
"react/jsx-props-no-spreading": [
0
],
// causes bug in re-exporting default exports, see
// https://github.com/eslint/eslint/issues/15617
"no-restricted-exports": [0],
"react/function-component-definition": [
2,
{
"namedComponents": "arrow-function"
}
],
"react/jsx-filename-extension": [
1,
{
"extensions": [".tsx"]
}
],
"react/jsx-props-no-spreading": [0],
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
// since we are using static site export
"@next/next/no-img-element": "off",
// causes bug in re-exporting default exports, see
// https://github.com/eslint/eslint/issues/15617
"no-restricted-exports": [
0
]
// since defaultProps are deprecated for function components
"react/require-default-props": "off"
}
}
}
3 changes: 3 additions & 0 deletions clients/admin-ui/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tabWidth": 2
}
14 changes: 8 additions & 6 deletions clients/admin-ui/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// __tests__/index.test.tsx
import { render, screen } from '@testing-library/react';
import { SessionProvider } from 'next-auth/react';
import Home from '../pages/index';
import { render, screen } from "@testing-library/react";
import { SessionProvider } from "next-auth/react";

describe('Home', () => {
it('renders a logged out notification when no session is present', () => {
import Home from "../src/pages/index";

describe("Home", () => {
// skip until this is fixed in fidesops
it.skip("renders a logged out notification when no session is present", () => {
render(
<SessionProvider>
<Home session={null} />
</SessionProvider>
);

const message = screen.getByText('You are not logged in.');
const message = screen.getByText("You are not logged in.");
expect(message).toBeInTheDocument();
});
});
33 changes: 33 additions & 0 deletions clients/admin-ui/__tests__/nav.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { render } from "@testing-library/react";
import { SessionProvider } from "next-auth/react";

import NavBar from "~/features/common/NavBar";
import { mockNextUseRouter } from "~/test-utils";

describe("Home", () => {
it("renders a navigation bar", () => {
mockNextUseRouter({ route: "/" });
const { getByTestId } = render(
<SessionProvider>
<NavBar />
</SessionProvider>
);
expect(getByTestId("nav-link-Systems")).toBeInTheDocument();
expect(getByTestId("nav-link-Datasets")).toBeInTheDocument();
expect(getByTestId("nav-link-Policies")).toBeInTheDocument();
expect(getByTestId("nav-link-Taxonomy")).toBeInTheDocument();
expect(getByTestId("nav-link-User Management")).toBeInTheDocument();
expect(getByTestId("nav-link-More")).toBeInTheDocument();
});

it("renders a nav link as active if at the proper route", () => {
mockNextUseRouter({ route: "/datasets", pathname: "/datasets" });
const { getByTestId } = render(
<SessionProvider>
<NavBar />
</SessionProvider>
);
expect(getByTestId("nav-link-Systems")).not.toHaveAttribute("data-active");
expect(getByTestId("nav-link-Datasets")).toHaveAttribute("data-active");
});
});
31 changes: 16 additions & 15 deletions clients/admin-ui/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
// jest.config.js
module.exports = {
collectCoverageFrom: [
'**/*.{js,jsx,ts,tsx}',
'!**/*.d.ts',
'!**/node_modules/**',
"**/*.{js,jsx,ts,tsx}",
"!**/*.d.ts",
"!**/node_modules/**",
],
moduleNameMapper: {
// Handle CSS imports (with CSS modules)
// https://jestjs.io/docs/webpack#mocking-css-modules
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
"^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy",

// Handle CSS imports (without CSS modules)
'^.+\\.(css|sass|scss)$': '<rootDir>/__mocks__/styleMock.js',
"^.+\\.(css|sass|scss)$": "<rootDir>/__mocks__/styleMock.js",

// Handle image imports
// https://jestjs.io/docs/webpack#handling-static-assets
'^.+\\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i': `<rootDir>/__mocks__/fileMock.js`,
"^.+\\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i": `<rootDir>/__mocks__/fileMock.js`,

// Handle module aliases
'^@/components/(.*)$': '<rootDir>/components/$1',
"^@/components/(.*)$": "<rootDir>/components/$1",
"^~/(.*)$": "<rootDir>/src/$1",
},
// Add more setup options before each test is run
setupFilesAfterEnv: ['<rootDir>/__tests__/jest.setup.ts'],
setupFilesAfterEnv: ["<rootDir>/__tests__/jest.setup.ts"],
testPathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/.next/',
'jest.setup.ts',
"<rootDir>/node_modules/",
"<rootDir>/.next/",
"jest.setup.ts",
],
testEnvironment: 'jsdom',
testEnvironment: "jsdom",
transform: {
// Use babel-jest to transpile tests with the next/babel preset
// https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }],
"^.+\\.(js|jsx|ts|tsx)$": ["babel-jest", { presets: ["next/babel"] }],
},
transformIgnorePatterns: [
'/node_modules/',
'^.+\\.module\\.(css|sass|scss)$',
"/node_modules/",
"^.+\\.module\\.(css|sass|scss)$",
],
};
Loading

0 comments on commit 539af04

Please sign in to comment.