mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 21:22:14 +08:00
149b389508
* Switch to using Typescript instead of Babel * Switch all es6 / jsx file extensions to ts / tsx * Convert Utils to a TS module from module.exports style module * Move everything from module.exports to typescript exports * Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :( * Load up on those @types * Synthesize TS types from PropTypes for standard components * Add types to Model classes and move constructor constants to instance vars * 9800 => 7700 TS errors * 7700 => 5600 TS errors * 5600 => 5330 TS errors * 5330 => 4866 TS errors * 4866 => 4426 TS errors * 4426 => 2411 TS errors * 2411 > 1598 TS errors * 1598 > 769 TS errors * 769 > 129 TS errors * 129 > 22 TS errors * Fix runtime errors * More runtime error fixes * Remove support for custom .es6 file extension * Remove a few odd remaining references to Nylas * Don’t ship Typescript support in the compiled app for now * Fix issues in compiled app - module resolution in TS is case sensitive? * README updates * Fix a few more TS errors * Make “No Signature” option clickable + selectable * Remove flicker when saving file and reloading keymaps * Fix mail rule item height in preferences * Fix missing spacing in thread sharing popover * Fix scrollbar ticks being nested incorrectly * Add Japanese as a manually reviewed language * Prevent the thread list from “sticking” * Re-use Sheet when switching root tabs, prevent sidebar from resetting * Ensure specs run * Update package configuration to avoid shpping types * Turn eslint back on - we will opt-in to the TS rules one by one
170 lines
5.7 KiB
TypeScript
170 lines
5.7 KiB
TypeScript
import moment from 'moment';
|
|
import { DateUtils } from 'mailspring-exports';
|
|
|
|
describe('DateUtils', function dateUtils() {
|
|
describe('nextWeek', () => {
|
|
it('returns tomorrow if now is sunday', () => {
|
|
const sunday = moment('03-06-2016', 'MM-DD-YYYY');
|
|
const nextWeek = DateUtils.nextWeek(sunday);
|
|
expect(nextWeek.format('MM-DD-YYYY')).toEqual('03-07-2016');
|
|
});
|
|
|
|
it('returns next monday if now is monday', () => {
|
|
const monday = moment('03-07-2016', 'MM-DD-YYYY');
|
|
const nextWeek = DateUtils.nextWeek(monday);
|
|
expect(nextWeek.format('MM-DD-YYYY')).toEqual('03-14-2016');
|
|
});
|
|
|
|
it('returns next monday', () => {
|
|
const saturday = moment('03-05-2016', 'MM-DD-YYYY');
|
|
const nextWeek = DateUtils.nextWeek(saturday);
|
|
expect(nextWeek.format('MM-DD-YYYY')).toEqual('03-07-2016');
|
|
});
|
|
});
|
|
|
|
describe('thisWeekend', () => {
|
|
it('returns tomorrow if now is friday', () => {
|
|
const friday = moment('03-04-2016', 'MM-DD-YYYY');
|
|
const thisWeekend = DateUtils.thisWeekend(friday);
|
|
expect(thisWeekend.format('MM-DD-YYYY')).toEqual('03-05-2016');
|
|
});
|
|
|
|
it('returns next saturday if now is saturday', () => {
|
|
const saturday = moment('03-05-2016', 'MM-DD-YYYY');
|
|
const thisWeekend = DateUtils.thisWeekend(saturday);
|
|
expect(thisWeekend.format('MM-DD-YYYY')).toEqual('03-12-2016');
|
|
});
|
|
|
|
it('returns next saturday', () => {
|
|
const sunday = moment('03-06-2016', 'MM-DD-YYYY');
|
|
const thisWeekend = DateUtils.thisWeekend(sunday);
|
|
expect(thisWeekend.format('MM-DD-YYYY')).toEqual('03-12-2016');
|
|
});
|
|
});
|
|
|
|
describe('getTimeFormat: 12-hour clock', () => {
|
|
beforeEach(() => {
|
|
spyOn(AppEnv.config, 'get').andReturn(false);
|
|
});
|
|
|
|
it('displays the time format for a 12-hour clock', () => {
|
|
const time = DateUtils.getTimeFormat(null);
|
|
expect(time).toBe('h:mm a');
|
|
});
|
|
|
|
it('displays the time format for a 12-hour clock with timezone', () => {
|
|
const opts = { timeZone: true };
|
|
const time = DateUtils.getTimeFormat(opts);
|
|
expect(time).toBe('h:mm a z');
|
|
});
|
|
|
|
it('displays the time format for a 12-hour clock with seconds', () => {
|
|
const opts = { seconds: true };
|
|
const time = DateUtils.getTimeFormat(opts);
|
|
expect(time).toBe('h:mm:ss a');
|
|
});
|
|
|
|
it('displays the time format for a 12-hour clock with seconds and timezone', () => {
|
|
const opts = { seconds: true, timeZone: true };
|
|
const time = DateUtils.getTimeFormat(opts);
|
|
expect(time).toBe('h:mm:ss a z');
|
|
});
|
|
|
|
it('displays the time format for a 12-hour clock in uppercase', () => {
|
|
const opts = { upperCase: true };
|
|
const time = DateUtils.getTimeFormat(opts);
|
|
expect(time).toBe('h:mm A');
|
|
});
|
|
|
|
it('displays the time format for a 12-hour clock in uppercase with seconds', () => {
|
|
const opts = { upperCase: true, seconds: true };
|
|
const time = DateUtils.getTimeFormat(opts);
|
|
expect(time).toBe('h:mm:ss A');
|
|
});
|
|
|
|
it('displays the time format for a 12-hour clock in uppercase with timezone', () => {
|
|
const opts = { upperCase: true, timeZone: true };
|
|
const time = DateUtils.getTimeFormat(opts);
|
|
expect(time).toBe('h:mm A z');
|
|
});
|
|
|
|
it('displays the time format for a 12-hour clock in uppercase with seconds and timezone', () => {
|
|
const opts = { upperCase: true, seconds: true, timeZone: true };
|
|
const time = DateUtils.getTimeFormat(opts);
|
|
expect(time).toBe('h:mm:ss A z');
|
|
});
|
|
});
|
|
|
|
describe('getTimeFormat: 24-hour clock', () => {
|
|
beforeEach(() => {
|
|
spyOn(AppEnv.config, 'get').andReturn(true);
|
|
});
|
|
|
|
it('displays the time format for a 24-hour clock', () => {
|
|
const time = DateUtils.getTimeFormat(null);
|
|
expect(time).toBe('HH:mm');
|
|
});
|
|
|
|
it('displays the time format for a 24-hour clock with timezone', () => {
|
|
const opts = { timeZone: true };
|
|
const time = DateUtils.getTimeFormat(opts);
|
|
expect(time).toBe('HH:mm z');
|
|
});
|
|
|
|
it('displays the time format for a 24-hour clock with seconds', () => {
|
|
const opts = { seconds: true };
|
|
const time = DateUtils.getTimeFormat(opts);
|
|
expect(time).toBe('HH:mm:ss');
|
|
});
|
|
|
|
it('displays the time format for a 24-hour clock with seconds and timezone', () => {
|
|
const opts = { seconds: true, timeZone: true };
|
|
const time = DateUtils.getTimeFormat(opts);
|
|
expect(time).toBe('HH:mm:ss z');
|
|
});
|
|
});
|
|
|
|
describe('mediumTimeString: 12-hour time', () => {
|
|
beforeEach(() => {
|
|
spyOn(AppEnv.config, 'get').andReturn(false);
|
|
});
|
|
|
|
it('displays a date and time', () => {
|
|
const datestring = DateUtils.mediumTimeString('1982-10-24 22:45');
|
|
expect(datestring).toBe('October 24, 1982, 10:45 PM');
|
|
});
|
|
});
|
|
|
|
describe('mediumTimeString: 24-hour time', () => {
|
|
beforeEach(() => {
|
|
spyOn(AppEnv.config, 'get').andReturn(true);
|
|
});
|
|
|
|
it('displays a date and time', () => {
|
|
const datestring = DateUtils.mediumTimeString('1982-10-24 22:45');
|
|
expect(datestring).toBe('October 24, 1982, 22:45');
|
|
});
|
|
});
|
|
|
|
describe('fullTimeString: 12-hour time', () => {
|
|
beforeEach(() => {
|
|
spyOn(AppEnv.config, 'get').andReturn(false);
|
|
});
|
|
|
|
it('displays a date and time', () => {
|
|
const datestring = DateUtils.fullTimeString('1982-10-24 22:45');
|
|
expect(datestring.startsWith(`Sunday, October 24th 1982, 10:45:00 PM`)).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('fullTimeString: 24-hour time', () => {
|
|
beforeEach(() => {
|
|
spyOn(AppEnv.config, 'get').andReturn(true);
|
|
});
|
|
|
|
it('displays a date and time', () => {
|
|
const datestring = DateUtils.fullTimeString('1982-10-24 22:45');
|
|
expect(datestring.startsWith(`Sunday, October 24th 1982, 22:45:00`)).toBe(true);
|
|
});
|
|
});
|
|
});
|