Skip to content

Commit

Permalink
Increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Sep 26, 2023
1 parent 1a55007 commit 6b7b0e6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
3 changes: 3 additions & 0 deletions superset-frontend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* under the License.
*/

// timezone for unit tests
process.env.TZ = 'America/New_York';

module.exports = {
testRegex:
'\\/superset-frontend\\/(spec|src|plugins|packages|tools)\\/.*(_spec|\\.test)\\.[jt]sx?$',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,43 @@ import finestTemporalGrain from './finestTemporalGrain';

test('finestTemporalGrain', () => {
const monthFormatter = finestTemporalGrain([
1041379200000, // 2003-01-01 00:00:00Z
1044057600000, // 2003-02-01 00:00:00Z
new Date('2003-01-01 00:00:00Z').getTime(),
new Date('2003-02-01 00:00:00Z').getTime(),
]);
expect(monthFormatter(1041379200000)).toBe('2003-01-01');
expect(monthFormatter(1044057600000)).toBe('2003-02-01');
expect(monthFormatter(new Date('2003-01-01 00:00:00Z').getTime())).toBe(
'2003-01-01',
);
expect(monthFormatter(new Date('2003-02-01 00:00:00Z').getTime())).toBe(
'2003-02-01',
);

const yearFormatter = finestTemporalGrain([
1041379200000, // 2003-01-01 00:00:00Z
1072915200000, // 2004-01-01 00:00:00Z
new Date('2003-01-01 00:00:00Z').getTime(),
new Date('2004-01-01 00:00:00Z').getTime(),
]);
expect(yearFormatter(1041379200000)).toBe('2003');
expect(yearFormatter(1072915200000)).toBe('2004');
expect(yearFormatter(new Date('2003-01-01 00:00:00Z').getTime())).toBe(
'2003',
);
expect(yearFormatter(new Date('2004-01-01 00:00:00Z').getTime())).toBe(
'2004',
);

const milliSecondFormatter = finestTemporalGrain([
new Date('2003-01-01 00:00:00Z').getTime(),
new Date('2003-04-05 06:07:08.123Z').getTime(),
]);
expect(milliSecondFormatter(new Date('2003-01-01 00:00:00Z').getTime())).toBe(
'2003-01-01 00:00:00.000',
);

const localTimeFormatter = finestTemporalGrain(
[
new Date('2003-01-01 00:00:00Z').getTime(),
new Date('2003-02-01 00:00:00Z').getTime(),
],
true,
);
expect(localTimeFormatter(new Date('2003-01-01 00:00:00Z').getTime())).toBe(
'2002-12-31 19:00',
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
getDataRecordFormatter({
timeFormatter: finestTemporalGrainFormatter(data.map(el => el.col)),
}),
[data, datatype],
[data],
);

const updateDataMask = useCallback(
Expand Down

0 comments on commit 6b7b0e6

Please sign in to comment.