This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
/
Copy pathapp.scenario.js
170 lines (127 loc) · 6.3 KB
/
app.scenario.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
'use strict';
var webdriver = require('selenium-webdriver');
describe('docs.angularjs.org', function() {
beforeEach(function() {
// read and clear logs from previous tests
browser.manage().logs().get('browser');
});
afterEach(function() {
// verify that there were no console errors in the browser
browser.manage().logs().get('browser').then(function(browserLog) {
var filteredLog = browserLog.filter(function(logEntry) {
return logEntry.level.value > webdriver.logging.Level.WARNING.value;
});
expect(filteredLog.length).toEqual(0);
if (filteredLog.length) {
console.log('browser console errors: ' + require('util').inspect(filteredLog));
}
});
browser.ignoreSynchronization = false;
browser.clearMockModules();
});
describe('App', function() {
// it('should filter the module list when searching', function () {
// browser.get();
// browser.waitForAngular();
// var search = element(by.model('q'));
// search.clear();
// search.sendKeys('ngBind');
// var firstModule = element(by.css('.search-results a'));
// expect(firstModule.getText()).toEqual('ngBind');
// });
it('should change the page content when clicking a link to a service', function() {
browser.get('build/docs/index-production.html');
var ngBindLink = element(by.css('.definition-table td a[href="api/ng/directive/ngClick"]'));
ngBindLink.click();
var mainHeader = element(by.css('.main-body h1 '));
expect(mainHeader.getText()).toEqual('ngClick');
});
it('should include the files for the embedded examples from the same domain', function() {
browser.get('build/docs/index-production.html#!api/ng/directive/ngClick');
var origin = browser.executeScript('return document.location.origin;');
var exampleIFrame = element(by.name('example-ng-click'));
// This is technically an implementation detail, but if this changes, then there's a good
// chance the deployment process changed
expect(exampleIFrame.getAttribute('src')).toContain('examples/example-ng-click/index.html');
browser.switchTo().frame('example-ng-click');
var scriptEl = element(by.tagName('script'));
// Ensure the included file is from the same domain
expect(scriptEl.getAttribute('src')).toContain(origin);
});
it('should be resilient to trailing slashes', function() {
browser.get('build/docs/index-production.html#!/api/ng/function/angular.noop/');
var mainHeader = element(by.css('.main-body h1 '));
expect(mainHeader.getText()).toEqual('angular.noop');
});
it('should be resilient to trailing "index"', function() {
browser.get('build/docs/index-production.html#!/api/ng/function/angular.noop/index');
var mainHeader = element(by.css('.main-body h1 '));
expect(mainHeader.getText()).toEqual('angular.noop');
});
it('should be resilient to trailing "index/"', function() {
browser.get('build/docs/index-production.html#!/api/ng/function/angular.noop/index/');
var mainHeader = element(by.css('.main-body h1 '));
expect(mainHeader.getText()).toEqual('angular.noop');
});
it('should display formatted error messages on error doc pages', function() {
browser.get('build/docs/index-production.html#!error/ng/areq?p0=Missing&p1=not%20a%20function,%20got%20undefined');
expect(element(by.css('.minerr-errmsg')).getText()).toEqual('Argument \'Missing\' is not a function, got undefined');
});
it('should display an error if the page does not exist', function() {
browser.get('build/docs/index-production.html#!/api/does/not/exist');
var mainHeader = element(by.css('.main-body h1 '));
expect(mainHeader.getText()).toEqual('Oops!');
});
it('should set "noindex" if the page does not exist', function() {
browser.get('build/docs/index-production.html#!/api/does/not/exist');
var robots = element(by.css('meta[name="robots"][content="noindex"]'));
var googleBot = element(by.css('meta[name="googlebot"][content="noindex"]'));
expect(robots.isPresent()).toBe(true);
expect(googleBot.isPresent()).toBe(true);
});
it('should remove "noindex" if the page exists', function() {
browser.get('build/docs/index-production.html#!/api');
var robots = element(by.css('meta[name="robots"][content="noindex"]'));
var googleBot = element(by.css('meta[name="googlebot"][content="noindex"]'));
expect(robots.isPresent()).toBe(false);
expect(googleBot.isPresent()).toBe(false);
});
describe('template request error', function() {
beforeEach(function() {
browser.addMockModule('httpMocker', function() {
angular.module('httpMocker', ['ngMock'])
.run(['$httpBackend', function($httpBackend) {
$httpBackend.whenGET('localhost:8000/build/docs/partials/api.html').respond(500, '');
}]);
});
});
it('should set "noindex" for robots if the request fails', function() {
// index-test includes ngMock
browser.get('build/docs/index-test.html#!/api');
var robots = element(by.css('meta[name="robots"][content="noindex"]'));
var googleBot = element(by.css('meta[name="googlebot"][content="noindex"]'));
expect(robots.isPresent()).toBe(true);
expect(googleBot.isPresent()).toBe(true);
});
});
describe('page bootstrap error', function() {
beforeEach(function() {
browser.addMockModule('httpMocker', function() {
// Require a module that does not exist to break the bootstrapping
angular.module('httpMocker', ['doesNotExist']);
});
});
it('should have "noindex" for robots if bootstrapping fails', function() {
browser.get('build/docs/index.html#!/api').catch(function() {
// get() will fail on AngularJS bootstrap, but if we continue here, protractor
// will assume the app is ready
browser.ignoreSynchronization = true;
var robots = element(by.css('meta[name="robots"][content="noindex"]'));
var googleBot = element(by.css('meta[name="googlebot"][content="noindex"]'));
expect(robots.isPresent()).toBe(true);
expect(googleBot.isPresent()).toBe(true);
});
});
});
});
});