-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from manh-t/release/0.2.0
Release - 0.2.0
- Loading branch information
Showing
46 changed files
with
1,864 additions
and
606 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,3 @@ | ||
{ | ||
"plugins": [["@babel/plugin-proposal-private-property-in-object", { "loose": true }]] | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { post } from 'adapters/Base'; | ||
import { config } from 'config'; | ||
|
||
import { signIn } from '.'; | ||
|
||
jest.mock('adapters/Base'); | ||
jest.mock('config'); | ||
|
||
describe('AuthenticationAdapter', () => { | ||
beforeEach(() => { | ||
(post as jest.Mock).mockImplementation(() => jest.fn()); | ||
(config as jest.Mock).mockImplementation(() => ({ | ||
clientId: 'client id', | ||
clientSecret: 'client secret', | ||
})); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('signIn', () => { | ||
describe('given an email and a password', () => { | ||
it('calls the post method from the base adapter', () => { | ||
const email = '[email protected]'; | ||
const password = 'test'; | ||
|
||
const expectedPath = 'oauth/token'; | ||
const expectedPayload = { | ||
grantType: 'password', | ||
clientId: config().clientId, | ||
clientSecret: config().clientSecret, | ||
email, | ||
password, | ||
}; | ||
|
||
signIn(email, password); | ||
|
||
expect(post).toHaveBeenCalledWith(expectedPath, expectedPayload); | ||
}); | ||
}); | ||
}); | ||
}); |
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,11 @@ | ||
import { post } from 'adapters/Base'; | ||
import { config } from 'config'; | ||
|
||
export const signIn = (email: string, password: string) => | ||
post('oauth/token', { | ||
clientId: config().clientId, | ||
clientSecret: config().clientSecret, | ||
grantType: 'password', | ||
email: email, | ||
password: password, | ||
}); |
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,49 @@ | ||
/* eslint-disable camelcase */ | ||
import requestManager from 'lib/request/v1/requestManager'; | ||
|
||
import { get, post } from '.'; | ||
|
||
jest.mock('lib/request/v1/requestManager', () => jest.fn()); | ||
|
||
describe('BaseAdapter', () => { | ||
const apiPath = '/sample'; | ||
const params = { | ||
testKey: 'test value', | ||
}; | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('GET', () => { | ||
describe('given only the api path', () => { | ||
it('calls the GET method from request manager with the path and no params', () => { | ||
get(apiPath); | ||
|
||
expect(requestManager).toHaveBeenCalledWith('get', apiPath, {}); | ||
}); | ||
}); | ||
|
||
describe('given the api path and url params', () => { | ||
it('calls the get method from request manager with the path and params with snake case keys', () => { | ||
get(apiPath, params); | ||
|
||
expect(requestManager).toHaveBeenCalledWith('get', apiPath, { | ||
params: { test_key: params.testKey }, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('POST', () => { | ||
describe('given the path and url params', () => { | ||
it('calls the post method from request manager with the path and data with snake case key', () => { | ||
post(apiPath, params); | ||
|
||
expect(requestManager).toHaveBeenCalledWith('post', apiPath, { | ||
data: { test_key: params.testKey }, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,19 @@ | ||
import { AxiosRequestConfig } from 'axios'; | ||
|
||
import { JSONObject, keysToSnakeCase } from 'helpers/json'; | ||
import requestManager from 'lib/request/v1/requestManager'; | ||
|
||
export function get(path: string, params?: JSONObject) { | ||
const requestOptions: AxiosRequestConfig = {}; | ||
if (params) { | ||
requestOptions.params = keysToSnakeCase(params); | ||
} | ||
|
||
return requestManager('get', path, requestOptions); | ||
} | ||
|
||
export const post = (path: string, params: JSONObject) => { | ||
const requestOptions: AxiosRequestConfig = { data: keysToSnakeCase(params) }; | ||
|
||
return requestManager('post', path, requestOptions); | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,19 @@ | ||
import React from 'react'; | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
|
||
import Alert from '.'; | ||
|
||
describe('Alert', () => { | ||
const errors = ['Error 1']; | ||
const dataTestId = 'alert'; | ||
|
||
it('renders an alert and its component', () => { | ||
render(<Alert errors={errors} data-test-id={dataTestId} />); | ||
|
||
const alert = screen.getByTestId(dataTestId); | ||
|
||
expect(alert).toBeVisible(); | ||
expect(alert).toHaveTextContent('Error 1'); | ||
}); | ||
}); |
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,25 @@ | ||
import React from 'react'; | ||
|
||
import { ReactComponent as AlertIcon } from 'assets/images/icons/alert.svg'; | ||
|
||
interface AlertProps { | ||
errors: string[]; | ||
'data-test-id'?: string; | ||
} | ||
const Alert = ({ errors, ...rest }: AlertProps): JSX.Element => ( | ||
<div role="alert" {...rest}> | ||
<div className="bg-black-raisin bg-opacity-60 rounded-xl px-4 py-4 flex flex-row"> | ||
<AlertIcon className="mr-[19px] text-white" /> | ||
<div> | ||
<p className="text-small text-white font-extrabold mb-2">Error</p> | ||
<ul className="list-disc list-inside text-white opacity-60 text-x-small"> | ||
{errors.map((error, index) => ( | ||
<li key={`${index}${error}`}>{error}</li> | ||
))} | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
|
||
export default Alert; |
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,17 @@ | ||
import React from 'react'; | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
|
||
import DashboardEmpty from '.'; | ||
|
||
describe('DashboardEmpty', () => { | ||
it('renders DashboardEmpty and its components', () => { | ||
const dataTestId = 'dashboard-empty'; | ||
render(<DashboardEmpty data-test-id={dataTestId} />); | ||
|
||
const dashboardEmpty = screen.getByTestId(dataTestId); | ||
|
||
expect(dashboardEmpty).toBeVisible(); | ||
expect(dashboardEmpty).toHaveTextContent('😎You‘ve completed all the surveys.Take a moment.'); | ||
}); | ||
}); |
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,20 @@ | ||
import React from 'react'; | ||
|
||
interface DashboardEmptyProps { | ||
'data-test-id'?: string; | ||
} | ||
|
||
const DashboardEmpty = (attributes: DashboardEmptyProps): JSX.Element => { | ||
return ( | ||
<div className="flex flex-col items-center" {...attributes}> | ||
<p className="text-[64px]">😎</p> | ||
<p className="text-white text-large font-[850] text-center mt-8"> | ||
You‘ve completed all the surveys. | ||
<br /> | ||
Take a moment. | ||
</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DashboardEmpty; |
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,30 @@ | ||
import React from 'react'; | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
|
||
import DashboardHeader from '.'; | ||
|
||
describe('DashboardHeader', () => { | ||
const dataTestId = 'dashboard-header'; | ||
it('renders DashboardHeader and its components', () => { | ||
const dateTime = 'Monday, JUNE 15'; | ||
const daysAgo = 'Today'; | ||
const profileUrl = 'test url'; | ||
render( | ||
<DashboardHeader dateTime={dateTime} daysAgo={daysAgo} profileUrl={profileUrl} data-test-id={dataTestId}> | ||
Dashboard Header | ||
</DashboardHeader> | ||
); | ||
|
||
const dashboardHeader = screen.getByTestId(dataTestId); | ||
const avatar = screen.getByAltText('user avatar'); | ||
|
||
expect(dashboardHeader).toBeVisible(); | ||
expect(dashboardHeader).toHaveTextContent(dateTime); | ||
expect(dashboardHeader).toHaveTextContent(dateTime); | ||
expect(dashboardHeader).toHaveTextContent(dateTime); | ||
|
||
expect(avatar).toBeVisible(); | ||
expect(avatar).toHaveAttribute('src', profileUrl); | ||
}); | ||
}); |
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,36 @@ | ||
import React from 'react'; | ||
|
||
import { ReactComponent as NimbleLogoWhite } from 'assets/images/icons/nimble-logo-white.svg'; | ||
|
||
interface DashboardHeaderProps { | ||
dateTime: string; | ||
daysAgo: string; | ||
profileUrl: string; | ||
children: React.ReactNode; | ||
'data-test-id'?: string; | ||
} | ||
const DashboardHeader = ({ dateTime, daysAgo, profileUrl, children, ...rest }: DashboardHeaderProps): JSX.Element => { | ||
return ( | ||
<header className="flex flex-col min-h-screen" {...rest}> | ||
<div className="flex justify-between pt-8"> | ||
<NimbleLogoWhite /> | ||
<img className="w-[36px] h-[36px] rounded-full" src={profileUrl} alt="user avatar" /> | ||
</div> | ||
<div className="flex justify-between"> | ||
<div className="w-1/5"></div> | ||
<div className="flex flex-col text-white mt-10 flex-1"> | ||
<p className="text-x-small font-extrabold">{dateTime}</p> | ||
<p className="text-x-large font-extrabold mt-1">{daysAgo}</p> | ||
</div> | ||
<div className="w-1/5"></div> | ||
</div> | ||
<div className="flex justify-between mt-8 grow"> | ||
<div className="w-1/5"></div> | ||
<div className="flex-1">{children}</div> | ||
<div className="w-1/5"></div> | ||
</div> | ||
</header> | ||
); | ||
}; | ||
|
||
export default DashboardHeader; |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
|
||
import LoadingDialog from '.'; | ||
|
||
describe('LoadingDialog', () => { | ||
const dataTestId = 'loading-dialog'; | ||
|
||
it('renders a loading dialog component', () => { | ||
render(<LoadingDialog data-test-id={dataTestId} />); | ||
|
||
const loadingDialog = screen.getByTestId(dataTestId); | ||
|
||
expect(loadingDialog).toBeVisible(); | ||
}); | ||
}); |
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,22 @@ | ||
import React from 'react'; | ||
|
||
interface LoadingDialogProps { | ||
'data-test-id'?: string; | ||
} | ||
|
||
const LoadingDialog = (htmlAttributes: LoadingDialogProps): JSX.Element => { | ||
return ( | ||
<div className="w-full h-full bg-black bg-opacity-60 fixed top-0 right-0" {...htmlAttributes}> | ||
<div | ||
className="inline-block h-8 w-8 animate-spin rounded-full border-4 border-solid border-white absolute z-[1000] left-1/2 top-1/2 border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]" | ||
role="status" | ||
> | ||
<span className="absolute -m-px h-px w-px overflow-hidden whitespace-nowrap border-0 p-0 [clip:rect(0,0,0,0)]"> | ||
Loading... | ||
</span> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LoadingDialog; |
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.