Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.2.0 #36

Merged
merged 26 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
"env": {
"browser": true,
"node": true,
"es6": true
"es6": true,
"jest": true
},
"globals": {
"Module": true,
"Log": true,
"waitForAsync": true,
"fetchMock": true
},
"rules": {
"import/no-commonjs": 0,
Expand All @@ -23,6 +30,7 @@
"curly": ["error", "all"],
"array-bracket-spacing": 0,
"space-before-function-paren": 0,
"object-curly-spacing": ["error", "never"],
"object-property-newline": ["error", { "allowAllPropertiesOnSameLine": true }]
}
}
38 changes: 38 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: build

on:
push:
branches: [ master, develop ]
pull_request:
branches: [ master, develop ]

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 14.x ]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run lint

test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run test
15 changes: 15 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: changelog

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: dangoslen/[email protected]
with:
changeLogPath: CHANGELOG.md
skipLabels: Skip Changelog
29 changes: 29 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: coverage

on:
push:
branches: [ master, develop ]
pull_request:
branches: [ master, develop ]

jobs:
upload-coverage-report:
strategy:
matrix:
node-version: [ 14.x ]
platform: [ ubuntu-latest ]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run test:coverage
- uses: codecov/codecov-action@v1
with:
file: ./coverage/lcov.info
fail_ci_if_error: true
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# MMM-soccer Changelog

## [Unreleased]

### Fixed

### Added

### Changed

### Removed

## [2.2.0]

**Update requires installation of dependencies refer to readme file!**

### Fixed

* Max teams showed in some occasions 1 team too much.

### Added

* Github actions (building and changelog)
* Dependency `node-fetch`
* Automated tests for node_helper and module
* Code coverage
* Codecov report

### Removed

* Travis integration
* Dependency `request`

## [2.1.1]

