Skip to content

Commit

Permalink
Updated the pwa theme color (#5)
Browse files Browse the repository at this point in the history
* fix: correct AuthProvider import path

* fix: test configuration and unused imports

* refactor: split auth context and provider into separate files

* Updated the pwa theme color

* chore: trigger CI

* chore: trigger ci
  • Loading branch information
aliakbar-deriv authored Jan 8, 2025
1 parent fd98876 commit 7643e67
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HashRouter as Router, Routes, Route } from "react-router-dom";
import { ThemeProvider, SnackbarProvider, Spinner } from "@deriv-com/quill-ui";
import { AuthProvider, useAuth } from "./hooks/useAuth.jsx";
import { useAuth } from "./hooks/useAuth.jsx";
import AuthProvider from "./providers/AuthProvider";
import Login from "./components/Login";
import Header from "./components/Header";
import Dashboard from "./components/Dashboard";
Expand Down
4 changes: 2 additions & 2 deletions src/components/__tests__/ProtectedRoute.test.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, it, expect, vi } from 'vitest'
import { describe, it, expect } from 'vitest'
import { render, screen } from '@testing-library/react'
import { MemoryRouter } from 'react-router-dom'
import ProtectedRoute from '../ProtectedRoute'
import { AuthContext } from '../../hooks/authContext.jsx'
import { AuthContext } from '../../contexts/auth'

const mockAuthContext = {
defaultAccount: null,
Expand Down
3 changes: 3 additions & 0 deletions src/contexts/auth.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createContext } from 'react';

export const AuthContext = createContext(null);
2 changes: 1 addition & 1 deletion src/hooks/useAuth.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useCallback, useEffect, useContext } from 'react';
import useWebSocket from "./useWebSocket";
import { AuthContext } from './authContext.jsx';
import { AuthContext } from '../contexts/auth';

export const useAuthState = () => {
const [isAuthorized, setIsAuthorized] = useState(false);
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/authContext.jsx → src/providers/AuthProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createContext } from 'react';
import PropTypes from 'prop-types';
import { useAuthState } from './useAuth';

export const AuthContext = createContext(null);
import { useAuthState } from '../hooks/useAuth';
import { AuthContext } from '../contexts/auth';

export const AuthProvider = ({ children }) => {
const auth = useAuthState();
Expand All @@ -12,3 +10,5 @@ export const AuthProvider = ({ children }) => {
AuthProvider.propTypes = {
children: PropTypes.node.isRequired,
};

export default AuthProvider;
18 changes: 17 additions & 1 deletion src/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import '@testing-library/jest-dom'
import { expect, afterEach } from 'vitest'
import { expect, afterEach, vi } from 'vitest'
import { cleanup } from '@testing-library/react'
import * as matchers from '@testing-library/jest-dom/matchers'
import React from 'react'

// Extend Vitest's expect method with methods from react-testing-library
expect.extend(matchers as any)

// Mock @deriv-com/quill-ui components
vi.mock('@deriv-com/quill-ui', () => {
const React = require('react')
const Skeleton = {
Square: ({ width, height }: { width: string, height: string }) =>
React.createElement('div', { style: { width, height } }, null)
}
return {
Spinner: () => null,
ThemeProvider: ({ children }: { children: React.ReactNode }) => React.createElement(React.Fragment, null, children),
SnackbarProvider: ({ children }: { children: React.ReactNode }) => React.createElement(React.Fragment, null, children),
Skeleton
}
})

// Cleanup after each test case (e.g. clearing jsdom)
afterEach(() => {
cleanup()
Expand Down
15 changes: 12 additions & 3 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ export default defineConfig(({ mode }) => {
environment: 'jsdom',
setupFiles: ['./src/test/setup.ts'],
deps: {
inline: ['@deriv-com/quill-ui']
optimizer: {
web: {
include: ['@deriv-com/quill-ui']
}
}
},
mockReset: true,
moduleNameMapper: {
'\\.(css|less|sass|scss)$': './src/test/mocks/styleMock.js'
'\\.(css|less|sass|scss)$': './src/test/mocks/styleMock.js',
'^@deriv-com/quill-ui/.*\\.css$': './src/test/mocks/styleMock.js'
},
transformMode: {
web: [/\.[jt]sx?$/],
ssr: [/\.css$/]
}
},
plugins: [
Expand All @@ -46,7 +55,7 @@ export default defineConfig(({ mode }) => {
name: 'Deriv Copy Trading',
short_name: 'Copy Trading',
description: 'Copy successful traders and automatically replicate their trading strategies in real-time.',
theme_color: '#FF444F',
theme_color: '#FFFFFF',
background_color: '#FFFFFF',
display: 'standalone',
start_url: '/copy-trading/',
Expand Down

0 comments on commit 7643e67

Please sign in to comment.