Matteo Scandolo | fb46ae6 | 2017-08-08 09:10:50 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | d3b57a1 | 2017-04-20 14:33:04 -0700 | [diff] [blame] | 19 | const user = require('../test_helpers/user'); |
| 20 | const page = require('./crud.po'); |
| 21 | const config = require('../test_helpers/config'); |
Matteo Scandolo | f4f6955 | 2017-08-24 17:26:25 -0700 | [diff] [blame] | 22 | const backend = require('../test_helpers/backend'); |
| 23 | |
| 24 | let testNode; |
Matteo Scandolo | d3b57a1 | 2017-04-20 14:33:04 -0700 | [diff] [blame] | 25 | |
| 26 | describe('XOS CRUD Page', function() { |
| 27 | |
| 28 | beforeEach((done) => { |
Matteo Scandolo | f4f6955 | 2017-08-24 17:26:25 -0700 | [diff] [blame] | 29 | const nodesUrl = `/xosapi/v1/core/nodes`; |
| 30 | |
| 31 | const _testNode = { |
| 32 | name: 'test-p', |
| 33 | site_deployment_id: 1 |
| 34 | } |
| 35 | |
| 36 | backend.deleteAllModels(nodesUrl) |
| 37 | .then(() => { |
| 38 | return backend.createModel(nodesUrl, _testNode) |
| 39 | }) |
| 40 | .then((node) => { |
| 41 | testNode = node; |
| 42 | done(); |
| 43 | }) |
| 44 | .catch(e => { |
| 45 | done(e); |
| 46 | }) |
| 47 | }); |
| 48 | |
| 49 | beforeEach((done) => { |
Matteo Scandolo | d3b57a1 | 2017-04-20 14:33:04 -0700 | [diff] [blame] | 50 | user.login() |
| 51 | .then(() => { |
| 52 | done(); |
| 53 | }); |
| 54 | }); |
| 55 | |
| 56 | describe('list view', () => { |
| 57 | beforeEach(() => { |
| 58 | browser.get(`${config.url}/core/nodes/`); |
| 59 | }); |
| 60 | it('should have a table', () => { |
Matteo Scandolo | f4f6955 | 2017-08-24 17:26:25 -0700 | [diff] [blame] | 61 | expect(page.tableRows.count()).toBe(1); |
| 62 | expect(page.tableColumn.count()).toBe(6); |
| 63 | expect(page.deleteBtn.count()).toBe(1); |
| 64 | expect(page.detailBtn.count()).toBe(1); |
Matteo Scandolo | d3b57a1 | 2017-04-20 14:33:04 -0700 | [diff] [blame] | 65 | }); |
| 66 | |
| 67 | it('should have an add button', () => { |
| 68 | expect(page.addBtn.isDisplayed()).toBeTruthy(); |
| 69 | page.addBtn.click(); |
| 70 | expect(browser.getCurrentUrl()).toBe(`${config.url}/core/nodes/add`); |
| 71 | }); |
| 72 | }); |
| 73 | |
| 74 | describe('details view', () => { |
| 75 | |
| 76 | describe('for an existing model', () => { |
| 77 | beforeEach(() => { |
Matteo Scandolo | f4f6955 | 2017-08-24 17:26:25 -0700 | [diff] [blame] | 78 | browser.get(`${config.url}/core/nodes/${testNode.id}`); |
Matteo Scandolo | d3b57a1 | 2017-04-20 14:33:04 -0700 | [diff] [blame] | 79 | }); |
Matteo Scandolo | f4f6955 | 2017-08-24 17:26:25 -0700 | [diff] [blame] | 80 | it('should load the correct model', () => { |
| 81 | expect(page.formInputs.count()).toBe(2); |
| 82 | expect(page.nameInput.getAttribute('value')).toBe(testNode.name); |
Matteo Scandolo | d3b57a1 | 2017-04-20 14:33:04 -0700 | [diff] [blame] | 83 | expect(page.formBtn.isPresent()).toBeTruthy(); |
| 84 | }); |
| 85 | |
| 86 | it('should save the model', () => { |
| 87 | page.nameField.clear().sendKeys('test'); |
| 88 | page.formBtn.click(); |
| 89 | expect(page.nameField.getAttribute('value')).toBe('test'); |
| 90 | expect(page.successFeedback.isDisplayed()).toBeTruthy(); |
| 91 | browser.sleep(3000) |
| 92 | }); |
| 93 | }) |
| 94 | }); |
| 95 | }); |