Skip to content

Commit

Permalink
fixed jest config, tests, and update gitigore
Browse files Browse the repository at this point in the history
  • Loading branch information
Carla-Moz committed Jan 16, 2025
1 parent 536edf7 commit 509c236
Show file tree
Hide file tree
Showing 18 changed files with 345 additions and 185 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ typings/

# package.lock.json
package-lock.json
yarn.lock
build/

# IDE files
Expand Down
81 changes: 0 additions & 81 deletions _tests_/chartJs.test.js

This file was deleted.

7 changes: 2 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
process.env.REACT_APP_NODE_ENV =
process.env.REACT_APP_NODE_ENVNODE_ENV || 'test';
process.env.REACT_APP_NODE_ENV = process.env.REACT_APP_NODE_ENV || 'test';
process.env.REACT_APP_DASHBOARD = process.env.REACT_APP_DASHBOARD || 'awfy';

module.exports = {
// The root of your source code, typically `/src`
roots: ['<rootDir>/src'],
collectCoverageFrom: ['src/**/*.{js,jsx}'],
coveragePathIgnorePatterns: ['_tests_', 'index'],
// Paths to modules that run some code to configure or set up the testing environment before each test
testMatch: ['<rootDir>/_tests_/**/*.{js,jsx}'],
coveragePathIgnorePatterns: ['__tests__', 'index'],
// Test environment that simulates a browser (using jsdom)
testEnvironment: 'jsdom',

Expand Down
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
"yarn lint"
]
},
"jest": {
"coverageDirectory": "./coverage/",
"collectCoverage": true
},
"dependencies": {
"@material-ui/core": "^4",
"@material-ui/icons": "^4",
Expand Down Expand Up @@ -55,7 +51,8 @@
"@pollyjs/adapter-node-http": "^5.0.0",
"@pollyjs/core": "^5.0.0",
"@pollyjs/persister-fs": "^5.0.0",
"@testing-library/react": "^16.1.0",
"@testing-library/dom": "^10.0.0",
"@testing-library/react": "^10.0.6",
"babel-loader": "^9.2.1",
"babel-preset-jest": "^29.6.3",
"codecov": "3.7.2",
Expand Down Expand Up @@ -87,4 +84,4 @@
"pre-push": "yarn test"
}
}
}
}
102 changes: 102 additions & 0 deletions src/_tests_/chartJs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import {
addPunctuationToNumbers,
generateChartJsOptions,
} from '../utils/chartJs';

it('Options with yLabel', () => {
const yLabel = 'foo';
const options = generateChartJsOptions('', yLabel);
expect(options).toStrictEqual({
maintainAspectRatio: false,
scales: {
xAxes: [
{
bounds: 'ticks',
ticks: {
max: undefined,
min: undefined,
},
time: { displayFormats: { hour: 'MMM D' } },
type: 'time',
},
],
yAxes: [
{
scaleLabel: { display: true, labelString: yLabel },
ticks: {
callback: options.scales.yAxes[0].ticks.callback,
beginAtZero: false,
reverse: false,
},
},
],
},
});
});

it('Option with higher is better', () => {
const options = generateChartJsOptions({ lower_is_better: false });
expect(options).toStrictEqual({
maintainAspectRatio: false,
scales: {
xAxes: [
{
bounds: 'ticks',
ticks: {
max: undefined,
min: undefined,
},
time: { displayFormats: { hour: 'MMM D' } },
type: 'time',
},
],
yAxes: [
{
scaleLabel: { display: true, labelString: 'Score' },
ticks: {
callback: options.scales.yAxes[0].ticks.callback,
beginAtZero: false,
reverse: true,
},
},
],
},
});
});

it('Option with lower is better', () => {
const options = generateChartJsOptions({ lower_is_better: true });
expect(options).toStrictEqual({
maintainAspectRatio: false,
scales: {
xAxes: [
{
bounds: 'ticks',
ticks: {
max: undefined,
min: undefined,
},
time: { displayFormats: { hour: 'MMM D' } },
type: 'time',
},
],
yAxes: [
{
scaleLabel: { display: true, labelString: 'Execution time (ms)' },
ticks: {
callback: options.scales.yAxes[0].ticks.callback,
beginAtZero: false,
reverse: false,
},
},
],
},
});
});

