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

GCW-3432 Authentication routing #6

Merged
merged 49 commits into from
Dec 8, 2020
Merged

Conversation

BboyStatix
Copy link
Contributor

Ticket Link

https://jira.crossroads.org.hk/browse/GCW-3432

What does this PR do?

  • Adds basic login functionality (along with router tests) with a Login Page and a Home Page.
  • includes a simple login button to set the authentication state and navigate to the home page.
  • routing logic which handles scenarios such as accessing private routes as a non-authenticated user and accessing non-existent paths.

Essential for testing routing by allowing us to mock router history
Ionic uses this to handle animations related to navigation/routing
Component required by Ionic so rather not have to mock this out in tests
Components do not show up as expected on JSDOM with IonReactRouter
Latest version has compatibility issues esp. redirects
Reverting history ver. to 4 fixes the issue with redirects
Routing should be based on user auth status
Rely on actual DOM elements for testing rather than data-testid
index.ts convention makes it harder to distinguish tabs in editors
Don't rely on data-testid
Comment on lines 8 to 36
const renderComponent = (initialAuthState: boolean) => (
initialPath: string
) => {
const history = createMemoryHistory({ initialEntries: [initialPath] });
return {
history,
...render(
<AuthProvider initialAuthState={initialAuthState}>
<Router history={history}>
<MainRouter />
</Router>
</AuthProvider>
),
};
};

// TODO extend jest matchers instead
const expectToBeOnPage = (
container: HTMLElement,
myPath: string,
expectedPage: string
) => {
const expectedPath = `/${expectedPage}`;
expect(myPath).toEqual(expectedPath);
expect(container.querySelector(".ion-page")).toHaveAttribute(
"title",
expectedPage
);
};
Copy link
Member

Choose a reason for hiding this comment

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

If any of those helpers will be useful in the future, don't hesitate to put them in a helper file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good point, but I feel that at this point this function is not abstract enough to warrant its own file?

Copy link
Member

@patrixr patrixr left a comment

Choose a reason for hiding this comment

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

Looks good 👍

{ initialPath: "/login", expectedPage: "login" },
{ initialPath: "/login/1234", expectedPage: "login" },
{ initialPath: "/", expectedPage: "login" },
{ initialPath: "/bad-route", expectedPage: "login" },
Copy link
Member

Choose a reason for hiding this comment

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

do we want a 404 page ? 🤔 (just thinking out loud)

Choose a reason for hiding this comment

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

yeah, its nice to have one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@patrixr @bharat619 any reason for 404 page? Current implementation makes it impossible to reach such a page. What are the possible disadvantages of this?

Copy link
Member

Choose a reason for hiding this comment

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

I'm talking about future implementation, not current.
and I just like 404s

Copy link

@bharat619 bharat619 left a comment

Choose a reason for hiding this comment

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

Nice!!!

Just a question
Is it possible to move this from dependency to devDependency?

"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.4.0",
"@testing-library/user-event": "^8.0.3",
"@types/jest": "^24.0.25",

@BboyStatix BboyStatix self-assigned this Dec 4, 2020
@BboyStatix
Copy link
Contributor Author

Nice!!!

Just a question
Is it possible to move this from dependency to devDependency?

"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.4.0",
"@testing-library/user-event": "^8.0.3",
"@types/jest": "^24.0.25",

@bharat619 yeah good point but I saw this stack overflow answer from the react team https://stackoverflow.com/a/44872787
so kinda confused.

@BboyStatix BboyStatix merged commit dd7c56e into main Dec 8, 2020
@BboyStatix BboyStatix deleted the GCW-3432-authentication-routing branch January 26, 2021 05:06
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.

None yet

4 participants