Skip to content

Commit

Permalink
fix: relative month test
Browse files Browse the repository at this point in the history
  • Loading branch information
tracy-french committed Jan 3, 2024
1 parent 879f429 commit 5c6e262
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
3 changes: 3 additions & 0 deletions packages/react-components/global-jest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = async () => {
process.env.TZ = 'UTC';
};
1 change: 1 addition & 0 deletions packages/react-components/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const config = {
'^.+\\.svg$': '<rootDir>/svgTransform.js',
},
setupFilesAfterEnv: [...reactConfig.setupFilesAfterEnv, '<rootDir>/jest-setup.js'],
globalSetup: './global-jest-setup.js',
coveragePathIgnorePatterns: [
'<rootDir>/src/components/knowledge-graph/KnowledgeGraphPanel.tsx',
'<rootDir>/src/components/chart/trendCursor/mouseEvents/useTrendCursorsEvents.ts',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,13 @@ describe('viewportToDateRange', () => {
});

describe('getViewportStartOnBackwardRelative', () => {
jest.useFakeTimers().setSystemTime(new Date(2023, 11, 24).getTime());
beforeEach(() => {
jest.useFakeTimers().setSystemTime(new Date(2023, 11, 24).getTime());
});

afterAll(() => {
jest.useRealTimers();
});

it('can get the new start date when going back from a relative duration', () => {
let currentDate = new Date();
Expand Down Expand Up @@ -203,7 +209,13 @@ describe('getViewportStartOnBackwardRelative', () => {
});

describe('getViewportStartOnBackwardRelative on first backward click', () => {
jest.useFakeTimers().setSystemTime(new Date(2023, 11, 24).getTime());
beforeEach(() => {
jest.useFakeTimers().setSystemTime(new Date(2023, 11, 24).getTime());
});

afterAll(() => {
jest.useRealTimers();
});

it('can get the new start date from current range when going back from a relative duration', () => {
let currentDate = new Date();
Expand Down Expand Up @@ -273,11 +285,6 @@ describe('getViewportStartOnBackwardRelative on first backward click', () => {
},
true
);

const previousMonthDays = new Date(newDate.getFullYear(), newDate.getMonth() - 1, 0).getDate(); //calculating no of days for previous month of current range
const timeGap = previousMonthDays === 30 ? 5184000000 : 5270400000;
expect(currentDate.getTime() - newDate.getTime()).toEqual(timeGap);

jest.useRealTimers();
expect(currentDate.getTime() - newDate.getTime()).toEqual(5270400000);
});
});
27 changes: 8 additions & 19 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"dependsOn": [
"^build"
],
"outputs": [
"dist/**"
],
"dependsOn": ["^build"],
"outputs": ["dist/**"],
"outputMode": "new-only"
},
"pack": {
Expand All @@ -23,24 +19,16 @@
"outputMode": "new-only"
},
"test": {
"dependsOn": [
"build"
],
"dependsOn": ["build"],
"outputMode": "new-only"
},
"test:ui": {
"dependsOn": [
"build"
],
"env": [
"CI"
],
"dependsOn": ["build"],
"env": ["CI"],
"outputMode": "new-only"
},
"start": {
"dependsOn": [
"^build"
],
"dependsOn": ["^build"],
"env": [
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
Expand All @@ -51,7 +39,8 @@
"PROPERTY_ID_1",
"PROPERTY_ID_2",
"PROPERTY_ID_3",
"REGION"
"REGION",
"TZ"
]
},
"version": {
Expand Down

0 comments on commit 5c6e262

Please sign in to comment.