forked from ng-bootstrap/ng-bootstrap
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: introduce e2e tests for the demo site (ng-bootstrap#3362)
- Loading branch information
1 parent
b16a0ca
commit cce4d80
Showing
6 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Protractor configuration file, see link for more information | ||
// https://github.com/angular/protractor/blob/master/lib/config.ts | ||
|
||
const { SpecReporter } = require('jasmine-spec-reporter'); | ||
|
||
const chromeArgs = process.env.TRAVIS ? [ | ||
'--headless', | ||
'--no-sandbox', | ||
'--window-size=1280x800' | ||
] : []; | ||
|
||
const jasmineNodeOpts = { | ||
showColors: true, | ||
defaultTimeoutInterval: 30000 | ||
}; | ||
|
||
if (!process.env.TRAVIS) { | ||
jasmineNodeOpts.print = function() {}; | ||
} | ||
|
||
exports.config = { | ||
allScriptsTimeout: 11000, | ||
specs: [ | ||
'./src/**/*.e2e-spec.ts' | ||
], | ||
capabilities: { | ||
browserName: 'chrome', | ||
chromeOptions: { | ||
args: chromeArgs | ||
} | ||
}, | ||
directConnect: true, | ||
baseUrl: 'http://localhost:4200/', | ||
framework: 'jasmine', | ||
jasmineNodeOpts, | ||
async onPrepare() { | ||
require('ts-node').register({ | ||
project: require('path').join(__dirname, './tsconfig.spec.json') | ||
}); | ||
|
||
if (!process.env.TRAVIS) { | ||
jasmine.getEnv().addReporter(new SpecReporter({spec: {displayStacktrace: true}})); | ||
} | ||
|
||
// Require because some demo pages have pending process and the tests fail with timeout | ||
// For example: autoclose alert in the alert page component | ||
browser.waitForAngularEnabled(false); | ||
|
||
await browser.get(`/`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { browser, $ } from 'protractor'; | ||
import { getLinkElement, getComponentTabsLinks, getCodeToggleElement, getCodeElements } from '../tools.po'; | ||
|
||
|
||
|
||
describe(`Components`, () => { | ||
|
||
beforeAll(async() => { | ||
await getLinkElement(`components`).click(); | ||
}); | ||
|
||
const components = [ | ||
'accordion', 'alert', 'buttons', 'carousel', 'collapse', 'datepicker', 'dropdown', | ||
'modal', 'pagination', 'popover', 'progressbar', 'rating', 'table', | ||
'tabset', 'timepicker', 'toast', 'tooltip', 'typeahead' | ||
]; | ||
components.forEach((component) => { | ||
describe(`${component} page`, () => { | ||
|
||
|
||
beforeAll(async() => { | ||
await getLinkElement(`components/${component}`).click(); | ||
}); | ||
|
||
afterAll(async () => { | ||
const browserLog = await browser.manage().logs().get('browser'); | ||
if (browserLog.length > 0) { | ||
console.error(browserLog); | ||
fail(`Unexpected console messages found`); | ||
} | ||
}); | ||
|
||
it(`should display the tabs`, async () => { | ||
const links = getComponentTabsLinks(component); | ||
const nbTabs = await links.count(); | ||
for (let i = 0; i < nbTabs; i++) { | ||
await links.get(i).click(); | ||
} | ||
}); | ||
|
||
it(`should display code samples`, async () => { | ||
await getLinkElement(`components/${component}/examples`).click(); | ||
|
||
const initialCodeElements = await getCodeElements().count(); | ||
await getCodeToggleElement().click(); | ||
expect(await getCodeElements().count()).toBe(initialCodeElements + 1); | ||
await getCodeToggleElement().click(); | ||
expect(await getCodeElements().count()).toBe(initialCodeElements); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { $, $$ } from 'protractor'; | ||
|
||
export const getLinkElement = (link) => { | ||
return $(`a[href="#/${link}"]`); | ||
}; | ||
|
||
export const getComponentTabsLinks = (component) => { | ||
return $('header.title').$$(`a.nav-link[href^="#/components/${component}"]`); | ||
}; | ||
|
||
export const getCodeToggleElement = () => { | ||
return $$(`button.toggle-code`).get(0); | ||
}; | ||
|
||
export const getCodeElements = () => { | ||
return $$(`code.language-html`); | ||
}; | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../out-tsc/app", | ||
"module": "commonjs", | ||
"types": [ | ||
"jasmine", | ||
"jasminewd2", | ||
"node" | ||
] | ||
}, | ||
"include": [ | ||
"**/*.e2e-spec.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters