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

WebApp update - Code quality #37

Conversation

Omarley7
Copy link
Contributor

@Omarley7 Omarley7 commented Apr 10, 2023

  • Many issues from code climate have been addressed.
  • Added .gittattibute so WSL can run scripts on Windows machines with configuring line endings locally
  • Readme has been updated
  • React-tabs have been implemented instead of MUI tabs to reduce code and accommodate code climate issues.
  • Extended E2E test on menu to cover 100% of navigation

@Omarley7 Omarley7 requested a review from prasadtalasila April 10, 2023 13:58
@codecov-commenter
Copy link

codecov-commenter commented Apr 10, 2023

Codecov Report

Merging #37 (76c87f2) into feature/distributed-demo (c4abeaf) will increase coverage by 13.14%.
The diff coverage is 96.87%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@                      Coverage Diff                      @@
##           feature/distributed-demo      #37       +/-   ##
=============================================================
+ Coverage                     49.07%   62.21%   +13.14%     
=============================================================
  Files                            31       31               
  Lines                           324      352       +28     
  Branches                          2        7        +5     
=============================================================
+ Hits                            159      219       +60     
+ Misses                          163      127       -36     
- Partials                          2        6        +4     
Flag Coverage Δ
client-browser-test ∅ <ø> (∅)
client-unit-test 58.44% <96.87%> (+9.36%) ⬆️
lib-microservice 88.63% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
client/src/route/auth/AccountTabs.tsx 0.00% <0.00%> (ø)
client/src/components/Iframe.tsx 100.00% <100.00%> (ø)
client/src/components/tab/TabComponent.tsx 100.00% <100.00%> (+100.00%) ⬆️
...ent/src/components/tab/subcomponents/TabRender.tsx 100.00% <100.00%> (ø)
client/src/route/digitaltwins/DigitalTwins.tsx 100.00% <100.00%> (ø)
client/src/route/library/Library.tsx 100.00% <100.00%> (ø)
...nt/src/route/scenarioAnalysis/ScenarioAnalysis.tsx 100.00% <100.00%> (ø)
client/src/route/workbench/Workbench.tsx 100.00% <100.00%> (ø)

... and 4 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Omarley7 Omarley7 mentioned this pull request Apr 10, 2023
Copy link
Contributor

@prasadtalasila prasadtalasila left a comment

Choose a reason for hiding this comment

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

Other comments: I've missed these changes over time. The react-iframe npm package has been removed from src/components/Iframe.tsx. Doesn't it provide better functionality than the existing code?

