-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All test passing, added commands to package and pre-commit (#244)
* All test passing, added commands to package and pre-commit * [nit] isLettersAndSpacesOnly * Corrected messages in signin and added valid test cases in generate * resolved comments * added pre-commit * css line change and pre-commit * added test cases for destroy API * added test and full coverage for add * Added test cases for upload, and corrected code * forgot, reset, signin and signout * verify * Added test, code and resolve minor issues * Corrected message for CORS in all test files
- Loading branch information
Showing
39 changed files
with
21,113 additions
and
27,791 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Pre-commit check | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- dev | ||
- tst | ||
- prd | ||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
steps: | ||
- name: Checkout repository content | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install run dependencies | ||
run: yarn install | ||
|
||
- name: Test Client | ||
run: yarn test:client | ||
|
||
- name: Test Server | ||
run: yarn test:server | ||
|
||
- name: Check formatting | ||
run: yarn check:client | ||
comment-on-pull-request: | ||
needs: pre-commit | ||
runs-on: ubuntu-latest | ||
if: failure() | ||
steps: | ||
- name: Send message to pull request | ||
uses: thollander/actions-comment-pull-request@v2 | ||
with: | ||
message: "Something failed: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,53 @@ | ||
import React from 'react'; | ||
import {render, screen, fireEvent} from '@testing-library/react'; | ||
import Dashboard from './Dashboard'; | ||
import {UserContext} from '../../contexts/UserContext'; | ||
|
||
describe('Dashboard Component', () => { | ||
const mockUserData = { | ||
firstName: 'Anoop', | ||
lastName: 'Singh', | ||
email: '[email protected]', | ||
userId: '99234290-a33b-40d1-a5d4-888e86d06cd1', | ||
userType: 'CUSTOMER', | ||
keys: [ | ||
{ | ||
keyId: '4d6544e38f5d4ad8bae546ea61e2b842', | ||
key: '4d6544e38f5d4ad8bae546ea61e2b842', | ||
usageCount: '0', | ||
keyDescription: 'Demo Key', | ||
updatedAt: new Date().toLocaleDateString('en-US', { | ||
day: '2-digit', | ||
month: 'short', | ||
year: 'numeric', | ||
}), | ||
createdAt: new Date().toLocaleDateString('en-US', { | ||
day: '2-digit', | ||
month: 'short', | ||
year: 'numeric', | ||
}), | ||
}, | ||
], | ||
subscription: { | ||
subscriptionId: '4d6544e3-8f5d-4ad8-bae5-46ea61e2b842', | ||
subscriptionType: 'HOBBY', | ||
keyLimit: 2, | ||
usageLimit: 500, | ||
isActive: false, | ||
createdAt: '2024-04-11T10:24:38.501Z', | ||
updatedAt: '2024-04-11T10:24:38.501Z', | ||
}, | ||
}; | ||
const renderDashboard = () => { | ||
render( | ||
<UserContext.Provider value={{userData: mockUserData}}> | ||
<Dashboard /> | ||
</UserContext.Provider>, | ||
); | ||
}; | ||
|
||
it('renders Dashboard with all its components', () => { | ||
render(<Dashboard />); | ||
renderDashboard(); | ||
const dashboardContainer = screen.getByTestId('testid-dashboard'); | ||
expect(dashboardContainer).toBeInTheDocument(); | ||
const currentPlanComponent = screen.getByText('Current Plan'); | ||
|
@@ -17,7 +60,7 @@ describe('Dashboard Component', () => { | |
expect(apiKeyTableComponent).toBeInTheDocument(); | ||
}); | ||
it('generates API key and adds to the list', () => { | ||
render(<Dashboard />); | ||
renderDashboard(); | ||
const descriptionInput = screen.getByLabelText('Description For API Key'); | ||
fireEvent.change(descriptionInput, {target: {value: 'Test API Key'}}); | ||
const generateButton = screen.getByText('Generate Key'); | ||
|
@@ -26,40 +69,42 @@ describe('Dashboard Component', () => { | |
expect(apiKeyDescription).toBeInTheDocument(); | ||
}); | ||
it('Delete API key and remove from the list', () => { | ||
render(<Dashboard />); | ||
renderDashboard(); | ||
const deleteButton = screen.getAllByTestId('api-key-delete'); | ||
fireEvent.click(deleteButton[0]); | ||
const deletedApiKeyDescription = screen.queryByText('Demo Key 1'); | ||
const deletedApiKeyDescription = screen.queryByText('Demo Key'); | ||
expect(deletedApiKeyDescription).not.toBeInTheDocument(); | ||
}); | ||
it('shows an error message when trying to generate a key without a description', async () => { | ||
render(<Dashboard />); | ||
renderDashboard(); | ||
const button = screen.getByText('Generate Key'); | ||
fireEvent.click(button); | ||
const errordocument = screen.getByText('Key Description cannot be empty'); | ||
const errordocument = screen.getByText('Description cannot be empty'); | ||
expect(errordocument).toBeInTheDocument(); | ||
}); | ||
|
||
it('shows an error message when trying to generate a key greater than 12 characters', () => { | ||
render(<Dashboard />); | ||
it('shows an error message when trying to generate a key greater than 20 characters', () => { | ||
renderDashboard(); | ||
const descriptionInput = screen.getByLabelText('Description For API Key'); | ||
fireEvent.change(descriptionInput, {target: {value: 'Test API Key'}}); | ||
fireEvent.change(descriptionInput, { | ||
target: {value: 'Long string text more than twenty characters'}, | ||
}); | ||
const generateButton = screen.getByText('Generate Key'); | ||
fireEvent.click(generateButton); | ||
const errordocument = screen.getByText( | ||
'Key Description cannot be more than 12 characters', | ||
'Description cannot be more than 20 characters', | ||
); | ||
expect(errordocument).toBeInTheDocument(); | ||
}); | ||
|
||
it('shows an error message when trying to generate a key having numbers', () => { | ||
render(<Dashboard />); | ||
renderDashboard(); | ||
const descriptionInput = screen.getByLabelText('Description For API Key'); | ||
fireEvent.change(descriptionInput, {target: {value: 'Test API 1222'}}); | ||
const generateButton = screen.getByText('Generate Key'); | ||
fireEvent.click(generateButton); | ||
const errordocument = screen.getByText( | ||
'Key Description must contain only alphabets and spaces', | ||
'Description must contain only alphabets and spaces', | ||
); | ||
expect(errordocument).toBeInTheDocument(); | ||
}); | ||
|
@@ -68,7 +113,11 @@ describe('Dashboard Component', () => { | |
global.navigator.clipboard = { | ||
writeText: jest.fn(), | ||
}; | ||
render(<Dashboard />); | ||
renderDashboard(); | ||
const descriptionInput = screen.getByLabelText('Description For API Key'); | ||
fireEvent.change(descriptionInput, {target: {value: 'Test API Key'}}); | ||
const generateButton = screen.getByText('Generate Key'); | ||
fireEvent.click(generateButton); | ||
const buttons = screen.getAllByTestId('api-key-copy'); | ||
fireEvent.click(buttons[0]); | ||
const inscreenirem = await screen.findByTestId('api-key-copied'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.