Skip to content

Commit

Permalink
qodana improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
JessicaMulein committed Nov 15, 2024
1 parent e8cf5e0 commit 0ffc088
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 97 deletions.
21 changes: 18 additions & 3 deletions .github/workflows/qodana_code_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit
fetch-depth: 0 # a full history is required for pull request analysis
ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit
fetch-depth: 0 # a full history is required for pull request analysis

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20' # Specify the Node.js version you want to use
cache: 'yarn'

- name: Set up FontAwesome NPM registry
run: ./fontawesome-npmrc.sh
env:
FONTAWESOME_KEY: ${{ secrets.FONTAWESOME_KEY }}

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2024.2
with:
pr-mode: false
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN_1177090119 }}
QODANA_ENDPOINT: 'https://qodana.cloud'
QODANA_ENDPOINT: 'https://qodana.cloud'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@types/react-window": "^1.8.8",
"@types/uuid": "^10.0.0",
"babel-jest": "^29.7.0",
"eslint": "^9.8.0",
"eslint": "^9.14.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "2.31.0",
"eslint-plugin-jsx-a11y": "6.7.1",
Expand Down
6 changes: 2 additions & 4 deletions src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useRef, ReactElement, ReactNode, useEffect, useState } from 'react';
import { ThemeProvider } from '@mui/material/styles';
import { BrowserRouter as Router, useLocation, useNavigate, useRoutes } from 'react-router-dom';
import { BrowserRouter as Router, useLocation, useRoutes } from 'react-router-dom';
import AboutScreen from '@/components/screens/AboutScreen';
import HomeIcon from '@mui/icons-material/Home';
import BookIcon from '@mui/icons-material/Book';
Expand Down Expand Up @@ -89,7 +89,7 @@ function AppRoutes() {
});
}

const routes = useRoutes([
return useRoutes([
{
path: '/',
element: <TabView ref={tabViewRef} tabs={tabs} />,
Expand All @@ -100,8 +100,6 @@ function AppRoutes() {
})),
},
]);

return routes;
}

export function App() {
Expand Down
3 changes: 1 addition & 2 deletions src/components/screens/UtilsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export const UtilsScreen: FC = () => {
) {
return prevState;
}
const newGame = rebuildGameTimeHistory(prevState);
return newGame;
return rebuildGameTimeHistory(prevState);
});
};

Expand Down
117 changes: 117 additions & 0 deletions src/game/__tests__/dominion-lib-log-calculatePausedTime.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { calculatePausedTime } from '@/game/dominion-lib-log';
import { ILogEntry } from '@/game/interfaces/log-entry';
import { GameLogAction } from '@/game/enumerations/game-log-action';
import { createMockLog } from '@/__fixtures__/dominion-lib-fixtures';

describe('calculatePausedTime', () => {
it('should return 0 if logEntries is empty', () => {
const logEntries: ILogEntry[] = [];
const endTime = new Date();
expect(calculatePausedTime(logEntries, 0, endTime)).toBe(0);
});

it('should return 0 if no pause or save/load actions are present', () => {
const logEntries: ILogEntry[] = [
createMockLog({
timestamp: new Date('2023-01-01T00:00:00Z'),
action: GameLogAction.START_GAME,
turn: 1,
}),
createMockLog({
timestamp: new Date('2023-01-01T01:00:00Z'),
action: GameLogAction.NEXT_TURN,
turn: 2,
}),
];
const endTime = new Date('2023-01-01T02:00:00Z');
expect(calculatePausedTime(logEntries, 0, endTime)).toBe(0);
});

it('should calculate paused time correctly for pause/unpause actions', () => {
const logEntries: ILogEntry[] = [
createMockLog({
timestamp: new Date('2023-01-01T00:00:00Z'),
action: GameLogAction.START_GAME,
turn: 1,
}),
createMockLog({
timestamp: new Date('2023-01-01T01:00:00Z'),
action: GameLogAction.PAUSE,
turn: 1,
}),
createMockLog({
timestamp: new Date('2023-01-01T01:30:00Z'),
action: GameLogAction.UNPAUSE,
turn: 1,
}),
];
const endTime = new Date('2023-01-01T02:00:00Z');
expect(calculatePausedTime(logEntries, 0, endTime)).toBe(30 * 60 * 1000); // 30 minutes in milliseconds
});

it('should calculate paused time correctly for save/load actions', () => {
const logEntries: ILogEntry[] = [
createMockLog({
timestamp: new Date('2023-01-01T00:00:00Z'),
action: GameLogAction.START_GAME,
turn: 1,
}),
createMockLog({
timestamp: new Date('2023-01-01T01:00:00Z'),
action: GameLogAction.SAVE_GAME,
turn: 1,
}),
createMockLog({
timestamp: new Date('2023-01-01T01:30:00Z'),
action: GameLogAction.LOAD_GAME,
turn: 1,
}),
];
const endTime = new Date('2023-01-01T02:00:00Z');
expect(calculatePausedTime(logEntries, 0, endTime)).toBe(30 * 60 * 1000); // 30 minutes in milliseconds
});

it('should handle case where end time is during a pause', () => {
const logEntries: ILogEntry[] = [
createMockLog({
timestamp: new Date('2023-01-01T00:00:00Z'),
action: GameLogAction.START_GAME,
turn: 1,
}),
createMockLog({
timestamp: new Date('2023-01-01T01:00:00Z'),
action: GameLogAction.PAUSE,
turn: 1,
}),
];
const endTime = new Date('2023-01-01T01:30:00Z');
expect(calculatePausedTime(logEntries, 0, endTime)).toBe(30 * 60 * 1000); // 30 minutes in milliseconds
});

it('should handle case where end time is after a pause/unpause cycle', () => {
const logEntries: ILogEntry[] = [
createMockLog({
timestamp: new Date('2023-01-01T00:00:00Z'),
action: GameLogAction.START_GAME,
turn: 1,
}),
createMockLog({
timestamp: new Date('2023-01-01T01:00:00Z'),
action: GameLogAction.PAUSE,
turn: 1,
}),
createMockLog({
timestamp: new Date('2023-01-01T01:30:00Z'),
action: GameLogAction.UNPAUSE,
turn: 1,
}),
createMockLog({
timestamp: new Date('2023-01-01T02:00:00Z'),
action: GameLogAction.PAUSE,
turn: 1,
}),
];
const endTime = new Date('2023-01-01T02:30:00Z');
expect(calculatePausedTime(logEntries, 0, endTime)).toBe(60 * 60 * 1000); // 1 hour in milliseconds
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { removeTargetAndLinkedActions } from '@/game/dominion-lib-undo-helpers';
import { IGame } from '@/game/interfaces/game';
import { ILogEntry } from '@/game/interfaces/log-entry';
import { GameLogAction } from '@/game/enumerations/game-log-action';
import { createMockGame, createMockLog } from '@/__fixtures__/dominion-lib-fixtures';

Expand Down
Loading

0 comments on commit 0ffc088

Please sign in to comment.