Skip to content

Commit

Permalink
Merge pull request #1064 from araujoarthur0/continue-electron-mocha-m…
Browse files Browse the repository at this point in the history
…ain-migration
  • Loading branch information
tupaschoal authored Mar 10, 2024
2 parents 3a4e99f + 85fe6bf commit a85f0d5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 45 deletions.
13 changes: 7 additions & 6 deletions __tests__/__main__/date-aux.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable no-undef */
'use strict';

const assert = require('assert');
import assert from 'assert';

import { getDateStr, getCurrentDateTimeStr, getMonthLength } from '../../js/date-aux.js';

describe('Date Functions', () =>
Expand All @@ -12,12 +13,12 @@ describe('Date Functions', () =>

describe('getDateStr(Date())', () =>
{
test('Given a JS Date() object, should return YYYY-MM-DD', () =>
it('Given a JS Date() object, should return YYYY-MM-DD', () =>
{
assert.strictEqual(getDateStr(testDate), expectedDate);
});

test('Given an insane object, should return an error', () =>
it('Given an insane object, should return an error', () =>
{
assert.notStrictEqual(getDateStr(badDate), expectedDate);
});
Expand All @@ -26,7 +27,7 @@ describe('Date Functions', () =>
describe('getMonthLength(Year, Month)', () =>
{
const testYear = 2024;
test('Given for the Year(2024) and Months, should return number of days in month', () =>
it('Given for the Year(2024) and Months, should return number of days in month', () =>
{
assert.strictEqual(getMonthLength(testYear, 0), 31);
assert.strictEqual(getMonthLength(testYear, 1), 29);
Expand All @@ -48,12 +49,12 @@ describe('Date Functions', () =>
const looseRegexCurrentDateTime = /(\d{4}_\d{2}_\d{2}_\d{2}_\d{2}_\d{2})/g;
const regexCurrentDateTime = /(\d{4}_(0[1-9]|1[0-2])_(0[1-9]|[12]\d|3[01])_(0\d|1\d|2[0-3])_([0-5]\d)_([0-5]\d))/g;

test('Should return Current Date Time string in YYYY_MM_DD_HH_MM_SS format with no spaces or unexpected characters making sure it accepts digits', () =>
it('Should return Current Date Time string in YYYY_MM_DD_HH_MM_SS format with no spaces or unexpected characters making sure it accepts digits', () =>
{
assert.strictEqual(looseRegexCurrentDateTime.test(getCurrentDateTimeStr()), true);
});

test('Should return Current Date Time string in YYYY_MM_DD_HH_MM_SS format with no spaces or unexpected characters', () =>
it('Should return Current Date Time string in YYYY_MM_DD_HH_MM_SS format with no spaces or unexpected characters', () =>
{
assert.strictEqual(regexCurrentDateTime.test(getCurrentDateTimeStr()), true);
});
Expand Down
38 changes: 19 additions & 19 deletions __tests__/__main__/import-export.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/* eslint-disable no-undef */
'use strict';

const assert = require('assert');
const {
import assert from 'assert';
import Store from 'electron-store';
import fs from 'fs';
import path from 'path';

import {
exportDatabaseToFile,
importDatabaseFromFile,
migrateFixedDbToFlexible,
validEntry
} = require('../../js/import-export');

import fs from 'fs';
import Store from 'electron-store';
import path from 'path';
validEntry,
} from '../../js/import-export.js';

describe('Import export', function()
{
Expand All @@ -27,14 +27,14 @@ describe('Import export', function()
const badFlexibleEntry = {'type': 'flexible', 'date': '2020-06-03', 'values': ['not-an-hour']};
const badFlexibleEntry2 = {'type': 'flexible', 'date': '2020-06-03', 'values': 'not-an-array'};
const badWaivedEntry = {'type': 'regular', 'date': '2020-06-03', 'data': 'day-begin', 'hours': 'not-an-hour'};
test('should be valid', () =>
it('should be valid', () =>
{
assert.strictEqual(validEntry(goodRegularEntry), true);
assert.strictEqual(validEntry(goodWaivedEntry), true);
assert.strictEqual(validEntry(goodFlexibleEntry), true);
});

test('should not be valid', () =>
it('should not be valid', () =>
{
assert.strictEqual(validEntry(badRegularEntry), false);
assert.strictEqual(validEntry(badWaivedEntry), false);
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('Import export', function()

describe('exportDatabaseToFile', function()
{
test('Check that export works', () =>
it('Check that export works', () =>
{
assert.strictEqual(exportDatabaseToFile(path.join(folder, 'exported_file.ttldb')), true);
assert.strictEqual(exportDatabaseToFile('/not/a/valid/path'), false);
Expand All @@ -100,7 +100,7 @@ describe('Import export', function()

describe('importDatabaseFromFile', function()
{
test('Check that import works', () =>
it('Check that import works', () =>
{
assert.strictEqual(importDatabaseFromFile([path.join(folder, 'exported_file.ttldb')])['result'], true);
assert.strictEqual(importDatabaseFromFile(['/not/a/valid/path'])['result'], false);
Expand All @@ -117,15 +117,15 @@ describe('Import export', function()

describe('migrateFixedDbToFlexible', function()
{
test('Check that migration works', () =>
it('Check that migration works', () =>
{
assert.strictEqual(flexibleStore.size, 2);
flexibleStore.clear();
assert.strictEqual(flexibleStore.size, 0);
migrateFixedDbToFlexible();
assert.strictEqual(flexibleStore.size, 2);
expect(flexibleStore.get('2020-3-1')).toStrictEqual(migratedFlexibleEntries['2020-3-1']);
expect(flexibleStore.get('2020-3-2')).toStrictEqual(migratedFlexibleEntries['2020-3-2']);
assert.deepStrictEqual(flexibleStore.get('2020-3-1'), migratedFlexibleEntries['2020-3-1']);
assert.deepStrictEqual(flexibleStore.get('2020-3-2'), migratedFlexibleEntries['2020-3-2']);
});
});

Expand All @@ -146,18 +146,18 @@ describe('Import export', function()

describe('importDatabaseFromFile (mixedContent)', function()
{
test('Check that import works', () =>
it('Check that import works', () =>
{
flexibleStore.clear();
assert.strictEqual(flexibleStore.size, 0);
assert.strictEqual(importDatabaseFromFile([mixedEntriesFile])['result'], true);
assert.strictEqual(flexibleStore.size, 2);
expect(flexibleStore.get('2020-2-1')).toStrictEqual(expectedMixedEntries['2020-2-1']);
expect(flexibleStore.get('2020-5-3')).toStrictEqual(expectedMixedEntries['2020-5-3']);
assert.deepStrictEqual(flexibleStore.get('2020-2-1'), expectedMixedEntries['2020-2-1']);
assert.deepStrictEqual(flexibleStore.get('2020-5-3'), expectedMixedEntries['2020-5-3']);
});
});

afterAll(() =>
after(() =>
{
fs.rmSync(folder, {recursive: true});
});
Expand Down
37 changes: 19 additions & 18 deletions __tests__/__main__/validate-json.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable no-undef */
'use strict';

const assert = require('assert');
import assert from 'assert';

import { validateJSON } from '../../js/validate-json.js';

describe('Validate json', function()
Expand All @@ -16,12 +17,12 @@ describe('Validate json', function()
const invalidTypeValue = [{ 'type': 'not valid type', 'date': '2020-06-03', 'values': ['08:00', '12:00', '13:00', '14:00'] }];
const invalidTypeType = [{ 'type': ['not valid type'], 'date': '2020-06-03', 'values': ['08:00', '12:00', '13:00', '14:00'] }];

test('should be valid JSON', () =>
it('should be valid JSON', () =>
{
assert.strictEqual(validateJSON(validWaivedType), true);
assert.strictEqual(validateJSON(validFlexibleType), true);
});
test('should not be valid JSON', () =>
it('should not be valid JSON', () =>
{
assert.strictEqual(validateJSON(invalidTypeValue), false);
assert.strictEqual(validateJSON(invalidTypeType), false);
Expand All @@ -34,7 +35,7 @@ describe('Validate json', function()
const validFlexibleDate2 = [{ 'type': 'flexible', 'date': '2020-6-3', 'values': ['08:00', '12:00', '13:00', '14:00'] }];
const validWaivedDate1 = [{ 'type': 'waived', 'date': '2020-06-03', 'data': 'waived', 'hours': '08:00' }];
const validWaivedDate2 = [{ 'type': 'waived', 'date': '2020-6-3', 'data': 'waived', 'hours': '08:00' }];
test('should be valid JSON', () =>
it('should be valid JSON', () =>
{
assert.strictEqual(validateJSON(validFlexibleDate1), true);
assert.strictEqual(validateJSON(validFlexibleDate2), true);
Expand All @@ -51,12 +52,12 @@ describe('Validate json', function()
const invalidDateType = [{ 'type': 'flexible', 'date': ['2020-06-13'], 'values': ['08:00', '12:00', '13:00', '14:00'] }];
const invalidDateValue = [{ 'type': 'flexible', 'date': '2020-26-03', 'values': ['08:00', '12:00', '13:00', '14:00'] }];
const invalidDayInMonth = [{ 'type': 'flexible', 'date': '2020-04-31', 'values': ['08:00', '12:00', '13:00', '14:00'] }];
test('should be valid JSON', () =>
it('should be valid JSON', () =>
{
assert.strictEqual(validateJSON(validWaivedDate), true);
assert.strictEqual(validateJSON(validFlexibleDate), true);
});
test('should not be valid JSON', () =>
it('should not be valid JSON', () =>
{
assert.strictEqual(validateJSON(invalidDateFormat), false);
assert.strictEqual(validateJSON(invalidDateType), false);
Expand All @@ -69,11 +70,11 @@ describe('Validate json', function()
{
const validData = [{ 'type': 'waived', 'date': '2020-06-03', 'data': 'waived', 'hours': '08:00' }];
const invalidDataType = [{ 'type': 'waived', 'date': '2020-06-03', 'data': ['waived'], 'hours': '08:00' }];
test('should be valid JSON', () =>
it('should be valid JSON', () =>
{
assert.strictEqual(validateJSON(validData), true);
});
test('should not be valid JSON', () =>
it('should not be valid JSON', () =>
{
assert.strictEqual(validateJSON(invalidDataType), false);
});
Expand All @@ -87,12 +88,12 @@ describe('Validate json', function()
const invalidHoursType = [{ 'type': 'waived', 'date': '2020-06-03', 'data': 'waived', 'hours': 8 }];
const invalidHoursValue = [{ 'type': 'waived', 'date': '2020-06-03', 'data': 'waived', 'hours': '30:00' }];
const invalidHoursValueNegative = [{ 'type': 'waived', 'date': '2020-06-03', 'data': 'waived', 'hours': '-01:00' }];
test('should be valid JSON', () =>
it('should be valid JSON', () =>
{
assert.strictEqual(validateJSON(validHours), true);
assert.strictEqual(validateJSON(validHours2), true);
});
test('should not be valid JSON', () =>
it('should not be valid JSON', () =>
{
assert.strictEqual(validateJSON(invalidHoursFormat), false);
assert.strictEqual(validateJSON(invalidHoursType), false);
Expand All @@ -111,11 +112,11 @@ describe('Validate json', function()
const invalidValuesType = [{ 'type': 'flexible', 'date': ['2020-06-03'], 'values': '08:00' }];
const invalidValuesValue = [{ 'type': 'flexible', 'date': '2020-26-03', 'values': ['80:00', '12:00', '13:00', '14:00'] }];
const invalidPointsInTime = [{ 'type': 'flexible', 'date': '2020-02-01', 'values': ['08:00', '07:00', '13:00', '14:00'] }];
test('should be valid JSON', () =>
it('should be valid JSON', () =>
{
assert.strictEqual(validateJSON(validValues), true);
});
test('should not be valid JSON', () =>
it('should not be valid JSON', () =>
{
assert.strictEqual(validateJSON(invalidValuesFormat1), false);
assert.strictEqual(validateJSON(invalidValuesFormat2), false);
Expand All @@ -132,7 +133,7 @@ describe('Validate json', function()
const invalidDay = [{ 'type': 'flexible', 'date': '2020-12-00', 'values': ['08:00', '12:00', '13:00', '14:00'] }];
const invalidDay2 = [{ 'type': 'flexible', 'date': '2020-12-32', 'values': ['08:00', '12:00', '13:00', '14:00'] }];

test('should be valid JSON', () =>
it('should be valid JSON', () =>
{
for (let i = 1; i <= 9; i++)
{
Expand All @@ -145,7 +146,7 @@ describe('Validate json', function()
assert.strictEqual(validateJSON(restDays), true);
}
});
test('should not be valid JSON', () =>
it('should not be valid JSON', () =>
{
assert.strictEqual(validateJSON(invalidDay), false);
assert.strictEqual(validateJSON(invalidDay2), false);
Expand All @@ -157,7 +158,7 @@ describe('Validate json', function()
const invalidMonth = [{ 'type': 'flexible', 'date': '2020-00-03', 'values': ['08:00', '12:00', '13:00', '14:00'] }];
const invalidMonth2 = [{ 'type': 'flexible', 'date': '2020-13-03', 'values': ['08:00', '12:00', '13:00', '14:00'] }];

test('should be valid JSON', () =>
it('should be valid JSON', () =>
{
for (let i = 1; i <= 9; i++)
{
Expand All @@ -170,7 +171,7 @@ describe('Validate json', function()
assert.strictEqual(validateJSON(restMonths), true);
}
});
test('should not be valid JSON', () =>
it('should not be valid JSON', () =>
{
assert.strictEqual(validateJSON(invalidMonth), false);
assert.strictEqual(validateJSON(invalidMonth2), false);
Expand All @@ -182,12 +183,12 @@ describe('Validate json', function()
const validLeapYear = [{ 'type': 'flexible', 'date': '2020-02-29', 'values': ['08:00', '12:00', '13:00', '14:00'] }];
const invalidLeapYear = [{ 'type': 'flexible', 'date': '2021-02-29', 'values': ['08:00', '12:00', '13:00', '14:00'] }];

test('should be valid JSON', () =>
it('should be valid JSON', () =>
{
assert.strictEqual(validateJSON(validLeapYear), true);

});
test('should not be valid JSON', () =>
it('should not be valid JSON', () =>
{
assert.strictEqual(validateJSON(invalidLeapYear), false);
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/electron-mocha-main.config.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const data = require('./mocha-base.config.cjs');

data.spec = ['__tests__/__main__/time-math.js'];
data.spec = ['__tests__/__main__/{date-aux,import-export,time-math,validate-json}.js'];

module.exports = data;
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
displayName: ' MAIN',
runner: '@jest-runner/electron/main',
testEnvironment: 'node',
testMatch: ['**/__tests__/**main**/*.js', '!**/time-math.js']
testMatch: ['**/__tests__/**main**/*.js', '!**/{date-aux,import-export,time-math,validate-json}.js']
},
{
displayName: 'RENDERER',
Expand Down

0 comments on commit a85f0d5

Please sign in to comment.