Skip to content

Commit

Permalink
Running mocha tests again
Browse files Browse the repository at this point in the history
  • Loading branch information
thamara committed Oct 25, 2022
1 parent 1bd3c0e commit 440b192
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 45 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/Checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,31 @@ jobs:
sudo chmod +x /tmp/chromedriver/chromedriver
/tmp/chromedriver/chromedriver &
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
- name: ' Create COV_REPORT'
run: |
mkdir COV_REPORT
- name: ' Tests'
shell: bash
env:
DISPLAY: ':99'
run: |
npm ci
npm run test:jest
- name: ' Create COV_REPORT'
run: |
mkdir COV_REPORT
- name: ' Copy jest results'
run: |
cp coverage_jest/coverage-final.json COV_REPORT/coverage-final-jest.json
- name: ' Tests - Mocha'
run: npm run test:mocha
shell: bash
if: matrix.os == 'ubuntu-latest'
- name: ' Copy mocha results'
run: |
cp coverage_jest/coverage-final.json COV_REPORT/coverage-final-mocha.json
if: matrix.os == 'ubuntu-latest'
- name: ' CodeCov'
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: COV_REPORT/coverage-final-jest.json
files: COV_REPORT/coverage-final-*.json
name: codecov-${{ matrix.os }}
verbose: true
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"start": "electron .",
"test": "npm-run-all test:*",
"test:jest": "jest --runInBand --detectOpenHandles --verbose --colors",
"test:mocha": "nyc --reporter=lcov --reporter=json mocha tests/*"
"test:mocha": "nyc --reporter=lcov --reporter=json mocha tests/* --bail"
},
"pre-commit": [
"clean",
Expand Down
98 changes: 58 additions & 40 deletions tests/main-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,67 @@ process.env.NODE_ENV = 'test';
const months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ];
const weekDay = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ];

function log(msg)
{
console.log(`${(new Date()).toISOString().substr(0, 19)}: ${msg}`);
}

describe('Application launch', function()
{
// deepcode ignore UseArrowFunction: => will not work on here
beforeEach(function()
this.timeout(30000);
this.beforeEach(async function()
{
this.timeout(25000); // Estimated pessimistic time taken for the app to the brought up in CI
this.app = new Application({
path: electronPath,
args: [path.join(__dirname, '..')]
args: [path.join(__dirname, '..')],
waitTimeout: 30000,
quitTimeout: 1000
});
return this.app.start();
log('Start app...')
await this.app.start();
log('App started.')
});

afterEach(function()
this.afterEach(async function()
{
this.timeout(10000); // Estimated pessimistic time taken for the app to be stopped in CI
this.timeout(30000);
log(`App is running: ${this.app && this.app.isRunning()}`)
if (this.app && this.app.isRunning())
{
return this.app.stop();
log('Stop app...');
await this.app.stop();
log('App stoped');
}
});

it('App opens correctly', async function()
{
log('Running test ' + this.test.title);
const { client, browserWindow } = this.app;
await client.waitUntilWindowLoaded();
await client.waitUntilWindowLoaded(10000);
const title = await browserWindow.getTitle();
assert.equal(title, 'Time to Leave');
log('Running test - Done');
});

it('Calendar opens on Current Month/Year', async function()
{
log('Running test ' + this.test.title);
const { client } = this.app;
await client.waitUntilWindowLoaded();
await client.waitUntilWindowLoaded(10000);

const monthYear = await client.$('#month-year');
const monthYearText = await monthYear.getText();
const today = new Date();
assert.equal(monthYearText, `${months[today.getMonth()]} ${today.getFullYear()}`);
});

it('Change to Day View', async function()
{
const { client } = this.app;
await client.waitUntilWindowLoaded();

const switchViewBtn = await client.$('#switch-view');
await switchViewBtn.click();
const headerDate = await client.$('#header-date');
const headerDateText = await headerDate.getText();
const today = new Date();
assert.equal(headerDateText, `${weekDay[today.getDay()]}, ${months[today.getMonth()]} ${today.getDate()}, ${today.getFullYear()}`);
log('Running test - Done');
});

it('Calendar change to previous Month', async function()
{
log('Running test ' + this.test.title);
const { client } = this.app;
await client.waitUntilWindowLoaded();
await client.waitUntilWindowLoaded(10000);

const prevMonth = await client.$('#prev-month');
prevMonth.click();
Expand All @@ -76,12 +79,14 @@ describe('Application launch', function()
const today = new Date();
const prevMonthDate = new Date(today.getFullYear(), today.getMonth(), -1);
assert.equal(monthYearText, `${months[prevMonthDate.getMonth()]} ${prevMonthDate.getFullYear()}`);
log('Running test - Done');
});

it('Calendar change to next Month', async function()
{
log('Running test ' + this.test.title);
const { client } = this.app;
await client.waitUntilWindowLoaded();
await client.waitUntilWindowLoaded(10000);

const nextMonth = await client.$('#next-month');
nextMonth.click();
Expand All @@ -90,35 +95,48 @@ describe('Application launch', function()
const today = new Date();
const nextMonthDate = new Date(today.getFullYear(), today.getMonth() + 1, 1);
assert.equal(monthYearText, `${months[nextMonthDate.getMonth()]} ${nextMonthDate.getFullYear()}`);
log('Running test - Done');
});

it('Calendar change to pervious Day', async function()
it('Day View - Current, yesterday and tomorrow', async function()
{
log('Running test ' + this.test.title);
const { client } = this.app;
await client.waitUntilWindowLoaded();
await client.waitUntilWindowLoaded(10000);

// Switch to Day View
const switchViewBtn = await client.$('#switch-view');
await switchViewBtn.click();

// Check that changed to current day
let headerDate = await client.$('#header-date');
let headerDateText = await headerDate.getText();
const today = new Date();
assert.equal(headerDateText, `${weekDay[today.getDay()]}, ${months[today.getMonth()]} ${today.getDate()}, ${today.getFullYear()}`);

// Check that prev day go back to yesterday
const prevDay = await client.$('#prev-day');
prevDay.click();
const headerDate = await client.$('#header-date');
const headerDateText = await headerDate.getText();
const today = new Date();
headerDate = await client.$('#header-date');
headerDateText = await headerDate.getText();
const previousDayDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1);
assert.equal(headerDateText, `${weekDay[previousDayDate.getDay()]}, ${months[previousDayDate.getMonth()]} ${previousDayDate.getDate()}, ${previousDayDate.getFullYear()}`);
});

it('Calendar change to next Day', async function()
{
const { client } = this.app;
await client.waitUntilWindowLoaded();
const switchViewBtn = await client.$('#switch-view');
await switchViewBtn.click();
// Back to current day
const currentDay = await client.$('#current-day');
currentDay.click();
headerDate = await client.$('#header-date');
headerDateText = await headerDate.getText();
assert.equal(headerDateText, `${weekDay[today.getDay()]}, ${months[today.getMonth()]} ${today.getDate()}, ${today.getFullYear()}`);

// Check that next day go back to tomorrow
const nextDay = await client.$('#next-day');
nextDay.click();
const headerDate = await client.$('#header-date');
const headerDateText = await headerDate.getText();
const today = new Date();
headerDate = await client.$('#header-date');
headerDateText = await headerDate.getText();
const nextDayDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1);
assert.equal(headerDateText, `${weekDay[nextDayDate.getDay()]}, ${months[nextDayDate.getMonth()]} ${nextDayDate.getDate()}, ${nextDayDate.getFullYear()}`);

log('Running test - Done');
});
});

0 comments on commit 440b192

Please sign in to comment.