redoc/tests/e2e/redoc.e2e.js

139 lines
4.6 KiB
JavaScript
Raw Permalink Normal View History

2016-01-15 23:34:28 +03:00
'use strict';
const verifyNoBrowserErrors = require('./helpers').verifyNoBrowserErrors;
const scrollToEl = require('./helpers').scrollToEl;
2016-01-17 14:51:21 +03:00
const fixFFTest = require('./helpers').fixFFTest;
const eachNth = require('./helpers').eachNth;
const getInnerHtml = require('./helpers').getInnerHtml;
2016-01-15 23:34:28 +03:00
const URL = 'index.html';
2016-10-31 21:15:56 +03:00
function waitForInit() {
const EC = protractor.ExpectedConditions;
const $apiInfo = $('api-info');
const $errorMessage = $('.redoc-error');
2016-10-31 21:15:56 +03:00
browser.wait(EC.or(EC.visibilityOf($apiInfo), EC.visibilityOf($errorMessage)), 60000);
}
2016-01-15 23:34:28 +03:00
function basicTests(swaggerUrl, title) {
describe(`Basic suite for ${title}`, () => {
let specUrl = URL;
if (swaggerUrl) {
specUrl += `?url=${encodeURIComponent(swaggerUrl)}`;
}
beforeEach(done => {
2016-01-17 14:51:21 +03:00
browser.get(specUrl);
2016-10-31 21:15:56 +03:00
waitForInit();
2016-01-17 14:51:21 +03:00
fixFFTest(done);
});
2016-01-15 23:34:28 +03:00
afterEach(() => {
verifyNoBrowserErrors();
});
it('should init redoc without errors', done => {
const $redoc = $('redoc');
2016-01-15 23:34:28 +03:00
expect($redoc.isPresent()).toBe(true);
2016-10-31 11:15:15 +03:00
setTimeout(() => {
const $operations = $$('operation');
2017-03-30 15:17:08 +03:00
expect($operations.count()).toBeGreaterThan(0);
2016-10-31 11:15:15 +03:00
done();
});
2016-01-15 23:34:28 +03:00
});
});
}
2016-01-16 00:22:11 +03:00
basicTests(null, 'Extended Petstore');
2016-01-15 23:34:28 +03:00
describe('Scroll sync', () => {
const specUrl = URL;
beforeEach(done => {
2016-01-17 14:51:21 +03:00
browser.get(specUrl);
2016-10-31 21:15:56 +03:00
waitForInit();
2016-01-17 14:51:21 +03:00
fixFFTest(done);
});
2016-05-18 17:44:58 +03:00
it('should update active menu entries on page scroll forwards', () => {
2016-07-26 12:03:15 +03:00
scrollToEl('[section="tag/store"]').then(() => {
expect(getInnerHtml('.menu-item.menu-item-depth-1.active > .menu-item-header')).toContain(
'store',
);
expect(getInnerHtml('.selected-tag')).toContain('store');
2016-01-15 23:34:28 +03:00
});
});
2016-05-18 17:44:58 +03:00
it('should update active menu entries on page scroll backwards', () => {
scrollToEl('[operation-id="getPetById"]').then(() => {
expect(getInnerHtml('.menu-item.menu-item-depth-1.active .menu-item-header')).toContain(
'pet',
);
expect(getInnerHtml('.selected-tag')).toContain('pet');
expect(getInnerHtml('.menu-item.menu-item-depth-2.active .menu-item-header')).toContain(
'Find pet by ID',
);
expect(getInnerHtml('.selected-endpoint')).toContain('Find pet by ID');
2016-05-18 17:44:58 +03:00
});
});
});
describe('Language tabs sync', () => {
const specUrl = URL;
2016-05-18 17:44:58 +03:00
beforeEach(done => {
2016-05-18 17:44:58 +03:00
browser.get(specUrl);
2016-10-31 21:15:56 +03:00
waitForInit();
2016-05-18 17:44:58 +03:00
fixFFTest(done);
});
// skip as it fails for no reason on IE on sauce-labs
// TODO: fixme
xit('should sync language tabs', () => {
const $item = $$('[operation-id="addPet"] tabs > ul > li').last();
2016-05-18 17:44:58 +03:00
// check if correct item
expect($item.getText()).toContain('PHP');
const EC = protractor.ExpectedConditions;
2016-12-25 20:15:24 +03:00
browser.wait(EC.elementToBeClickable($item), 5000);
2016-05-18 17:44:58 +03:00
$item.click().then(() => {
expect($('[operation-id="updatePet"] li.active').getText()).toContain('PHP');
});
});
2016-01-15 23:34:28 +03:00
});
if (process.env.JOB === 'e2e-guru') {
describe('APIs.guru specs test', () => {
// global.apisGuruList was loaded in onPrepare method of protractor config
let apisGuruList = global.apisGuruList;
// Remove certain APIs that are known to cause problems
delete apisGuruList['motaword.com']; // invalid (see https://github.com/BigstickCarpet/swagger-parser/issues/26)
delete apisGuruList['learnifier.com']; // allof object and no type
delete apisGuruList['googleapis.com:mirror']; // bad urls in images
delete apisGuruList['googleapis.com:discovery']; // non-string references
delete apisGuruList['clarify.io']; // non-string references
2019-06-04 15:47:22 +03:00
//delete apisGuruList['pushpay.com']; // https://github.com/Redocly/redoc/issues/30
2016-06-29 22:29:05 +03:00
delete apisGuruList['bbci.co.uk']; // too big
2016-11-01 18:23:51 +03:00
delete apisGuruList['bbc.com']; // too big
delete apisGuruList['osisoft.com']; // too big
delete apisGuruList['magento.com']; // too big
// run quick version of e2e test on all builds except releases
if (process.env.TRAVIS && !process.env.TRAVIS_TAG) {
console.log('Running on a short APIs guru list');
apisGuruList = eachNth(apisGuruList, 20);
} else {
console.log('Running on full APIs guru list');
}
for (const apiName of Object.keys(apisGuruList)) {
const apiInfo = apisGuruList[apiName].versions[apisGuruList[apiName].preferred];
let url = apiInfo.swaggerUrl;
// temporary hack due to this issue: https://github.com/substack/https-browserify/issues/6
url = url.replace('https://', 'http://');
url = url.replace('apis-guru.github.io/', 'apis-guru.github.io:80/');
basicTests(url, `${apiName}:${apiInfo.info.version}\n${url}`);
}
});
}