Skip to content

Commit e0357cb

Browse files
authored
Merge pull request #10 from oslabs-beta/brooke/featuretests
added collectionTest.js
2 parents 839f291 + d665203 commit e0357cb

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

test/subSuites/collectionTest.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/* this test file checks the app's ability to run tests on a collection of requests (via the workspace "Send Collection" button),
2+
as the subSuite and integration tests run tests on a single API call, tests are required into the testSuite.js file and called there */
3+
4+
/* the Send Collection functionality currently works for http requests if all requests in the collection are http, it does
5+
not work for graphQL requests */
6+
7+
const { _electron: electron } = require('playwright');
8+
const pwTest = require('@playwright/test');
9+
const chai = require('chai');
10+
const expect = chai.expect;
11+
const chaiHttp = require('chai-http');
12+
chai.use(chaiHttp);
13+
const path = require('path');
14+
const fs = require('fs');
15+
const {
16+
isButtonDisabled,
17+
fillRestRequest,
18+
addAndSend,
19+
} = require('./testHelper');
20+
const { Console } = require('console');
21+
22+
let electronApp,
23+
page,
24+
num = 0;
25+
26+
module.exports = () => {
27+
28+
describe('collectionTests', () => {
29+
30+
/* these before and after functions run after each test suite, consider moving into the testSuite.js main file
31+
to limit the number of electron apps that have to launch to run the test suite */
32+
before(async () => {
33+
electronApp = await electron.launch({
34+
args: ['main.js']
35+
});
36+
});
37+
38+
after(async () => {
39+
await page.locator('button >> text=Clear Workspace').click();
40+
await electronApp.close();
41+
});
42+
43+
afterEach(async function () {
44+
if (this.currentTest.state === 'failed') {
45+
console.log(`Screenshotting failed test window`);
46+
const imageBuffer = await page.screenshot();
47+
fs.writeFileSync(
48+
path.resolve(
49+
__dirname + '/../failedTests',
50+
`FAILED_${this.currentTest.title}.png`
51+
),
52+
imageBuffer
53+
);
54+
}
55+
});
56+
57+
/* The app takes a while to launch, and without these rendering checks within each test file the tests can get flakey because of long
58+
load times so these are here to ensure the app launches as expect before continuing, all test files have these tests in them
59+
consider refactoring by moving them into the testSuite.js main file */
60+
describe('Window rendering', () => {
61+
it('Electron app should launch', async () => {
62+
expect(electronApp).to.be.ok;
63+
});
64+
65+
it('Electron app should be a visible window', async () => {
66+
const window = await electronApp.firstWindow();
67+
pwTest.expect(window).toBeVisible();
68+
});
69+
70+
it('App should only have 1 window (i.e. confirm devTools is not open)', async () => {
71+
expect(electronApp.windows().length).to.equal(1);
72+
});
73+
});
74+
75+
/* test case 1: browser controller should add two http tests to the workspace, select "Send Collection", and receive valid responses for both tests
76+
this test inconsistently works in isolation and fails when incorporated into the test suite, this is likely caused by an issue with the async functionality
77+
I've commented out the collectionTest suite in testSuite.js file until this issue is resolved */
78+
describe('http collection tests', () => {
79+
before(async () => {
80+
page = electronApp.windows()[0]; // In case there is more than one window
81+
await page.waitForLoadState(`domcontentloaded`);
82+
});
83+
84+
it('should GET information from two public APIs', async () => {
85+
const url1 = 'https://swapi.dev/api/people/1';
86+
const url2 = 'https://swapi.dev/api/people/2';
87+
const method = 'GET';
88+
89+
try {
90+
await fillRestRequest(page, url1, method);
91+
await page.locator('button >> text=Add to Workspace').click();
92+
await fillRestRequest(page, url2, method);
93+
await page.locator('button >> text=Add to Workspace').click();
94+
await page.locator('button >> text=Send Collection').click();
95+
96+
// check that first request returned a 200 status and correct character information ("name": "Luke Skywalker")
97+
await page.waitForSelector('#view-button-0');
98+
await page.locator('#view-button-0').click();
99+
let statusCode = await page.locator('.status-tag').innerText();
100+
let events = await page.locator('#events-display >> .cm-content').innerText();
101+
expect(statusCode).to.equal('200');
102+
expect(events.slice(1, 100)).to.include('Luke Skywalker');
103+
104+
// check that second request returned a 200 status and correct character information ("name": "C-3PO")
105+
await page.waitForSelector('#view-button-1');
106+
await page.locator('#view-button-1').click();
107+
statusCode = await page.locator('.status-tag').innerText();
108+
events = await page.locator('#events-display >> .cm-content').innerText();
109+
expect(statusCode).to.equal('200');
110+
expect(events.slice(1, 100)).to.include('C-3PO');
111+
}
112+
113+
catch (err) {
114+
console.error(err);
115+
}
116+
});
117+
});
118+
});
119+
}
120+
121+
/* test case 2: browser controller should add two graphQL tests to the workspace, select "Send Collection", and receive valid responses for both tests */
122+
/* test case 3: browser controller should add two grpc tests to the workspace, select "Send Collection", and receive valid responses for both tests */
123+
/* test case 4: browser controller should add two websocket tests to the workspace, select "Send Collection", and receive valid responses for both tests */
124+
/* test case 5: browser controller should add 4 tests to the workspace of each API type, select "Send Collection", and receive valid responses for all tests */

test/subSuites/httpTest.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ module.exports = () => {
103103
console.error(err);
104104
}
105105
});
106+
107+
106108
});
107109

108110
describe('httpTest Server', () => {

test/testSuite.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
*/
2626

2727
// Import various tests
28+
2829
const appOpensTests = require('./subSuites/appOpens');
2930
const reqInputTests = require('./subSuites/reqInputTests');
31+
const collectionTest = require('./subSuites/collectionTest');
3032
const httpTest = require('./subSuites/httpTest');
3133
const websocketTest = require('./subSuites/websocketTest');
3234
const grpcTest = require('./subSuites/grpcTest');
@@ -66,6 +68,7 @@ describe('Protocol selection and usage', function () {
6668
grpcTest();
6769
webRTCTest();
6870
openAPITest();
71+
// collectionTest(); // new test suite to check Send Collection functionality, see test file for more info
6972
}).timeout(20000);
7073

7174
describe('Request/response testing functionality', function () {

0 commit comments

Comments
 (0)