await page.goto('/sanalysis');
await page.locator('div[role="button"]:has-text("Library")').click();
await expect(page).toHaveURL('/library');
links.forEach((link) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a strange convention. Usually we put code inside test.describe() function. Now we are iterating on the test() function itself. Can you move the link.forEach() into test.describe()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm pretty sure I read somewhere that it's also convention to loop outside of the test() function if needed (of course I failed to find where I read it).

  • In this case, we will have identical tests for each route. (Loop 1)
  • Each route navigates to every link to check if it works. (Loop 2)

Looping twice inside the test gave us many issues.

For now I've taken it out of the PR, and will look into it more in detail for the next PR.

await page.goto('/library');
await page.locator('div[role="button"]:has-text("Digital Twins")').click();
await expect(page).toHaveURL('/digitaltwins');
interface TestLink {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice refactoring

import TabPanel, { a11yProps } from 'components/tab/subcomponents/TabPanel';
import { useState, SyntheticEvent } from 'react';
import { Paper } from '@mui/material';
import TabRender from './subcomponents/TabRender';
Copy link
Contributor

Choose a reason for hiding this comment

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

There seems to be a circular dependency between TabComponents and TabRender.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also as a convention, things in parent directories depend on sub-directories, except when they are in different packages, or in different parts of directory structure. For example, code in src/components/subcomponents/TabRender.tsx can depend on src/utility/sample.tsx but not on src/components/Components.tsx.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DaloonOfDoom took a look at this and fixed it

@prasadtalasila
Copy link
Contributor

At this moment, about 75% of the code quality issues are in client/. Is it possible to fix more code quality issues in this PR?

@SyntaxXeror SyntaxXeror force-pushed the feature/distributed-demo branch from 8678627 to 7152af5 Compare April 19, 2023 11:35
@prasadtalasila
Copy link
Contributor

@Omarley7, the scope of this PR seems to be expanding quite a bit. Can you please list the improvements and downgrades made in this PR so far?
If there are already significant improvements, let's merge this and push further work into next PR. Thanks.

@Omarley7
Copy link
Contributor Author

@prasadtalasila I was hoping to include the issue discussed in #42.
I'll make an update on the work in this PR and move some of the E2E test stuff to the next PR.

Omarley7 and others added 17 commits April 20, 2023 11:41
* DUGK-57 Updated readme instructions.
Ultra clear build instructions.

* DUGK-57 removed 'test'
* DUGK-61 Refactored /e2e/Menu.test.ts

* DUGK-61 work in progress, not ready to merge

* DUGK-61 The test works for now

* DUGK-61 Fixed loop issue in menu test

---------

Co-authored-by: Omar <[email protected]>
Added gitattributes for line endings
Convert to react-tabs. Add unit tests. simplify type TabData
Husky now only checks certain directories within client
* removed husky

* DUGK-65 Removed husky from scripts

* DUGK-65 Pre-push Fixed.
Now comparing to origin/current-branch instead of default

* DUGK-65 Added config script and updated readme

* DUGK-65 Added hook script to prepare

* Formatting

* DUGK-65 CodeClimate issues fixed

* DUGK-65 Removed husky from readme.
Also changed echo to printf
Raised threshold of similar-code to 45 (default for TS) 
Fixed a lot of configuration errors.
Fixed additional codeclimate issues in client scripts.
If coverage is not met, the whole pipeline breaks instead of continuing.
This temp fix will run the tests twice. Collect coverage during second.
This allows test coverage below threshold to be uploaded.
Implemented global mocks.
Removed fullsize from iframe props.
Fixed all failing tests.
Added 'src/util/envUtil.ts' as getter for global env for easier testing.
'test/__mocks__/' now contains global mocks for components and page.
Removed all redundant render() functions from tests.
Replaced 'test/unitTest/config' dir with 'test/unitTest/jest.setup.ts'
Removed iframe mock. Needs to exists for tests. Can be located by title.
@Omarley7 Omarley7 force-pushed the feature/distributed-demo branch from b3c0222 to 072008f Compare April 20, 2023 09:41
- E2E menu test optimization
- Pipeline errors in test.bash
@Omarley7
Copy link
Contributor Author

Omarley7 commented Apr 20, 2023

Here's the update @prasadtalasila

Scope of this PR

Priority number 1 was to reduce CodeClimte issues. To achieve that the following changes have been made:

  • React-tabs have been implemented instead of MUI tabs to reduce code and complexity. It uses styled-components paradigm
  • All unit tests are now using global mocks and test utility. Greatly improves the implementation of the testing framework. Described in detail here.
  • Bash scripts now declare PATH before exporting
  • Removed middle routes like "workflows" and "components", as they are not needed yet and only increase the complexity
  • E2E test of menu has been successfully been reduced. await in for..of and forEach is not possible with async functions. Reduce can solve all these issues.

Pipeline improvements

  • Added .gittattibute so WSL can run scripts on Windows machines with configuring line endings locally
  • .codeclimate.yml has been updated from V1 to V2. Runs much better locally. It uses .eslintrc from the client since it was the only way we could make it work. You mentioned this as well in Next top-level changes to the project #24. Any reason why it was ruled out?
  • We have removed husky from the project, as git-hooks provide the same functionality and take care of Husky workflow mistakes #34 It has also been added to the <root>/README.md

Client improvements

  • .eslintrc has been corrected according to eslintrc check #36
  • Readme has been updated to improve installation processes (could use some feedback on this from @KarstenMalle or @Artin13. Does it make sense when you read it?)
  • React-Iframe has been reinstated. It was removed early on because its value wasn't understood in the beginning. Now we realize the type-safety is much better with this package.
  • Added interface description to data files in route directories
  • On the Digital Twin route, all iframe tabs now go to URL/label: e.g. https://example.com/models
  • Instead of using environment variables directly in the code, getter functions have been implemented in util/envUtils.ts Greatly improves testability.

Not covered yet

@Omarley7 Omarley7 requested a review from prasadtalasila April 20, 2023 10:49
@KarstenMalle
Copy link
Contributor

KarstenMalle commented Apr 20, 2023

@Omarley7

Readme looks good to us, only thing is that we have to use sudo for the bash script/install.bash, to install correctly since we use a Ubuntu VM, but i'm guessing it's not required with the suggested setup of "vagrant virtual machine".

@codeclimate
Copy link

codeclimate bot commented Apr 21, 2023

Code Climate has analyzed commit 76c87f2 and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 2

View more on Code Climate.

@prasadtalasila prasadtalasila merged commit 23330ad into INTO-CPS-Association:feature/distributed-demo Apr 21, 2023
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.

6 participants