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 unittest for all react components #3404

Merged
merged 15 commits into from
Mar 20, 2023

Conversation

timizuoebideri1
Copy link
Contributor

Closes: #3239

What's Changed

TODO

  • Explanation of Change(s)
  • Added change log fragment(s) (for more information see the documentation)
  • Attached Screenshots, Payload Example
  • Unit, Integration Tests
  • Documentation Updates (when adding/changing features)
  • Example Plugin Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

@timizuoebideri1 timizuoebideri1 changed the base branch from develop to next-ui-2.0 March 8, 2023 16:14
Copy link
Member

@bryanculver bryanculver left a comment

Choose a reason for hiding this comment

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

😎

@timizuoebideri1 in lieu of any CI integration, can you include a quick doc on how to test this? Even if it's just in the README in the UI for now?

Copy link
Contributor

@HanlinMiao HanlinMiao left a comment

Choose a reason for hiding this comment

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

Awesome work, I learned a lot just by reading thru the PR.

What's our plan to run this in GitHub CI?

Comment on lines 11 to 15
jest.spyOn(global, 'fetch').mockImplementation(() =>
Promise.resolve({
text: () => Promise.resolve(mockHTML),
})
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can I get a comment on what this is doing?


// Check that a checkbox is rendered for each item
const checkboxes = screen.getAllByRole("checkbox");
expect(checkboxes.length).toBe(3);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be 2 here? Or do we have a checkbox for the headers as well?

Suggested change
expect(checkboxes.length).toBe(3);
expect(checkboxes.length).toBe(2);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, Including header

nautobot/ui/README.md Outdated Show resolved Hide resolved
timizuoebideri1 and others added 3 commits March 9, 2023 18:01
Co-authored-by: Hanlin Miao <46973263+HanlinMiao@users.noreply.github.com>
tasks.py Outdated
@@ -175,10 +175,11 @@ def run_command(context, command, **kwargs):
# Check if Nautobot is running; no need to start another Nautobot container to run a command
docker_compose_status = "ps --services --filter status=running"
results = docker_compose(context, docker_compose_status, hide="out")
docker_container = kwargs.pop("container", "nautobot")
Copy link
Member

Choose a reason for hiding this comment

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

I think the better approach would to make this a named argument in the function signature with a default?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, should be a service argument to match others

@timizuoebideri1 timizuoebideri1 marked this pull request as ready for review March 9, 2023 21:12
nautobot/ui/README.md Outdated Show resolved Hide resolved
Co-authored-by: Bryan Culver <31187+bryanculver@users.noreply.github.com>
Copy link
Member

@bryanculver bryanculver left a comment

Choose a reason for hiding this comment

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

There are some quality-of-life improvements @glennmatthews made in #3376 that should remove the issues I ran into with testing this locally (trying to run it before the Node modules were installed, containers not starting because of misconfigured waits) but both locally and in-container I was able to run both the NPM and Invoke commands and they passed, then failed when I changed the tests. 😎

tasks.py Outdated
"label": "Specify a directory to test instead of running all Nautobot UI tests.",
},
)
def ui_unittest(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please rename this to unittest_ui so that it naturally sorts in invoke --list next to unittest? Thank yoU!

@bryanculver bryanculver merged commit 21ba8ba into next-ui-2.0 Mar 20, 2023
@bryanculver bryanculver deleted the u/timizuoebideri1-3239-unittest-ui branch March 20, 2023 19:38
bryanculver added a commit that referenced this pull request Apr 25, 2023
* create list templete

* create add form view templete

* refactor and create NautobotInput Component

* move sites/ to dcim/sites/

* move react back one folder

* move react back one folder

* new changes

* new changes

* get model fields

* copy react files from plugin into nautobot frontend

* fix menu

* Work in progress on table

* json api

* Add get table fields

* fix table header

* Use absolte path

* slugify python

* Field groups

* Account for status and tags

* add react to example plugin

* push all code

* nautobot.2319 React UI components update

* add docker-compose.nodejs.yml to run an nginx reverse proxy for nautobot and nodejs

* remove unused ui prototype

* update to work with nextjs

* Revert "remove unused ui prototype"

This reverts commit 7bccab7.

* make react work?

* add object detail view

* remove comment

* remove comments

* add links to object detail view

* fix region

* Implement basic module federation for webpack

- Publishes `nautobot` module as `remoteEntry.js`
- Implemented webpack `config-overrides.js` using `react-app-rewired` as a dev dependency

* remove nextjs ui

* remove plugin file copy

* optimize dev docker environment

* Update react app build output paths

Output js to static/reactjs
Output css to static/reactcss

* use global router

* add postbuild script to move files to nautobot

* add navmenu headers

* convert prototype to nextjs

* fix some imports

* update to use cross site api calls

* remove nginx config

* update nautobot dev server to use uwsgi instead of runserver

* consolidate frontend pages, update django routing for react

* add plugin full width html fragment support

* fix detail page layout

* add plugin routes

* expose django's login/logout routes

* YEET

* Fixing some lints and bugs.

- Removed bad import in router
- Fixed linting errors for unused imports
- Fixed URL route on table item
- Improved Docker compose file to mount node_modules as a separate volume

* fix permissions issue on docker-compose in linux

* fix linux docker nodejs permissions (really)

* Make detail view generic

* stashing

* add paginator for list view

* yolo

* fix nautobot brand image, add some better looking icons

* stashing

* stashing

* replace react views with base.html that's derived from the react app's index.html

* Something broke but this is progress

* CustomViews and Plugin Components

* fix bug in detail view when json key name starts with underscore

* basic management command to generate ui

* tweaks

* Tweaks and update

* fixes and starts

* update dockerfile to match next

* update poetry lockfile

* linting and minor bug fixes

* clean up imports

* fix bug

* added nginx container in nodejs.yml and made nodejs serve up /static/js/bundle.js (#3057)

Co-authored-by: Hanlin Miao <hanlinmiao@Hanlins-MBP-2.home>

* fix runserver database exhaustion with nginx

* increase keepalive timeout on nginx connection

* Revert "increase keepalive timeout on nginx connection"

This reverts commit d3aabdd.

* increase keepalive timeout on nginx connection

* clean up api for plugin react components

* add web_url to all valid serializers

* remove debug logging

* add login view

* fix js error

* Implemented generic create view for React app.

- Requires the nested serialization changes.
- Implemented nested serialization using `?depth=`
    - Revert nested serializer and `brief=True` pattern
    - Replace it with `depth=?` arguments to views and rendering forms from JSON schema using `drf-react-template-framework`
    - Commented out all `brief=` and associated code
- Updated `RegionSerializer` to have `parent` field fallback to default.

* First pass at #3204 (#3252)

* Some low-hanging fruit fixes to get us closer back to next

* next-ui-2.0 cleanup and commenting (#3285)

* Remove unused code added to example_plugin

* Add a bunch of TODO comments

* More TODO comments

* Black

* Flake8

* Markdownlint

* Pylint

* Removing some more stuff that's not needed at present

* Revert a few things back to baseline

* One more deletion

* Fixes to example_plugin and example_plugin_with_view_override

* Update comments and address a couple of TODOs

* More TODO updates

* web_url fixup

* Added a `nautobot-server build_ui` command (#3306)

- This command does the following from the `nautobot/ui` directory
  - Generates the `app_imports.js` file from any installed plugins
  - Runs `npm install` when `--npm-install` is passed
  - Runs `npm run build`
- This command is now also called by `nautobot-server post_upgrade`, which calls it with `--npm-install`
- Updated the `config-overrides.js` to not hash JS or CSS files so that their raw filename can be stored in static files and referenced using `{% static %}` (e.g. `{% static 'js/main.js %}`) without having to overload the `base.html` template for the web UI
- Updated `nautobot/core/templates/base.html` to link directly to the static files for JS and CSS that get pulled in from the UI build environment by `nautobot-server collectstatic` 
- Parameterized the API key needed for now to read from `NAUTOBOT_API_TOKEN` environment variable
- `app_imports.js` now renders with relative paths vs. absolute paths making commits that happen compatible across Docker-local and production use-cases.
- Restored the `/plugins/` route and the `InstalledPlugins.jsx` module
- The `build` command runs `npm` silently by default to hide the debug/warn/error messages unless `-v 2` or `-v 3` are passed.
- There is some `console.log` output that is now not displayed unless `NAUTOBOT_DEBUG` environment variable is set. The `build_ui` command will also set this if verbosity is desired.
- Implemented a new `invoke version` task to align versions of core with UI apps.
  - Will bump both `pyproject.toml` and `package.json` to keep them in sync.
  - If no argument is provided, displays the versions instead.
- Also added `NAUTOBOT_UI_DIR` into `nautobot.core.settings` so that it can be easily reused
- Moved `nautobot_ui` to `nautobot/ui`
- `nautobot/ui` is now included in the package build
- Added a basic README file back to `nautobot/ui`
- Renamed all UI references of "plugin" to "app"

After using `build_ui` it's possible to serve the entire application using Django now without requiring `node`. Of course for development `node` will still be desirable due to live rendering.

* setState for islogged in

* Revert "setState for islogged in"

This reverts commit 596d9c1.

* remove ourrunserver reference in docker compose (#3366)

* UI 2.0 remove nginx container (#3367)

* Initial removal of react-bootstrap and addition of nautobot-ui

* Clean up devDependencies

* Simplify tasks.py

* Updates from feedback

* Add node_modules ignore

* move 'api/' ui related urls under 'api/ui/' (#3385)

* move 'api/' ui related urls under 'api/ui/'

* flake8

* address PR feedback

* exclude get-menu api endpoint from OpenAPI schema and add documentation for UI-related API endpoints

* flake8

* mdlint

* elaborate UI-related endpoints documentation

* update mkdocs.yml

---------

Co-authored-by: Hanlin Miao <hanlinmiao@Hanlins-MBP-2.home>

* Logged in state for nautobot-ui (#3356)

* Update from fix nautobot/nautobot-ui#9

* Black

* Hadolint

* More hadolint

* UI docker dev environment tweaks (#3408)

* Don't copy node_modules and UI build when rebuilding docker image

* Capture npm output and print it in case of failures

* Create docker volume for node_modules, change container startup, update docs

* nautobot-ui is public now; can use node:18-slim

* Add TODO comments

* Add unittest for all react components (#3404)

* Add test for component common

* common test case

* Done testing core

* Add test for BSTableItem Component

* Add partial views test

* Add test for views

* add doc

* run ui unittest

* Apply suggestions from code review

Co-authored-by: Hanlin Miao <46973263+HanlinMiao@users.noreply.github.com>

* fix markdown

* update ReadMe

* Update nautobot/ui/README.md

Co-authored-by: Bryan Culver <31187+bryanculver@users.noreply.github.com>

* Merge conflicts

* Update README.md

---------

Co-authored-by: Hanlin Miao <46973263+HanlinMiao@users.noreply.github.com>
Co-authored-by: Bryan Culver <31187+bryanculver@users.noreply.github.com>
Co-authored-by: Bryan Culver <bryan.culver@networktocode.com>

* UI 2.0 Cleanup (#3444)

* Provide a way to refresh CSRF without shortcutting CSRF protections

* Session endpoint

* Stashing to switch between computers

* more stashing

* yeeet

* This is going to be a lot

* Updates

* Updates from feedback

* Black & flake8

* Fix indention

* Remove top-level package lock

* Revert bad merge

* UI 2.0: Cleanup Router Links, Import Font as Source (#3482)

* Cleanup Router Links

* Move font to built-in instead of served via Google Fonts.

* Remove unneccessary import

* UI 2.0: Introduce Prettier, Use ESLint for Formatting and Linting (#3531)

* Move to craco (#3546)

Fix Jest testing

Remove should be ignored paths file as this is autogenerated

Scope creep avoid get tests passing so we can demonstrate it's working.

Prettier...

Add base paths for testing

No cached example, just copy the template in CI

Mock would prefer a file exists for app_imports.js

* Add New UI Toggle (#3615)

* Add New UI Toggle

* Add changelog fragment.

* Prettier

* Fix corrupted package-lock.json (#3618)

* Fix corrupted package-lock.json

* Add changelog fragment.

* Remove duplicate package for nautbot-ui

* Get tests passing for UI 2.0 (#3632)

* Get tests passing for UI 2.0

* Add changelog fragment.

* Updates from feedback

* Exception handling

* Fix CI step merge

* Pylint

* Fix changes from next

* UI 2.0 Implement GenericView component (#3626)

* [UI 2.0] Implement GenericView component

* [UI 2.0] Add missing objectData prop to GenericView in ObjectRetrieve view

* [UI 2.0] Remove Current route is ... debug message

* Move popover to it's own component.

---------

Co-authored-by: Bryan Culver <bryan.culver@networktocode.com>
Co-authored-by: Bryan Culver <me@bryanculver.com>

* 👟

---------

Co-authored-by: Timizuo <timizuoebideri@gmail.com>
Co-authored-by: Chris Thant <chris.thant@networktocode.com>
Co-authored-by: Gary Snider <gary.snider@networktocode.com>
Co-authored-by: jathanism <jathan@gmail.com>
Co-authored-by: Hanlin Miao <46973263+HanlinMiao@users.noreply.github.com>
Co-authored-by: Hanlin Miao <hanlinmiao@Hanlins-MBP-2.home>
Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>
Co-authored-by: Gary Snider <75227981+gsnider2195@users.noreply.github.com>
Co-authored-by: Timizuo <94907097+timizuoebideri1@users.noreply.github.com>
Co-authored-by: Norbert Mieczkowski <117445994+norbert-mieczkowski-codilime@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UI 2.0: UI-specific Unit Tests of Components, Views (specific to the front-end)
6 participants