write some tests

This commit is contained in:
RVKen
2017-06-20 01:53:43 -07:00
parent c553f4587e
commit d53a139e9c
6 changed files with 113 additions and 33 deletions

View File

@@ -56,6 +56,13 @@ If you'd like to make modifications to the codebase, run the dev server with: `n
If you'd like to rebuild the `/dist` folder with your codebase changes, run `npm run build`. If you'd like to rebuild the `/dist` folder with your codebase changes, run `npm run build`.
##### Integrate Tests
You will need JDK of version 7 or higher as instructed here
http://nightwatchjs.org/gettingstarted#selenium-server-setup
##### Browser support ##### Browser support
Swagger UI works in the latest versions of Chrome, Safari, Firefox, Edge and IE11. Swagger UI works in the latest versions of Chrome, Safari, Firefox, Edge and IE11.

View File

@@ -33,7 +33,8 @@
"test-in-node": "npm run lint-errors && npm run just-test-in-node", "test-in-node": "npm run lint-errors && npm run just-test-in-node",
"just-test": "karma start --config karma.conf.js", "just-test": "karma start --config karma.conf.js",
"just-test-in-node": "mocha --recursive --compilers js:babel-core/register test/core test/components test/bugs test/swagger-ui-dist-package", "just-test-in-node": "mocha --recursive --compilers js:babel-core/register test/core test/components test/bugs test/swagger-ui-dist-package",
"e2e": "nightwatch test/e2e/scenarios --config test/e2e/nightwatch.json --verbose" "e2e": "nightwatch test/e2e/scenarios --config test/e2e/nightwatch.json --verbose",
"e2e-initial-render": "nightwatch test/e2e/scenarios --config test/e2e/nightwatch.json --group initial-render"
}, },
"dependencies": { "dependencies": {
"babel-polyfill": "^6.23.0", "babel-polyfill": "^6.23.0",

View File

@@ -4,7 +4,7 @@
"live_output": true, "live_output": true,
"custom_commands_path" : "", "custom_commands_path" : "",
"custom_assertions_path" : "", "custom_assertions_path" : "",
"page_objects_path" : "", "page_objects_path" : "test/e2e/pages",
"globals_path" : "", "globals_path" : "",
"test_workers" : { "test_workers" : {
"enabled" : true, "enabled" : true,

26
test/e2e/pages/main.js Normal file
View File

@@ -0,0 +1,26 @@
module.exports = {
sections: {
topbar: {
selector: ".topbar",
elements: {
inputBox: {
selector: "input"
},
btnExplore: {
selector: "button"
}
}
},
informationContainer: {
selector: ".information-container",
elements: {
title: {
selector: ".title"
},
version: {
selector: ".version"
}
}
}
}
}

View File

@@ -0,0 +1,77 @@
describe("initial render", function () {
let mainPage
describe("for topbar", function () {
let topbar
before(function (client, done) {
done()
})
after(function (client, done) {
client.end(function () {
done()
})
})
afterEach(function (client, done) {
done()
})
beforeEach(function (client, done) {
mainPage = client
.url("localhost:3200")
.page.main()
topbar = mainPage.section.topbar
done()
})
it("renders section", function (client) {
mainPage.expect.section("@topbar").to.be.visible
client.end()
})
it("renders input box", function (client) {
topbar.expect.element("@inputBox").to.be.visible
client.end()
})
it("renders explore button", function (client) {
topbar.expect.element("@btnExplore").to.be.visible
client.end()
})
})
describe("for information", function () {
let informationContainer
beforeEach(function (client, done) {
mainPage = client
.url("localhost:3200")
.page.main()
informationContainer = mainPage.section.informationContainer
done()
})
it("renders section", function (client) {
mainPage.expect.section("@informationContainer").to.be.visible.before(5000)
client.end()
})
it("renders title", function (client) {
// informationContainer.waitForElementVisible("@title", 5000, function() {
// informationContainer.expect.element("@title").to.contain.text("Swagger Petstore")
// informationContainer.expect.element("@version").to.contain.text("1.0.0")
// client.end()
// })
informationContainer.waitForElementVisible("@title", 5000)
.assert.containsText("@title", "Swagger Petstore")
.assert.containsText("@version", "1.0.0")
client.end()
})
})
})

View File

@@ -1,31 +0,0 @@
describe('Google demo test for Mocha', function () {
describe('with Nightwatch', function () {
before(function (client, done) {
done()
})
after(function (client, done) {
client.end(function () {
done()
})
})
afterEach(function (client, done) {
done()
})
beforeEach(function (client, done) {
done()
})
it('uses TDD to run the Google simple test', function (client) {
client
.url('http://google.com')
.expect.element('body').to.be.present.before(1000)
client.setValue('input[type=text]', ['nightwatch', client.Keys.ENTER])
.pause(1000)
.assert.containsText('#main', 'Night Watch')
})
})
})