mirror of
https://github.com/GeorgeSG/lovelace-time-picker-card.git
synced 2025-12-28 21:00:29 +00:00
Update all dependencies
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"files.exclude": {
|
||||
"dist/**": true
|
||||
},
|
||||
"files.associations": {
|
||||
"*.yaml": "home-assistant"
|
||||
}
|
||||
}
|
||||
|
||||
8
jest.config.js
Normal file
8
jest.config.js
Normal file
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
preset: 'ts-jest/presets/js-with-babel',
|
||||
testRegex: '/test/.*\\.test?\\.ts$',
|
||||
transformIgnorePatterns: [
|
||||
'node_modules/(?!(testing-library__dom|@open-wc|lit-html|lit-element|pure-lit|lit-element-state-decoupler)/)',
|
||||
],
|
||||
moduleFileExtensions: ['ts', 'js'],
|
||||
};
|
||||
14244
package-lock.json
generated
14244
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
54
package.json
54
package.json
@@ -15,47 +15,35 @@
|
||||
"license": "MIT",
|
||||
"repository": "git@github.com:GeorgeSG/lovelace-time-picker-card.git",
|
||||
"scripts": {
|
||||
"start": "rollup -c --watch",
|
||||
"start": "rollup -c --watch --bundleConfigAsCjs",
|
||||
"build": "npm run lint && npm run rollup",
|
||||
"lint": "eslint src/*.ts",
|
||||
"rollup": "rollup -c",
|
||||
"test": "./node_modules/karma/bin/karma start ./test/karma.conf.js",
|
||||
"rollup": "rollup -c --bundleConfigAsCjs",
|
||||
"test": "jest",
|
||||
"release-patch": "npm version patch && git push origin master --tags",
|
||||
"release-minor": "npm version minor && git push origin master --tags",
|
||||
"release-major": "npm version major && git push origin master --tags",
|
||||
"start:ha": "docker run --rm -p8124:8123 -v $(pwd)/devtools/homeassistant:/config homeassistant/home-assistant:latest",
|
||||
"start:ha": "docker run --rm -p8124:8123 -v $(pwd)/devtools/homeassistant:/config homeassistant/home-assistant:latest"
|
||||
},
|
||||
"dependencies": {
|
||||
"custom-card-helpers": "^1.6.6",
|
||||
"home-assistant-js-websocket": "^5.7.0",
|
||||
"lit-element": "^2.4.0",
|
||||
"lit-html": "^1.3.0"
|
||||
"custom-card-helpers": "^1.9.0",
|
||||
"home-assistant-js-websocket": "^8.0.0",
|
||||
"lit": "^2.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.12.7",
|
||||
"@open-wc/testing": "^2.5.32",
|
||||
"@rollup/plugin-commonjs": "^11.1.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^7.1.3",
|
||||
"@rollup/plugin-typescript": "^4.1.2",
|
||||
"@types/chai": "^4.2.14",
|
||||
"@typescript-eslint/eslint-plugin": "^2.34.0",
|
||||
"@typescript-eslint/parser": "^2.34.0",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-config-prettier": "^6.15.0",
|
||||
"eslint-plugin-prettier": "^3.1.4",
|
||||
"karma": "^6.3.16",
|
||||
"karma-chai": "^0.1.0",
|
||||
"karma-chrome-launcher": "^3.1.0",
|
||||
"karma-mocha": "^2.0.1",
|
||||
"karma-rollup-preprocessor": "^7.0.5",
|
||||
"mocha": "^7.2.0",
|
||||
"prettier": "^2.2.0",
|
||||
"rollup": "^1.32.1",
|
||||
"rollup-plugin-babel": "^4.4.0",
|
||||
"rollup-plugin-serve": "^1.1.0",
|
||||
"rollup-plugin-terser": "^5.3.1",
|
||||
"sinon": "^9.2.1",
|
||||
"typescript": "^3.9.7"
|
||||
"@el3um4s/rollup-plugin-terser": "^1.0.2",
|
||||
"@rollup/plugin-babel": "^6.0.2",
|
||||
"@rollup/plugin-commonjs": "^23.0.2",
|
||||
"@rollup/plugin-json": "^5.0.1",
|
||||
"@rollup/plugin-node-resolve": "^15.0.1",
|
||||
"@rollup/plugin-typescript": "^9.0.2",
|
||||
"@types/jest": "^29.2.1",
|
||||
"eslint": "^8.26.0",
|
||||
"jest": "^29.2.2",
|
||||
"prettier": "^2.7.1",
|
||||
"rollup": "^3.2.5",
|
||||
"rollup-plugin-serve": "^2.0.1",
|
||||
"ts-jest": "^29.0.3",
|
||||
"typescript": "^4.8.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import nodeResolve from '@rollup/plugin-node-resolve';
|
||||
import json from '@rollup/plugin-json';
|
||||
import typescript from '@rollup/plugin-typescript';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
import babel from 'rollup-plugin-babel';
|
||||
import { terser } from '@el3um4s/rollup-plugin-terser';
|
||||
import babel from '@rollup/plugin-babel';
|
||||
import serve from 'rollup-plugin-serve';
|
||||
|
||||
const dev = process.env.ROLLUP_WATCH;
|
||||
|
||||
const serveOptions = {
|
||||
contentBase: ['./dist'],
|
||||
host: '0.0.0.0',
|
||||
host: 'localhost',
|
||||
port: 5000,
|
||||
allowCrossOrigin: true,
|
||||
headers: {
|
||||
@@ -24,9 +24,9 @@ export default {
|
||||
format: 'es',
|
||||
},
|
||||
plugins: [
|
||||
typescript({ exclude: ['test/**/*'] }),
|
||||
nodeResolve(),
|
||||
json(),
|
||||
typescript(),
|
||||
babel({
|
||||
exclude: 'node_modules/**',
|
||||
}),
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
import {
|
||||
css,
|
||||
CSSResult,
|
||||
customElement,
|
||||
html,
|
||||
LitElement,
|
||||
property,
|
||||
TemplateResult,
|
||||
} from 'lit-element';
|
||||
import { ClassInfo, classMap } from 'lit-html/directives/class-map';
|
||||
import { css, CSSResult, html, LitElement, TemplateResult } from 'lit';
|
||||
import { customElement, property } from 'lit/decorators.js';
|
||||
import { ClassInfo, classMap } from 'lit/directives/class-map.js';
|
||||
import { Layout, Period } from '../types';
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
import {
|
||||
css,
|
||||
CSSResult,
|
||||
customElement,
|
||||
html,
|
||||
LitElement,
|
||||
property,
|
||||
TemplateResult,
|
||||
} from 'lit-element';
|
||||
import { LitElement, TemplateResult, html, CSSResult, css } from 'lit';
|
||||
import { customElement, property } from 'lit/decorators.js';
|
||||
import { TimeUnit } from '../models/time-unit';
|
||||
import { Direction } from '../types';
|
||||
|
||||
|
||||
@@ -1,23 +1,16 @@
|
||||
import { computeDomain, HomeAssistant, LovelaceCardEditor } from 'custom-card-helpers';
|
||||
import { HassEntity } from 'home-assistant-js-websocket';
|
||||
import {
|
||||
css,
|
||||
CSSResult,
|
||||
customElement,
|
||||
html,
|
||||
LitElement,
|
||||
property,
|
||||
TemplateResult,
|
||||
} from 'lit-element';
|
||||
import { css, CSSResult, html, LitElement, TemplateResult } from 'lit';
|
||||
import { customElement, property } from 'lit/decorators.js';
|
||||
import {
|
||||
DEFAULT_HOUR_STEP,
|
||||
DEFAULT_MINUTE_STEP,
|
||||
ENTITY_DOMAIN,
|
||||
DEFAULT_LAYOUT_ALIGN_CONTROLS,
|
||||
DEFAULT_LAYOUT_NAME,
|
||||
DEFAULT_MINUTE_STEP,
|
||||
DEFAULT_SECOND_STEP,
|
||||
ENTITY_DOMAIN,
|
||||
} from './const';
|
||||
import { TimePickerCardConfig, Layout, HourMode } from './types';
|
||||
import { HourMode, Layout, TimePickerCardConfig } from './types';
|
||||
|
||||
@customElement('time-picker-card-editor')
|
||||
export class TimePickerCardEditor extends LitElement implements LovelaceCardEditor {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { html, TemplateResult } from 'lit-element';
|
||||
import { TimePickerCardConfig, TimePickerHideConfig } from './types';
|
||||
import { LovelaceCard } from 'custom-card-helpers';
|
||||
import { HassEntity } from 'home-assistant-js-websocket';
|
||||
import { html, TemplateResult } from 'lit';
|
||||
import { TimePickerCardConfig, TimePickerHideConfig } from './types';
|
||||
|
||||
export class Partial {
|
||||
static error(error: string, origConfig: TimePickerCardConfig): TemplateResult {
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
import { computeDomain, HomeAssistant, LovelaceCard } from 'custom-card-helpers';
|
||||
import { HassEntity } from 'home-assistant-js-websocket';
|
||||
import {
|
||||
css,
|
||||
CSSResult,
|
||||
customElement,
|
||||
html,
|
||||
LitElement,
|
||||
property,
|
||||
TemplateResult,
|
||||
} from 'lit-element';
|
||||
import { ClassInfo, classMap } from 'lit-html/directives/class-map';
|
||||
import { css, CSSResult, html, LitElement, TemplateResult } from 'lit';
|
||||
import { customElement, property } from 'lit/decorators.js';
|
||||
import { ClassInfo, classMap } from 'lit/directives/class-map.js';
|
||||
import './components/time-period.component';
|
||||
import './components/time-unit.component';
|
||||
import {
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import { LovelaceCard } from 'custom-card-helpers';
|
||||
import { customElement, html, LitElement, TemplateResult } from 'lit-element';
|
||||
|
||||
@customElement('hui-error-card')
|
||||
export class HuiErrorCard extends LitElement implements LovelaceCard {
|
||||
setConfig(): void {
|
||||
return;
|
||||
}
|
||||
|
||||
render(): TemplateResult {
|
||||
return html``;
|
||||
}
|
||||
|
||||
getCardSize(): number {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
import { expect, fixture, html } from '@open-wc/testing';
|
||||
import { HomeAssistant } from 'custom-card-helpers';
|
||||
import { HassEntity } from 'home-assistant-js-websocket';
|
||||
import '../../src/time-picker-card';
|
||||
import { TimePickerCard } from '../../src/time-picker-card';
|
||||
import { TimePickerCardConfig, HourMode } from '../../src/types';
|
||||
import './test-error-card';
|
||||
|
||||
async function render(config?: {
|
||||
entityId?: string;
|
||||
friendlyName?: string;
|
||||
hasTime?: boolean;
|
||||
hourMode?: HourMode;
|
||||
hideName?: boolean;
|
||||
}): Promise<TimePickerCard> {
|
||||
const { entityId, friendlyName, hasTime, hourMode, hideName } = Object.assign(
|
||||
{
|
||||
entityId: 'input_datetime.wake_time',
|
||||
friendlyName: 'Wake Time',
|
||||
hasTime: true,
|
||||
hideName: false,
|
||||
},
|
||||
config
|
||||
);
|
||||
|
||||
const testEntity: HassEntity = {
|
||||
entity_id: entityId,
|
||||
attributes: {
|
||||
friendly_name: friendlyName,
|
||||
has_time: hasTime,
|
||||
},
|
||||
state: '00:10:00',
|
||||
last_changed: '',
|
||||
last_updated: '',
|
||||
context: {
|
||||
id: entityId,
|
||||
user_id: null,
|
||||
},
|
||||
};
|
||||
|
||||
const hass: Partial<HomeAssistant> = {
|
||||
states: {
|
||||
[entityId]: testEntity,
|
||||
},
|
||||
};
|
||||
|
||||
const testConfig: TimePickerCardConfig = {
|
||||
type: 'custom:time-picker-card',
|
||||
entity: entityId,
|
||||
hour_mode: hourMode,
|
||||
hide: {
|
||||
name: hideName,
|
||||
},
|
||||
};
|
||||
|
||||
const card = await fixture<TimePickerCard>(
|
||||
html`<time-picker-card .hass=${hass} .config=${testConfig}></time-picker-card>`
|
||||
);
|
||||
|
||||
card.setConfig(testConfig);
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
function errorCard(): string {
|
||||
return html`<hui-error-card></hui-error-card>`.getHTML();
|
||||
}
|
||||
|
||||
describe('test', () => {
|
||||
it('renders', async () => {
|
||||
const card = await render();
|
||||
expect(card).shadowDom.to.match('time-picker-card');
|
||||
});
|
||||
|
||||
it('errors if entity is not an input_datetime', async () => {
|
||||
const card = await render({ entityId: 'sensor.test_sensor' });
|
||||
expect(card).shadowDom.to.equal(errorCard());
|
||||
});
|
||||
|
||||
it("errors if entity doesn't have time", async () => {
|
||||
const card = await render({ hasTime: false });
|
||||
expect(card).shadowDom.to.equal(errorCard());
|
||||
});
|
||||
|
||||
it('renders card name', async () => {
|
||||
const card = await render();
|
||||
expect(card.shadowRoot?.innerHTML).to.match(/Wake Time/);
|
||||
});
|
||||
|
||||
it('hides card name', async () => {
|
||||
const card = await render({ hideName: true });
|
||||
expect(card.shadowRoot?.innerHTML).not.to.match(/Wake Time/);
|
||||
});
|
||||
|
||||
it('renders time units', async () => {
|
||||
const card = await render();
|
||||
expect(card.shadowRoot?.innerHTML.match(/<time-unit>/g)!.length).to.equal(2);
|
||||
});
|
||||
|
||||
describe('time-period', () => {
|
||||
it('is not rendered by default', async () => {
|
||||
const card = await render();
|
||||
expect(card.shadowRoot?.innerHTML.match(/<time-period>/g)).to.be.null;
|
||||
});
|
||||
|
||||
it('renders in 12-hour mode', async () => {
|
||||
const card = await render({ hourMode: 12 });
|
||||
expect(card.shadowRoot?.innerHTML.match(/<time-period>/g)!.length).to.equal(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,45 +0,0 @@
|
||||
module.exports = function (config) {
|
||||
return config.set({
|
||||
basePath: './',
|
||||
frameworks: ['mocha', 'chai'],
|
||||
files: ['**/*.test.ts'],
|
||||
preprocessors: {
|
||||
'**/*.test.ts': ['rollup'],
|
||||
},
|
||||
|
||||
rollupPreprocessor: {
|
||||
plugins: [
|
||||
require('@rollup/plugin-node-resolve')(),
|
||||
require('@rollup/plugin-json')(),
|
||||
require('@rollup/plugin-typescript')(),
|
||||
require('@rollup/plugin-commonjs')({
|
||||
namedExports: {
|
||||
chai: ['expect'],
|
||||
},
|
||||
}),
|
||||
],
|
||||
output: {
|
||||
format: 'umd',
|
||||
sourcemap: 'inline',
|
||||
},
|
||||
onwarn: function (message) {
|
||||
if (/Circular dependency/.test(message)) return;
|
||||
console.warn(message);
|
||||
},
|
||||
},
|
||||
|
||||
reporters: ['dots'],
|
||||
|
||||
port: 9876,
|
||||
colors: true,
|
||||
autoWatch: false,
|
||||
singleRun: true,
|
||||
|
||||
concurrency: Infinity,
|
||||
browsers: ['ChromeHeadless'],
|
||||
|
||||
client: {
|
||||
captureConsole: false,
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -1,165 +1,164 @@
|
||||
import { Hour } from '../../src/models/hour';
|
||||
import { Direction } from '../../src/types';
|
||||
import { DEFAULT_HOUR_STEP } from '../../src/const';
|
||||
import { expect } from 'chai';
|
||||
|
||||
describe('Hour', () => {
|
||||
let hour: Hour;
|
||||
|
||||
context('with default config', () => {
|
||||
describe('with default config', () => {
|
||||
beforeEach(() => {
|
||||
hour = new Hour(2);
|
||||
});
|
||||
|
||||
it('returns value', () => {
|
||||
expect(hour.value).to.equal(2);
|
||||
expect(hour.value).toEqual(2);
|
||||
});
|
||||
|
||||
it('has correct max value', () => {
|
||||
expect(hour.maxValue).to.equal(23);
|
||||
expect(hour.maxValue).toEqual(23);
|
||||
});
|
||||
|
||||
describe('toString', () => {
|
||||
it('returns formatted string', () => {
|
||||
expect(hour.toString()).to.equal('02');
|
||||
expect(hour.toString()).toEqual('02');
|
||||
});
|
||||
|
||||
it('renders values correctly', () => {
|
||||
hour = new Hour(0);
|
||||
expect(hour.toString()).to.equal('00');
|
||||
expect(hour.toString()).toEqual('00');
|
||||
|
||||
hour = new Hour(6);
|
||||
expect(hour.toString()).to.equal('06');
|
||||
expect(hour.toString()).toEqual('06');
|
||||
|
||||
hour = new Hour(12);
|
||||
expect(hour.toString()).to.equal('12');
|
||||
expect(hour.toString()).toEqual('12');
|
||||
|
||||
hour = new Hour(18);
|
||||
expect(hour.toString()).to.equal('18');
|
||||
expect(hour.toString()).toEqual('18');
|
||||
|
||||
hour = new Hour(23);
|
||||
expect(hour.toString()).to.equal('23');
|
||||
expect(hour.toString()).toEqual('23');
|
||||
});
|
||||
});
|
||||
|
||||
describe('stepUpdate', () => {
|
||||
it('updates up', () => {
|
||||
hour.stepUpdate(Direction.UP);
|
||||
expect(hour.value).to.equal(3);
|
||||
expect(hour.value).toEqual(3);
|
||||
});
|
||||
|
||||
it('updates down', () => {
|
||||
hour.stepUpdate(Direction.DOWN);
|
||||
expect(hour.value).to.equal(1);
|
||||
expect(hour.value).toEqual(1);
|
||||
});
|
||||
|
||||
it('goes up from 23 to 0', () => {
|
||||
hour = new Hour(23);
|
||||
hour.stepUpdate(Direction.UP);
|
||||
expect(hour.value).to.equal(0);
|
||||
expect(hour.value).toEqual(0);
|
||||
});
|
||||
|
||||
it('goes down from 0 to 23', () => {
|
||||
hour = new Hour(0);
|
||||
hour.stepUpdate(Direction.DOWN);
|
||||
expect(hour.value).to.equal(23);
|
||||
expect(hour.value).toEqual(23);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setStringValue', () => {
|
||||
it('sets value from valid string', () => {
|
||||
hour.setStringValue('3');
|
||||
expect(hour.value).to.equal(3);
|
||||
expect(hour.value).toEqual(3);
|
||||
});
|
||||
|
||||
it("doesn't set value from invalid string", () => {
|
||||
hour.setStringValue('test');
|
||||
expect(hour.value).to.equal(2);
|
||||
expect(hour.value).toEqual(2);
|
||||
});
|
||||
|
||||
it("doesn't set value from outside of scope", () => {
|
||||
hour.setStringValue('24');
|
||||
expect(hour.value).to.equal(2);
|
||||
expect(hour.value).toEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('with a different step size', () => {
|
||||
describe('with a different step size', () => {
|
||||
beforeEach(() => {
|
||||
hour = new Hour(2, 5);
|
||||
});
|
||||
|
||||
it('goes up correctly', () => {
|
||||
hour.stepUpdate(Direction.UP);
|
||||
expect(hour.value).to.equal(7);
|
||||
expect(hour.value).toEqual(7);
|
||||
|
||||
hour.stepUpdate(Direction.UP);
|
||||
hour.stepUpdate(Direction.UP);
|
||||
hour.stepUpdate(Direction.UP);
|
||||
hour.stepUpdate(Direction.UP);
|
||||
|
||||
expect(hour.value).to.equal(3);
|
||||
expect(hour.value).toEqual(3);
|
||||
});
|
||||
|
||||
it('goes down correclty', () => {
|
||||
hour.stepUpdate(Direction.DOWN);
|
||||
expect(hour.value).to.equal(21);
|
||||
expect(hour.value).toEqual(21);
|
||||
});
|
||||
});
|
||||
|
||||
context('in 12 hour mode', () => {
|
||||
describe('in 12 hour mode', () => {
|
||||
beforeEach(() => {
|
||||
hour = new Hour(2, DEFAULT_HOUR_STEP, 12);
|
||||
});
|
||||
|
||||
it('has correct max value', () => {
|
||||
expect(hour.maxValue).to.equal(12);
|
||||
expect(hour.maxValue).toEqual(12);
|
||||
});
|
||||
|
||||
describe('togglePeriod', () => {
|
||||
it('changes values correclty', () => {
|
||||
hour = new Hour(2, DEFAULT_HOUR_STEP, 12);
|
||||
hour.togglePeriod();
|
||||
expect(hour.value).to.equal(14);
|
||||
expect(hour.value).toEqual(14);
|
||||
|
||||
hour = new Hour(0, DEFAULT_HOUR_STEP, 12);
|
||||
hour.togglePeriod();
|
||||
expect(hour.value).to.equal(12);
|
||||
expect(hour.value).toEqual(12);
|
||||
|
||||
hour = new Hour(23, DEFAULT_HOUR_STEP, 12);
|
||||
hour.togglePeriod();
|
||||
expect(hour.value).to.equal(11);
|
||||
expect(hour.value).toEqual(11);
|
||||
});
|
||||
|
||||
it('has no side effects', () => {
|
||||
const value = hour.value;
|
||||
hour.togglePeriod();
|
||||
hour.togglePeriod();
|
||||
expect(hour.value).to.equal(value);
|
||||
expect(hour.value).toEqual(value);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toString', () => {
|
||||
it('renders values above 12 orrectly', () => {
|
||||
hour = new Hour(13, DEFAULT_HOUR_STEP, 12);
|
||||
expect(hour.toString()).to.equal('01');
|
||||
expect(hour.toString()).toEqual('01');
|
||||
});
|
||||
|
||||
it('renders values correctly', () => {
|
||||
hour = new Hour(0, DEFAULT_HOUR_STEP, 12);
|
||||
expect(hour.toString()).to.equal('12');
|
||||
expect(hour.toString()).toEqual('12');
|
||||
|
||||
hour = new Hour(6, DEFAULT_HOUR_STEP, 12);
|
||||
expect(hour.toString()).to.equal('06');
|
||||
expect(hour.toString()).toEqual('06');
|
||||
|
||||
hour = new Hour(12, DEFAULT_HOUR_STEP, 12);
|
||||
expect(hour.toString()).to.equal('12');
|
||||
expect(hour.toString()).toEqual('12');
|
||||
|
||||
hour = new Hour(18, DEFAULT_HOUR_STEP, 12);
|
||||
expect(hour.toString()).to.equal('06');
|
||||
expect(hour.toString()).toEqual('06');
|
||||
|
||||
hour = new Hour(23, DEFAULT_HOUR_STEP, 12);
|
||||
expect(hour.toString()).to.equal('11');
|
||||
expect(hour.toString()).toEqual('11');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,119 +1,118 @@
|
||||
import { Minute } from '../../src/models/minute';
|
||||
import { Direction } from '../../src/types';
|
||||
import { expect } from 'chai';
|
||||
|
||||
describe('Minute', () => {
|
||||
let minute: Minute;
|
||||
|
||||
context('with default config', () => {
|
||||
describe('with default config', () => {
|
||||
beforeEach(() => {
|
||||
minute = new Minute(2);
|
||||
});
|
||||
|
||||
it('returns value', () => {
|
||||
expect(minute.value).to.equal(2);
|
||||
expect(minute.value).toEqual(2);
|
||||
});
|
||||
|
||||
it('has correct max value', () => {
|
||||
expect(minute.maxValue).to.equal(59);
|
||||
expect(minute.maxValue).toEqual(59);
|
||||
});
|
||||
|
||||
describe('toString', () => {
|
||||
it('renders values correctly', () => {
|
||||
minute = new Minute(0);
|
||||
expect(minute.toString()).to.equal('00');
|
||||
expect(minute.toString()).toEqual('00');
|
||||
|
||||
minute = new Minute(5);
|
||||
expect(minute.toString()).to.equal('05');
|
||||
expect(minute.toString()).toEqual('05');
|
||||
|
||||
minute = new Minute(59);
|
||||
expect(minute.toString()).to.equal('59');
|
||||
expect(minute.toString()).toEqual('59');
|
||||
});
|
||||
});
|
||||
|
||||
describe('stepUpdate', () => {
|
||||
it('updates up', () => {
|
||||
minute.stepUpdate(Direction.UP);
|
||||
expect(minute.value).to.equal(7);
|
||||
expect(minute.value).toEqual(7);
|
||||
});
|
||||
|
||||
it('updates down', () => {
|
||||
minute.stepUpdate(Direction.DOWN);
|
||||
expect(minute.value).to.equal(57);
|
||||
expect(minute.value).toEqual(57);
|
||||
});
|
||||
|
||||
it('goes up from 59 to 4', () => {
|
||||
minute = new Minute(59);
|
||||
minute.stepUpdate(Direction.UP);
|
||||
expect(minute.value).to.equal(4);
|
||||
expect(minute.value).toEqual(4);
|
||||
});
|
||||
|
||||
it('goes down from 0 to 55', () => {
|
||||
minute = new Minute(0);
|
||||
minute.stepUpdate(Direction.DOWN);
|
||||
expect(minute.value).to.equal(55);
|
||||
expect(minute.value).toEqual(55);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setStringValue', () => {
|
||||
it('sets value from valid string', () => {
|
||||
minute.setStringValue('3');
|
||||
expect(minute.value).to.equal(3);
|
||||
expect(minute.value).toEqual(3);
|
||||
});
|
||||
|
||||
it("doesn't set value from invalid string", () => {
|
||||
minute.setStringValue('test');
|
||||
expect(minute.value).to.equal(2);
|
||||
expect(minute.value).toEqual(2);
|
||||
});
|
||||
|
||||
it("doesn't set value from outside of scope", () => {
|
||||
minute.setStringValue('60');
|
||||
expect(minute.value).to.equal(2);
|
||||
expect(minute.value).toEqual(2);
|
||||
|
||||
minute.setStringValue('65');
|
||||
expect(minute.value).to.equal(2);
|
||||
expect(minute.value).toEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('with a different step size', () => {
|
||||
describe('with a different step size', () => {
|
||||
beforeEach(() => {
|
||||
minute = new Minute(2, 15);
|
||||
});
|
||||
|
||||
it('goes up correctly', () => {
|
||||
minute.stepUpdate(Direction.UP);
|
||||
expect(minute.value).to.equal(17);
|
||||
expect(minute.value).toEqual(17);
|
||||
|
||||
minute.stepUpdate(Direction.UP);
|
||||
minute.stepUpdate(Direction.UP);
|
||||
minute.stepUpdate(Direction.UP);
|
||||
expect(minute.value).to.equal(2);
|
||||
expect(minute.value).toEqual(2);
|
||||
|
||||
minute.stepUpdate(Direction.UP);
|
||||
expect(minute.value).to.equal(17);
|
||||
expect(minute.value).toEqual(17);
|
||||
});
|
||||
|
||||
it('goes down correclty', () => {
|
||||
minute.stepUpdate(Direction.DOWN);
|
||||
expect(minute.value).to.equal(47);
|
||||
expect(minute.value).toEqual(47);
|
||||
});
|
||||
});
|
||||
|
||||
describe('will overflow', () => {
|
||||
it('returns true if the minutes will overflow an hour up', () => {
|
||||
minute.setStringValue('59');
|
||||
expect(minute.willOverflow(Direction.UP)).to.be.true;
|
||||
expect(minute.willOverflow(Direction.UP)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true if the minutes will overflow an hour down', () => {
|
||||
minute.setStringValue('0');
|
||||
expect(minute.willOverflow(Direction.DOWN)).to.be.true;
|
||||
expect(minute.willOverflow(Direction.DOWN)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true if the minutes will not overflow', () => {
|
||||
minute.setStringValue('55');
|
||||
expect(minute.willOverflow(Direction.DOWN)).to.be.false;
|
||||
expect(minute.willOverflow(Direction.DOWN)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,119 +1,118 @@
|
||||
import { Second } from '../../src/models/second';
|
||||
import { Direction } from '../../src/types';
|
||||
import { expect } from 'chai';
|
||||
|
||||
describe('Second', () => {
|
||||
let second: Second;
|
||||
|
||||
context('with default config', () => {
|
||||
describe('with default config', () => {
|
||||
beforeEach(() => {
|
||||
second = new Second(2);
|
||||
});
|
||||
|
||||
it('returns value', () => {
|
||||
expect(second.value).to.equal(2);
|
||||
expect(second.value).toEqual(2);
|
||||
});
|
||||
|
||||
it('has correct max value', () => {
|
||||
expect(second.maxValue).to.equal(59);
|
||||
expect(second.maxValue).toEqual(59);
|
||||
});
|
||||
|
||||
describe('toString', () => {
|
||||
it('renders values correctly', () => {
|
||||
second = new Second(0);
|
||||
expect(second.toString()).to.equal('00');
|
||||
expect(second.toString()).toEqual('00');
|
||||
|
||||
second = new Second(5);
|
||||
expect(second.toString()).to.equal('05');
|
||||
expect(second.toString()).toEqual('05');
|
||||
|
||||
second = new Second(59);
|
||||
expect(second.toString()).to.equal('59');
|
||||
expect(second.toString()).toEqual('59');
|
||||
});
|
||||
});
|
||||
|
||||
describe('stepUpdate', () => {
|
||||
it('updates up', () => {
|
||||
second.stepUpdate(Direction.UP);
|
||||
expect(second.value).to.equal(7);
|
||||
expect(second.value).toEqual(7);
|
||||
});
|
||||
|
||||
it('updates down', () => {
|
||||
second.stepUpdate(Direction.DOWN);
|
||||
expect(second.value).to.equal(57);
|
||||
expect(second.value).toEqual(57);
|
||||
});
|
||||
|
||||
it('goes up from 59 to 4', () => {
|
||||
second = new Second(59);
|
||||
second.stepUpdate(Direction.UP);
|
||||
expect(second.value).to.equal(4);
|
||||
expect(second.value).toEqual(4);
|
||||
});
|
||||
|
||||
it('goes down from 0 to 55', () => {
|
||||
second = new Second(0);
|
||||
second.stepUpdate(Direction.DOWN);
|
||||
expect(second.value).to.equal(55);
|
||||
expect(second.value).toEqual(55);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setStringValue', () => {
|
||||
it('sets value from valid string', () => {
|
||||
second.setStringValue('3');
|
||||
expect(second.value).to.equal(3);
|
||||
expect(second.value).toEqual(3);
|
||||
});
|
||||
|
||||
it("doesn't set value from invalid string", () => {
|
||||
second.setStringValue('test');
|
||||
expect(second.value).to.equal(2);
|
||||
expect(second.value).toEqual(2);
|
||||
});
|
||||
|
||||
it("doesn't set value from outside of scope", () => {
|
||||
second.setStringValue('60');
|
||||
expect(second.value).to.equal(2);
|
||||
expect(second.value).toEqual(2);
|
||||
|
||||
second.setStringValue('65');
|
||||
expect(second.value).to.equal(2);
|
||||
expect(second.value).toEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('with a different step size', () => {
|
||||
describe('with a different step size', () => {
|
||||
beforeEach(() => {
|
||||
second = new Second(2, 15);
|
||||
});
|
||||
|
||||
it('goes up correctly', () => {
|
||||
second.stepUpdate(Direction.UP);
|
||||
expect(second.value).to.equal(17);
|
||||
expect(second.value).toEqual(17);
|
||||
|
||||
second.stepUpdate(Direction.UP);
|
||||
second.stepUpdate(Direction.UP);
|
||||
second.stepUpdate(Direction.UP);
|
||||
expect(second.value).to.equal(2);
|
||||
expect(second.value).toEqual(2);
|
||||
|
||||
second.stepUpdate(Direction.UP);
|
||||
expect(second.value).to.equal(17);
|
||||
expect(second.value).toEqual(17);
|
||||
});
|
||||
|
||||
it('goes down correclty', () => {
|
||||
second.stepUpdate(Direction.DOWN);
|
||||
expect(second.value).to.equal(47);
|
||||
expect(second.value).toEqual(47);
|
||||
});
|
||||
});
|
||||
|
||||
describe('will overflow', () => {
|
||||
it('returns true if the Seconds will overflow an hour up', () => {
|
||||
second.setStringValue('59');
|
||||
expect(second.willOverflow(Direction.UP)).to.be.true;
|
||||
expect(second.willOverflow(Direction.UP)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true if the Seconds will overflow an hour down', () => {
|
||||
second.setStringValue('0');
|
||||
expect(second.willOverflow(Direction.DOWN)).to.be.true;
|
||||
expect(second.willOverflow(Direction.DOWN)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true if the Seconds will not overflow', () => {
|
||||
second.setStringValue('55');
|
||||
expect(second.willOverflow(Direction.DOWN)).to.be.false;
|
||||
expect(second.willOverflow(Direction.DOWN)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user