Skip to content

Commit

Permalink
fix: invalid date in cases its not a full day event (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
idaho committed Dec 15, 2023
1 parent 2207c2e commit 7f831c8
Show file tree
Hide file tree
Showing 23 changed files with 520 additions and 140 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ jobs:
- name: Install dependencies
run: |
npm install
- name: Quality assurance
- name: Lint
run: |
npm run qa
npm run lint
- name: Test
run: |
npm test
- name: Build
run: |
npm run build
23 changes: 23 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

module.exports = {
displayName: { name: 'source', color: 'magenta' },
rootDir: './',
testEnvironment: 'node',
testPathIgnorePatterns: [ 'node_modules/', './dist' ],
moduleFileExtensions: [ 'js', 'ts', 'tsx', 'json' ],
transform: {
'^.+\\.(ts|tsx)$': [
'ts-jest', {
tsconfig: '<rootDir>/tsconfig.json',
isolatedModules: true
}
]
},
clearMocks: true,
resetMocks: true,
restoreMocks: true,
testMatch: [
`<rootDir>/src/**/*.test.ts`
]
};
46 changes: 46 additions & 0 deletions mocks/calendarData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"start": {
"date": "2023-12-10"
},
"end": {
"date": "2023-12-11"
},
"summary": "BIO",
"description": null,
"location": null
},
{
"start": {
"dateTime": "2023-12-14T13:10:00+01:00"
},
"end": {
"dateTime": "2023-12-14T14:10:00+01:00"
},
"summary": "Event 1",
"description": null,
"location": null
},
{
"start": {
"dateTime": "2023-12-18T09:10:00+01:00"
},
"end": {
"dateTime": "2023-12-18T10:10:00+01:00"
},
"summary": "Event 2",
"description": null,
"location": null
},
{
"start": {
"dateTime": "2023-12-18T18:00:00+01:00"
},
"end": {
"dateTime": "2023-12-18T19:00:00+01:00"
},
"summary": "Event 3",
"description": null,
"location": null
}
]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"clean": "npx rimraf ./dist",
"qa": "npm run lint && npm run test",
"lint": "npx eslint ./src --color",
"test": "echo \"no tests defined\"",
"test": "npx jest",
"start:hass": "docker run --rm -p8123:8123 -v ${PWD}/.hass_dev:/config homeassistant/home-assistant:beta",
"start:hass-cmd": "docker run --rm -p8123:8123 -v %cd%/.hass_dev:/config homeassistant/home-assistant:beta"
},
Expand Down
13 changes: 0 additions & 13 deletions src/cards/trash-card/const.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import type { TrashItem } from './trash-card-config';

// eslint-disable-next-line @typescript-eslint/naming-convention
export const TRASH_CARD_NAME = `trash-card`;
// eslint-disable-next-line @typescript-eslint/naming-convention
export const TRASH_CARD_EDITOR_NAME = `${TRASH_CARD_NAME}-editor`;

export type TrashDataItem = TrashItem & {
type: string;
data?: {
summary: string;
};
};

export interface TrashData {
date: Date;
item?: TrashDataItem;
}
18 changes: 6 additions & 12 deletions src/cards/trash-card/trash-card-config.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import type { EntitySharedConfig } from 'lovelace-mushroom/src/shared/config/entity-config';
import type { ItemSettings } from '../../utils/itemSettings';
import { layoutStruct } from 'lovelace-mushroom/src/utils/layout';
import type { LovelaceCardConfig } from 'lovelace-mushroom/src/ha';
import { lovelaceCardConfigStruct } from 'lovelace-mushroom/src/shared/config/lovelace-card-config';
import { assign, boolean, integer, object, optional, string } from 'superstruct';

export interface TrashItem {
label?: string;
color?: string;
pattern?: string;
icon?: string;
}

type EntityWithOutIcon = Omit<EntitySharedConfig, 'icon'>;
export type TrashCardConfig = LovelaceCardConfig &
EntityWithOutIcon & {
settings?: {
organic?: TrashItem;
paper?: TrashItem;
recycle?: TrashItem;
waste?: TrashItem;
others?: TrashItem;
organic?: ItemSettings;
paper?: ItemSettings;
recycle?: ItemSettings;
waste?: ItemSettings;
others?: ItemSettings;
};
// eslint-disable-next-line @typescript-eslint/naming-convention
next_days?: number;
Expand Down
5 changes: 1 addition & 4 deletions src/cards/trash-card/trash-card-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,12 @@ export class TrashCardEditor extends LitElement implements LovelaceCardEditor {

const customLocalize = setupCustomlocalize(this.hass);

if (GENERIC_LABELS.includes(schema.name)) {
if (GENERIC_LABELS.includes(schema.name) || OTHER_LABELS.has(schema.name)) {
return customLocalize(`editor.card.generic.${schema.name}`);
}
if (schema.label && TRASH_LABELS.has(schema.label)) {
return customLocalize(`editor.card.trash.${schema.label}`);
}
if (OTHER_LABELS.has(schema.name)) {
return customLocalize(`editor.card.generic.${schema.name}`);
}

return this.hass.localize(`ui.panel.lovelace.editor.card.generic.${schema.name}`);
};
Expand Down
Loading

0 comments on commit 7f831c8

Please sign in to comment.