it('Tests that numbers are added commas and numbers', () => {
expect(addPunctuationToNumbers('1000000')).toStrictEqual('1,000,000');
expect(addPunctuationToNumbers('1000')).toStrictEqual('1,000');
expect(addPunctuationToNumbers('5.20')).toStrictEqual('5.20');
expect(addPunctuationToNumbers('5')).toStrictEqual('5');
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { render } from '@testing-library/react';
import 'raf/polyfill';
import Pickers from '../../src/components/Pickers';
import { CONFIG } from '../../src/config';
import Pickers from '../../components/Pickers';
import { CONFIG } from '../../config';

it('renders correctly', () => {
const { asFragment } = render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports[`renders correctly 1`] = `
>
<div
aria-haspopup="listbox"
aria-labelledby=" mui-component-select-platform"
aria-labelledby="mui-component-select-platform"
class="MuiSelect-root MuiSelect-select MuiSelect-selectMenu MuiInputBase-input MuiInput-input"
id="mui-component-select-platform"
role="button"
Expand All @@ -32,15 +32,16 @@ exports[`renders correctly 1`] = `
Windows 10 64bit
</div>
<input
aria-hidden="true"
class="MuiSelect-nativeInput"
name="platform"
type="hidden"
tabindex="-1"
value="win10"
/>
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSelect-icon"
focusable="false"
role="presentation"
viewBox="0 0 24 24"
>
<path
Expand Down Expand Up @@ -68,7 +69,7 @@ exports[`renders correctly 1`] = `
>
<div
aria-haspopup="listbox"
aria-labelledby=" mui-component-select-category"
aria-labelledby="mui-component-select-category"
class="MuiSelect-root MuiSelect-select MuiSelect-selectMenu MuiInputBase-input MuiInput-input"
id="mui-component-select-category"
role="button"
Expand All @@ -77,15 +78,16 @@ exports[`renders correctly 1`] = `
Benchmarks
</div>
<input
aria-hidden="true"
class="MuiSelect-nativeInput"
name="category"
type="hidden"
tabindex="-1"
value="benchmarks"
/>
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSelect-icon"
focusable="false"
role="presentation"
viewBox="0 0 24 24"
>
<path
Expand Down Expand Up @@ -113,7 +115,7 @@ exports[`renders correctly 1`] = `
>
<div
aria-haspopup="listbox"
aria-labelledby=" mui-component-select-results"
aria-labelledby="mui-component-select-results"
class="MuiSelect-root MuiSelect-select MuiSelect-selectMenu MuiInputBase-input MuiInput-input"
id="mui-component-select-results"
role="button"
Expand All @@ -122,15 +124,16 @@ exports[`renders correctly 1`] = `
Overview
</div>
<input
aria-hidden="true"
class="MuiSelect-nativeInput"
name="results"
type="hidden"
tabindex="-1"
value="overview"
/>
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSelect-icon"
focusable="false"
role="presentation"
viewBox="0 0 24 24"
>
<path
Expand Down Expand Up @@ -158,7 +161,7 @@ exports[`renders correctly 1`] = `
>
<div
aria-haspopup="listbox"
aria-labelledby=" mui-component-select-numDays"
aria-labelledby="mui-component-select-numDays"
class="MuiSelect-root MuiSelect-select MuiSelect-selectMenu MuiInputBase-input MuiInput-input"
id="mui-component-select-numDays"
role="button"
Expand All @@ -167,15 +170,16 @@ exports[`renders correctly 1`] = `
Last 60 days
</div>
<input
aria-hidden="true"
class="MuiSelect-nativeInput"
name="numDays"
type="hidden"
tabindex="-1"
value="60"
/>
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSelect-icon"
focusable="false"
role="presentation"
viewBox="0 0 24 24"
>
<path
Expand All @@ -187,7 +191,7 @@ exports[`renders correctly 1`] = `
</form>
<div>
<div
class="MuiFormControl-root MultipleSelectPicker-formControl-85"
class="MuiFormControl-root MultipleSelectPicker-formControl-3"
>
<label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiFormLabel-filled"
Expand All @@ -210,15 +214,16 @@ exports[`renders correctly 1`] = `
Firefox
</div>
<input
aria-hidden="true"
class="MuiSelect-nativeInput"
name="series"
type="hidden"
tabindex="-1"
value="Firefox"
/>
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSelect-icon"
focusable="false"
role="presentation"
viewBox="0 0 24 24"
>
<path
Expand Down
Loading

0 comments on commit 509c236

Please sign in to comment.