Skip to content

Commit

Permalink
Convert badge-setter and html-generator test files to JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
1 parent 7178011 commit fe7546a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
/**
* @typedef {import('../static/types').PullRequestRecord} PullRequestRecord
*/

import BadgeSetter from './badge-setter.js';
import { PullRequestRecord } from '../static/types';
import { pullRequestRecordFactory } from '../../../__test__/mocks/factories';
import { pullRequestRecordFactory } from '../../../__test__/mocks/factories.js';

global.chrome = {
action: {
setBadgeText: jest.fn(),
setBadgeBackgroundColor: jest.fn(),
},
} as any;
};

describe('BadgeSetter', () => {
describe('update', () => {
let record: PullRequestRecord;
/** @type {PullRequestRecord} */
let record;
let counter = {
'reviewRequested': true,
'teamReviewRequested': true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/**
* @jest-environment jsdom
* @typedef {import('../static/types').CounterConfig} CounterConfig
* @typedef {import('../static/types').PullRequestRecord} PullRequestRecord
*/

import HTMLGenerator from './html-generator';
import { CounterConfig, PullRequestRecord } from '../static/types';
import { pullRequestRecordFactory } from '../../../__test__/mocks/factories';
import HTMLGenerator from './html-generator.js';
import { pullRequestRecordFactory } from '../../../__test__/mocks/factories.js';

describe('HTMLGenerator', () => {
const htmlGenerator = HTMLGenerator();
Expand All @@ -18,9 +19,12 @@ describe('HTMLGenerator', () => {
};

describe('#generate', () => {
let record: PullRequestRecord;
let counter: CounterConfig;
let result: HTMLDivElement;
/** @type {PullRequestRecord} */
let record;
/** @type {CounterConfig} */
let counter;
/** @type {HTMLDivElement} */
let result;

beforeEach(() => {
result = htmlGenerator.generate(record, counter);
Expand All @@ -44,11 +48,11 @@ describe('HTMLGenerator', () => {
});

it('has the correct <p> as its first child', () => {
expect(result.innerHTML).toContain('I must review');
expect(result.childNodes[0].innerHTML).toEqual('I must review');
});

it('has the correct <div> as its second child', () => {
expect((result.childNodes[1] as HTMLDivElement).className).toEqual('group-container');
expect(result.childNodes[1].className).toEqual('group-container');
});

describe('second child', () => {
Expand All @@ -58,16 +62,19 @@ describe('HTMLGenerator', () => {

describe('<div>', () => {
it('has the correct link', () => {
const a = result.querySelector('.pr-link') as HTMLAnchorElement;
const a = result.childNodes[1].childNodes[0].childNodes[0];

expect(a.href).toEqual('https://github.com/renuo/github-pull-request-counter/pull/1');
expect(a.target).toEqual('_blank');
expect(a.innerHTML).toEqual('PullRequest-Title');
});

it('has the correct subdescription', () => {
const p = result.querySelector('.repo-link') as HTMLParagraphElement;
expect(p.innerHTML).toContain('renuo/github-pull-request-counter');
const p = result.childNodes[1].childNodes[0].childNodes[1];
const age = Math.floor(record.reviewRequested[0].ageInDays);
const id = record.reviewRequested[0].id;

expect(p.innerHTML).toEqual(`renuo/github-pull-request-counter<b> #${id}</b> (${age} days ago)`);
});
});
});
Expand All @@ -86,11 +93,11 @@ describe('HTMLGenerator', () => {
});

it('the title has an additional class', () => {
expect((result.childNodes[0] as HTMLParagraphElement).classList.value).toEqual('title less-relevant-group');
expect(result.childNodes[0].classList.value).toEqual('title less-relevant-group');
});

it('the group container has an additional class', () => {
expect((result.childNodes[1] as HTMLDivElement).classList.value).toEqual('group-container less-relevant-group');
expect(result.childNodes[1].classList.value).toEqual('group-container less-relevant-group');
});
});
});
Expand Down

0 comments on commit fe7546a

Please sign in to comment.