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

Re-added testing files #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
65 changes: 65 additions & 0 deletions __test__/e2e/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const puppeteer = require('puppeteer');
require('dotenv').config();

describe('index.html', () => {
const EXTENSION_PATH = process.env.E2E_EXTENSION_PATH;
const EXTENSION_ID = process.env.E2E_EXTENSION_ID;

let browser;
let githubUrl = "https://github.com/JStuve/git-kit/issues"

beforeEach(async () => {

browser = await puppeteer.launch({
headless: false,
args: [
`--disable-extensions-except=${EXTENSION_PATH}`,
`--load-extension=${EXTENSION_PATH}`,

]
});
});

afterEach(async () => {
await browser.close();

browser = undefined;
});

test('popup contains the correct text for non-github pages', async () => {
const page = await browser.newPage();

await page.goto(`chrome-extension://${EXTENSION_ID}/index.html`);

const h3InnerHTML = await page.$eval('h3', (h3) => h3.innerHTML);

await expect(h3InnerHTML).toMatch("This Github tab currently has no features.");


const buttonInnerHTML = await page.$eval('button', (button) => button.innerHTML);

await expect(buttonInnerHTML).toMatch("Request feature");

});

// requires that the github url has at least 1 issue
test("removes an element from a page when visible-container is clicked.", async () => {
const page = await browser.newPage();

await page.goto(`${githubUrl}`,{waitUntil: 'networkidle2'});

const divIds = await page.$$eval('div', divs => divs.map(div => div.id));

let filteredIds = await divIds.filter(id => id.startsWith('issue'));

const issueId = await filteredIds[0].replace('issue_', '')

await page.hover(`#issue_${issueId}`);

const svgElement = await page.$(`#visible-container-${issueId}`);

await svgElement.click();

await expect(page.waitForSelector(`#issue_${issueId}`, { hidden: true })).resolves.not.toThrow();
});
})
18 changes: 18 additions & 0 deletions __test__/unit/popup.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from '../../popup';
import { UnitTestHelper } from './unit-test-helper';


describe('App', () => {

UnitTestHelper.setupBeforeAndAfter();

test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/This Github tab currently has no features./i);
expect(linkElement).toBeInTheDocument();
});

})

13 changes: 13 additions & 0 deletions __test__/unit/unit-test-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as chrome from 'sinon-chrome';

export class UnitTestHelper {

static setupBeforeAndAfter() {
beforeAll(() => {
global.chrome = chrome as any;
});
afterAll(() => {
chrome.flush();
});
}
}
Loading