### Added
Expand Down
78 changes: 39 additions & 39 deletions MMM-soccer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ Module.register('MMM-soccer', {
* @member {Object} competition - Details about the current selected league.
*/
competition: {},
/**
* @member {Object} season - Details about the current season of the selected league.
*/
season: {},

/**
* @function start
Expand All @@ -110,7 +114,7 @@ Module.register('MMM-soccer', {
* @returns {void}
*/
getData() {
this.sendSocketNotification('GET_DATA', { league: this.currentLeague, api_key: this.config.api_key });
this.sendSocketNotification('GET_DATA', {league: this.currentLeague, api_key: this.config.api_key});
},

/**
Expand Down Expand Up @@ -206,7 +210,7 @@ Module.register('MMM-soccer', {
boundaries: this.calculateTeamDisplayBoundaries(),
competitionName: this.competition.name || this.name,
config: this.config,
matchDayNumber: this.season ? this.season.currentMatchday : 'N/A',
matchDayNumber: this.season.currentMatchday || 'N/A',
standing: this.standing,
loading: this.loading
};
Expand Down Expand Up @@ -269,16 +273,16 @@ Module.register('MMM-soccer', {
* @returns {void}
*/
handleLeagueSwitch(data) {
const countrys = Object.keys(this.config.leagues);
const countries = Object.keys(this.config.leagues);

for (let i = 0; i < countrys.length; i += 1) {
const regexp = new RegExp(countrys[i], 'g');
for (const country of countries) {
const regexp = new RegExp(country, 'g');

if (regexp.test(data)) {
this.sendNotification('CLOSE_MODAL');

if (this.currentLeague !== this.config.leagues[countrys[i]]) {
this.currentLeague = this.config.leagues[countrys[i]];
if (this.currentLeague !== this.config.leagues[country]) {
this.currentLeague = this.config.leagues[country];
this.getData();
}

Expand Down Expand Up @@ -308,23 +312,27 @@ Module.register('MMM-soccer', {
},

/**
* @function isMaxTeamsLessAll
* @description Are there more entries than the config option specifies.
* @function getMaxTeams
* @description Are there less entries than the config option specifies.
*
* @returns {boolean} Is max teams less than all teams?
* @returns {number} Amount of teams to display
*/
isMaxTeamsLessAll() {
return this.config.max_teams && this.config.max_teams <= this.standing.length;
getMaxTeams() {
if (this.config.max_teams) {
return Math.min(Math.max(this.config.max_teams, 0), this.standing.length);
}

return this.standing.length;
},

/**
* @function findFocusTeam
* @description Helper function to find index of team in standings
*
* @returns {Object} Index of team, first and last team to display.
* @returns {Object} Index of team, first and last team to display. focusTeamIndex is -1 if it can't be found.
*/
findFocusTeam() {
let focusTeamIndex;
let focusTeamIndex = -1;

for (let i = 0; i < this.standing.length; i += 1) {
if (this.standing[i].team.name === this.config.focus_on[this.config.show]) {
Expand All @@ -333,9 +341,9 @@ Module.register('MMM-soccer', {
}
}

const { firstTeam, lastTeam } = this.getFirstAndLastTeam(focusTeamIndex);
const {firstTeam, lastTeam} = this.getFirstAndLastTeam(focusTeamIndex);

return { focusTeamIndex, firstTeam, lastTeam };
return {focusTeamIndex, firstTeam, lastTeam};
},

/**
Expand All @@ -347,25 +355,21 @@ Module.register('MMM-soccer', {
* @returns {Object} Index of the first and the last team.
*/
getFirstAndLastTeam(index) {
let firstTeam;
let lastTeam;
let firstTeam = 0;
let lastTeam = this.standing.length - 1;

if (this.config.max_teams) {
const before = parseInt(this.config.max_teams / 2);
firstTeam = index - before >= 0 ? index - before : 0;
if (firstTeam + this.config.max_teams <= this.standing.length) {
lastTeam = firstTeam + this.config.max_teams;
const indexDiff = this.config.max_teams - 1;
firstTeam = Math.max(index - before, 0);
if (firstTeam + indexDiff < this.standing.length) {
lastTeam = firstTeam + indexDiff;
} else {
lastTeam = this.standing.length;
firstTeam = lastTeam - this.config.max_teams >= 0
? lastTeam - this.config.max_teams : 0;
firstTeam = Math.max(lastTeam - indexDiff, 0);
}
} else {
firstTeam = 0;
lastTeam = this.standing.length;
}

return { firstTeam, lastTeam };
return {firstTeam, lastTeam};
},

/**
Expand All @@ -380,24 +384,18 @@ Module.register('MMM-soccer', {
return {
focusTeamIndex: -1,
firstTeam: 0,
lastTeam: this.isMaxTeamsLessAll() ? this.config.max_teams : this.standing.length
lastTeam: this.getMaxTeams() - 1
};
} else if (this.config.focus_on[this.config.show] === 'BOTTOM') {
return {
focusTeamIndex: -1,
firstTeam: this.isMaxTeamsLessAll() ? this.standing.length - this.config.max_teams : 0,
lastTeam: this.standing.length
firstTeam: this.standing.length - this.getMaxTeams(),
lastTeam: this.standing.length - 1
};
}

return this.findFocusTeam();
}

return {
focusTeamIndex: -1,
firstTeam: 0,
lastTeam: this.config.max_teams || this.standing.length
};
return this.findFocusTeam();
},

/**
Expand All @@ -411,7 +409,9 @@ Module.register('MMM-soccer', {
if (this.config.max_teams && focus >= 0) {
if (index !== focus) {
const currentStep = Math.abs(index - focus);
return `opacity: ${1 - 1 / this.config.max_teams * currentStep}`;
const percentage = (1 - 1 / this.config.max_teams * currentStep).toFixed(2);

return `opacity: ${percentage}`;
}
}

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MMM-soccer [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/fewieden/MMM-soccer/master/LICENSE) [![Build Status](https://travis-ci.org/fewieden/MMM-soccer.svg?branch=master)](https://travis-ci.org/fewieden/MMM-soccer) [![Code Climate](https://codeclimate.com/github/fewieden/MMM-soccer/badges/gpa.svg?style=flat)](https://codeclimate.com/github/fewieden/MMM-soccer) [![Known Vulnerabilities](https://snyk.io/test/github/fewieden/mmm-soccer/badge.svg)](https://snyk.io/test/github/fewieden/mmm-soccer)
# MMM-soccer [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/fewieden/MMM-soccer/master/LICENSE) ![Build status](https://github.com/fewieden/MMM-soccer/workflows/build/badge.svg) [![Code Climate](https://codeclimate.com/github/fewieden/MMM-soccer/badges/gpa.svg?style=flat)](https://codeclimate.com/github/fewieden/MMM-soccer) [![Known Vulnerabilities](https://snyk.io/test/github/fewieden/mmm-soccer/badge.svg)](https://snyk.io/test/github/fewieden/mmm-soccer) [![codecov](https://codecov.io/gh/fewieden/MMM-soccer/branch/master/graph/badge.svg?token=vB22qyfCXz)](https://codecov.io/gh/fewieden/MMM-soccer)

European Soccer Standings Module for MagicMirror²

Expand All @@ -11,7 +11,7 @@ European Soccer Standings Module for MagicMirror²
* An installation of [MagicMirror²](https://github.com/MichMich/MagicMirror)
* OPTIONAL: [Voice Control](https://github.com/fewieden/MMM-voice) and [MMM-Modal](https://github.com/fewieden/MMM-Modal)
* npm
* [request](https://www.npmjs.com/package/request)
* [node-fetch](https://www.npmjs.com/package/node-fetch)

## Installation

Expand Down
7 changes: 7 additions & 0 deletions __mocks__/Logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
global.Log = {
debug: jest.fn(),
log: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
}
Loading