Best JavaScript code snippet using playwright-internal
coding-rules-spec.js
Source:coding-rules-spec.js
...3describe('Coding Rules App', function () {4 it('should show alert when there is no available profiles for activation', 2, function (casper, test) {5 return casper6 .start(lib.buildUrl('base'), function () {7 lib.setDefaultViewport();8 lib.fmock('/api/rules/app', 'app-no-available-profiles.json');9 lib.fmock('/api/rules/search', 'search-no-available-profiles.json');10 lib.fmock('/api/rules/show', 'show-no-available-profiles.json');11 lib.smock('/api/issues/search', '{}');12 })13 .then(function () {14 casper.evaluate(function () {15 require(['apps/coding-rules/app'], function (App) {16 App.start({ el: '#content' });17 });18 });19 })20 .then(function () {21 casper.waitForSelector('.coding-rule.selected', function () {22 casper.click('.coding-rule.selected .js-rule');23 });24 })25 .then(function () {26 casper.waitForSelector('.coding-rules-detail-header');27 })28 .then(function () {29 test.assertExist('#coding-rules-quality-profile-activate');30 casper.click('#coding-rules-quality-profile-activate');31 casper.waitForSelector('.modal');32 })33 .then(function () {34 test.assertExists('.modal .alert');35 });36 });37 it('should show profile facet', 6, function (casper, test) {38 return casper39 .start(lib.buildUrl('base'), function () {40 lib.setDefaultViewport();41 lib.fmock('/api/rules/app', 'app.json');42 lib.fmock('/api/rules/search', 'search-profile-facet-qprofile-active.json', { data: { activation: true } });43 lib.fmock('/api/rules/search', 'search-profile-facet-qprofile-inactive.json',44 { data: { activation: 'false' } });45 lib.fmock('/api/rules/search', 'search-profile-facet.json');46 })47 .then(function () {48 casper.evaluate(function () {49 require(['apps/coding-rules/app'], function (App) {50 App.start({ el: '#content' });51 });52 });53 })54 .then(function () {55 casper.waitForSelector('.coding-rule');56 })57 .then(function () {58 test.assertSelectorContains('#coding-rules-total', '609');59 casper.click('[data-property="qprofile"] .js-facet-toggle');60 casper.waitForSelector('.js-facet[data-value="java-default-with-mojo-conventions-49307"]');61 })62 .then(function () {63 casper.click('.js-facet[data-value="java-default-with-mojo-conventions-49307"]');64 casper.waitForSelectorTextChange('#coding-rules-total');65 })66 .then(function () {67 test.assertSelectorContains('#coding-rules-total', '407');68 test.assertExists('.js-facet[data-value="java-default-with-mojo-conventions-49307"] .js-active.facet-toggle-active');69 casper.click('.js-facet[data-value="java-default-with-mojo-conventions-49307"] .js-inactive');70 casper.waitForSelectorTextChange('#coding-rules-total');71 })72 .then(function () {73 test.assertSelectorContains('#coding-rules-total', '408');74 test.assertExists('.js-facet[data-value="java-default-with-mojo-conventions-49307"] .js-inactive.facet-toggle-active');75 casper.click('[data-property="qprofile"] .js-facet-toggle');76 casper.waitForSelectorTextChange('#coding-rules-total');77 })78 .then(function () {79 test.assertSelectorContains('#coding-rules-total', '609');80 });81 });82 it('should show query facet', 3, function (casper, test) {83 return casper84 .start(lib.buildUrl('base'), function () {85 lib.setDefaultViewport();86 lib.fmock('/api/rules/app', 'app.json');87 lib.fmock('/api/rules/search', 'search-query.json', { data: { q: 'query' } });88 lib.fmock('/api/rules/search', 'search.json');89 })90 .then(function () {91 casper.evaluate(function () {92 require(['apps/coding-rules/app'], function (App) {93 App.start({ el: '#content' });94 });95 });96 })97 .then(function () {98 casper.waitForSelector('.coding-rule');99 })100 .then(function () {101 test.assertSelectorContains('#coding-rules-total', '609');102 casper.evaluate(function () {103 jQuery('[data-property="q"] input').val('query');104 jQuery('[data-property="q"] form').submit();105 });106 casper.waitForSelectorTextChange('#coding-rules-total');107 })108 .then(function () {109 test.assertSelectorContains('#coding-rules-total', '4');110 casper.evaluate(function () {111 jQuery('[data-property="q"] input').val('');112 jQuery('[data-property="q"] form').submit();113 });114 casper.waitForSelectorTextChange('#coding-rules-total');115 })116 .then(function () {117 test.assertSelectorContains('#coding-rules-total', '609');118 });119 });120 it('should show rule permalink', 1, function (casper, test) {121 return casper122 .start(lib.buildUrl('base'), function () {123 lib.setDefaultViewport();124 lib.fmock('/api/rules/app', 'app.json');125 lib.fmock('/api/rules/search', 'search.json');126 lib.fmock('/api/rules/show', 'show.json');127 lib.smock('/api/issues/search', '{}');128 })129 .then(function () {130 casper.evaluate(function () {131 require(['apps/coding-rules/app'], function (App) {132 App.start({ el: '#content' });133 });134 });135 })136 .then(function () {137 casper.waitForSelector('.coding-rule.selected');138 })139 .then(function () {140 casper.click('.coding-rule.selected .js-rule');141 casper.waitForSelector('.coding-rules-detail-header');142 })143 .then(function () {144 lib.capture();145 test.assertExists('a[href="/coding_rules#rule_key=squid%3AS2204"]');146 });147 });148 it('should activate profile', 5, function (casper, test) {149 return casper150 .start(lib.buildUrl('base'), function () {151 lib.setDefaultViewport();152 lib.fmock('/api/rules/app', 'app.json');153 lib.fmock('/api/rules/search', 'search.json');154 this.showMock = lib.fmock('/api/rules/show', 'show-activate-profile.json');155 lib.smock('/api/qualityprofiles/activate_rule', '{}');156 lib.smock('/api/issues/search', '{}');157 })158 .then(function () {159 casper.evaluate(function () {160 require(['apps/coding-rules/app'], function (App) {161 App.start({ el: '#content' });162 });163 });164 })165 .then(function () {166 casper.waitForSelector('.coding-rule.selected', function () {167 casper.click('.coding-rule.selected .js-rule');168 });169 })170 .then(function () {171 casper.waitForSelector('.coding-rules-detail-header');172 })173 .then(function () {174 test.assertDoesntExist('.coding-rules-detail-quality-profile-name');175 test.assertExist('#coding-rules-quality-profile-activate');176 casper.click('#coding-rules-quality-profile-activate');177 casper.waitForSelector('.modal');178 })179 .then(function () {180 lib.clearRequestMock(this.showMock);181 lib.fmock('/api/rules/show', 'show-activate-profile-with-profile.json');182 casper.click('#coding-rules-quality-profile-activation-activate');183 casper.waitForSelector('.coding-rules-detail-quality-profile-name');184 })185 .then(function () {186 test.assertExists('.coding-rules-detail-quality-profile-name');187 test.assertExists('.coding-rules-detail-quality-profile-severity');188 test.assertExists('.coding-rules-detail-quality-profile-deactivate');189 });190 });191 it('should create custom rule', 1, function (casper, test) {192 return casper193 .start(lib.buildUrl('base'), function () {194 lib.setDefaultViewport();195 lib.fmock('/api/rules/app', 'app.json');196 this.customRulesSearchMock = lib.fmock('/api/rules/search', 'search-custom-rules.json',197 { data: { template_key: 'squid:ArchitecturalConstraint' } });198 this.searchMock = lib.fmock('/api/rules/search', 'search-create-custom-rules.json');199 lib.fmock('/api/rules/show', 'show-create-custom-rules.json');200 lib.smock('/api/rules/create', '{}');201 lib.smock('/api/issues/search', '{}');202 })203 .then(function () {204 casper.evaluate(function () {205 require(['apps/coding-rules/app'], function (App) {206 App.start({ el: '#content' });207 });208 });209 })210 .then(function () {211 casper.waitForSelector('.coding-rule.selected');212 })213 .then(function () {214 casper.click('.coding-rule.selected .js-rule');215 casper.waitForSelector('#coding-rules-detail-custom-rules .coding-rules-detail-list-name');216 })217 .then(function () {218 lib.clearRequestMock(this.customRulesSearchMock);219 lib.clearRequestMock(this.searchMock);220 lib.fmock('/api/rules/search', 'search-custom-rules2.json');221 })222 .then(function () {223 test.assertElementCount('#coding-rules-detail-custom-rules .coding-rules-detail-list-name', 1);224 casper.click('.js-create-custom-rule');225 casper.evaluate(function () {226 jQuery('.modal form [name="name"]').val('test').keyup();227 jQuery('.modal form [name="markdown_description"]').val('test');228 });229 casper.click('#coding-rules-custom-rule-creation-create');230 lib.waitForElementCount('#coding-rules-detail-custom-rules .coding-rules-detail-list-name', 2);231 });232 });233 it('should reactivate custom rule', 2, function (casper, test) {234 return casper235 .start(lib.buildUrl('base'), function () {236 lib.setDefaultViewport();237 lib.fmock('/api/rules/app', 'app.json');238 this.customRulesSearchMock = lib.fmock('/api/rules/search', 'search-custom-rules.json',239 { data: { template_key: 'squid:ArchitecturalConstraint' } });240 this.searchMock = lib.fmock('/api/rules/search', 'search-create-custom-rules.json');241 lib.fmock('/api/rules/show', 'show-create-custom-rules.json');242 this.createMock = lib.fmock('/api/rules/create', 'create-create-custom-rules.json', { status: 409 });243 lib.smock('/api/issues/search', '{}');244 })245 .then(function () {246 casper.evaluate(function () {247 require(['apps/coding-rules/app'], function (App) {248 App.start({ el: '#content' });249 });250 jQuery.ajaxSetup({ dataType: 'json' });251 });252 })253 .then(function () {254 casper.waitForSelector('.coding-rule.selected', function () {255 casper.click('.coding-rule.selected .js-rule');256 });257 })258 .then(function () {259 casper.waitForSelector('.js-create-custom-rule');260 })261 .then(function () {262 casper.click('.js-create-custom-rule');263 casper.waitForSelector('.modal');264 })265 .then(function () {266 casper.evaluate(function () {267 jQuery('.modal form [name="name"]').val('My Custom Rule').keyup();268 jQuery('.modal form [name="markdown_description"]').val('My Description');269 });270 casper.click('#coding-rules-custom-rule-creation-create');271 casper.waitForSelector('.modal .alert-warning');272 })273 .then(function () {274 test.assertVisible('.modal #coding-rules-custom-rule-creation-reactivate');275 test.assertNotVisible('.modal #coding-rules-custom-rule-creation-create');276 lib.clearRequestMock(this.createMock);277 lib.clearRequestMock(this.customRulesSearchMock);278 lib.clearRequestMock(this.searchMock);279 lib.fmock('/api/rules/create', 'create-create-custom-rules.json');280 this.customRulesSearchMock = lib.fmock('/api/rules/search', 'search-custom-rules2.json',281 { data: { template_key: 'squid:ArchitecturalConstraint' } });282 this.searchMock = lib.fmock('/api/rules/search', 'search-create-custom-rules.json');283 casper.click('.modal #coding-rules-custom-rule-creation-reactivate');284 lib.waitForElementCount('#coding-rules-detail-custom-rules .coding-rules-detail-list-name', 2);285 });286 });287 it('should create manual rule', 3, function (casper, test) {288 return casper289 .start(lib.buildUrl('base'), function () {290 lib.setDefaultViewport();291 lib.fmock('/api/rules/app', 'app.json');292 lib.fmock('/api/rules/search', 'search-create-manual-rule.json');293 lib.fmock('/api/rules/create', 'show-create-manual-rule.json');294 lib.fmock('/api/rules/show', 'show-create-manual-rule.json');295 lib.smock('/api/issues/search', '{}');296 })297 .then(function () {298 casper.evaluate(function () {299 require(['apps/coding-rules/app'], function (App) {300 App.start({ el: '#content' });301 });302 });303 })304 .then(function () {305 casper.waitForSelector('.js-create-manual-rule');306 })307 .then(function () {308 casper.click('.js-create-manual-rule');309 casper.waitForSelector('.modal');310 })311 .then(function () {312 casper.evaluate(function () {313 jQuery('.modal [name="name"]').val('Manual Rule').keyup();314 jQuery('.modal [name="markdown_description"]').val('Manual Rule Description');315 jQuery('.modal #coding-rules-manual-rule-creation-create').click();316 });317 casper.waitForSelector('.coding-rules-detail-header');318 })319 .then(function () {320 test.assertSelectorContains('.coding-rules-detail-header', 'Manual Rule');321 test.assertSelectorContains('.coding-rule-details', 'manual:Manual_Rule');322 test.assertSelectorContains('.coding-rules-detail-description', 'Manual Rule Description');323 });324 });325 it('should reactivate manual rule', 7, function (casper, test) {326 return casper327 .start(lib.buildUrl('base'), function () {328 lib.setDefaultViewport();329 lib.fmock('/api/rules/app', 'app.json');330 lib.fmock('/api/rules/search', 'search-create-manual-rule.json');331 this.createMock = lib.fmock('/api/rules/create', 'show-create-manual-rule.json', { status: 409 });332 lib.fmock('/api/rules/show', 'show-create-manual-rule.json');333 lib.smock('/api/issues/search', '{}');334 })335 .then(function () {336 casper.evaluate(function () {337 require(['apps/coding-rules/app'], function (App) {338 App.start({ el: '#content' });339 });340 jQuery.ajaxSetup({ dataType: 'json' });341 });342 })343 .then(function () {344 casper.waitForSelector('.js-create-manual-rule');345 })346 .then(function () {347 casper.click('.js-create-manual-rule');348 casper.waitForSelector('.modal');349 })350 .then(function () {351 test.assertNotVisible('.modal #coding-rules-manual-rule-creation-reactivate');352 test.assertVisible('.modal #coding-rules-manual-rule-creation-create');353 casper.evaluate(function () {354 jQuery('.modal [name="name"]').val('Manual Rule').keyup();355 jQuery('.modal [name="markdown_description"]').val('Manual Rule Description');356 jQuery('.modal #coding-rules-manual-rule-creation-create').click();357 });358 casper.waitForSelector('.modal .alert-warning');359 })360 .then(function () {361 test.assertVisible('.modal #coding-rules-manual-rule-creation-reactivate');362 test.assertNotVisible('.modal #coding-rules-manual-rule-creation-create');363 lib.clearRequestMock(this.createMock);364 lib.fmock('/api/rules/create', 'show.json');365 casper.click('.modal #coding-rules-manual-rule-creation-reactivate');366 casper.waitForSelector('.coding-rules-detail-header');367 })368 .then(function () {369 test.assertSelectorContains('.coding-rules-detail-header', 'Manual Rule');370 test.assertSelectorContains('.coding-rule-details', 'manual:Manual_Rule');371 test.assertSelectorContains('.coding-rules-detail-description', 'Manual Rule Description');372 });373 });374 it('should delete custom rules', 1, function (casper, test) {375 return casper376 .start(lib.buildUrl('base'), function () {377 lib.setDefaultViewport();378 lib.fmock('/api/rules/app', 'app.json');379 lib.fmock('/api/rules/search', 'search-delete-custom-rule-custom-rules.json',380 { data: { template_key: 'squid:ArchitecturalConstraint' } });381 lib.fmock('/api/rules/search', 'search-delete-custom-rule.json');382 lib.fmock('/api/rules/show', 'show-delete-custom-rule.json');383 lib.smock('/api/rules/delete', '{}');384 lib.smock('/api/issues/search', '{}');385 })386 .then(function () {387 casper.evaluate(function () {388 require(['apps/coding-rules/app'], function (App) {389 App.start({ el: '#content' });390 });391 });392 })393 .then(function () {394 casper.waitForSelector('.coding-rule.selected', function () {395 casper.click('.coding-rule.selected .js-rule');396 });397 })398 .then(function () {399 casper.waitForSelector('#coding-rules-detail-custom-rules .coding-rules-detail-list-name');400 })401 .then(function () {402 test.assertElementCount('#coding-rules-detail-custom-rules .coding-rules-detail-list-name', 2);403 casper.click('.js-delete-custom-rule');404 casper.click('[data-confirm="yes"]');405 lib.waitForElementCount('#coding-rules-detail-custom-rules .coding-rules-detail-list-name', 1);406 });407 });408 it('should delete manual rules', 1, function (casper, test) {409 return casper410 .start(lib.buildUrl('base'), function () {411 lib.setDefaultViewport();412 lib.fmock('/api/rules/app', 'app.json');413 this.searchMock = lib.fmock('/api/rules/search', 'search-delete-manual-rule-before.json');414 lib.fmock('/api/rules/show', 'show-delete-manual-rule.json');415 lib.smock('/api/rules/delete', '{}');416 lib.smock('/api/issues/search', '{}');417 })418 .then(function () {419 casper.evaluate(function () {420 require(['apps/coding-rules/app'], function (App) {421 App.start({ el: '#content' });422 });423 });424 })425 .then(function () {426 casper.waitForSelector('.coding-rule.selected', function () {427 casper.click('.coding-rule.selected .js-rule');428 });429 })430 .then(function () {431 casper.waitForSelector('.js-delete');432 })433 .then(function () {434 casper.click('.js-delete');435 casper.waitForSelector('[data-confirm="yes"]');436 })437 .then(function () {438 lib.clearRequestMock(this.searchMock);439 lib.fmock('/api/rules/search', 'search-delete-manual-rule-after.json');440 casper.click('[data-confirm="yes"]');441 casper.waitForSelectorTextChange('#coding-rules-total');442 })443 .then(function () {444 test.assertSelectorContains('#coding-rules-total', 0);445 });446 });447 it('should show custom rules', 3, function (casper, test) {448 return casper449 .start(lib.buildUrl('base'), function () {450 lib.setDefaultViewport();451 lib.fmock('/api/rules/app', 'app.json');452 lib.fmock('/api/rules/search', 'search-show-cutsom-rule-custom-rules.json',453 { data: { template_key: 'squid:ArchitecturalConstraint' } });454 lib.fmock('/api/rules/search', 'search-show-cutsom-rule.json');455 lib.fmock('/api/rules/show', 'show-show-cutsom-rule.json');456 lib.smock('/api/issues/search', '{}');457 })458 .then(function () {459 casper.evaluate(function () {460 require(['apps/coding-rules/app'], function (App) {461 App.start({ el: '#content' });462 });463 });464 })465 .then(function () {466 casper.waitForSelector('.coding-rule.selected', function () {467 casper.click('.coding-rule.selected .js-rule');468 });469 })470 .then(function () {471 casper.waitForSelector('#coding-rules-detail-custom-rules .coding-rules-detail-list-name');472 })473 .then(function () {474 test.assertExists('#coding-rules-detail-custom-rules');475 test.assertElementCount('#coding-rules-detail-custom-rules .coding-rules-detail-list-name', 2);476 test.assertSelectorContains('#coding-rules-detail-custom-rules .coding-rules-detail-list-name',477 'Do not use org.h2.util.StringUtils');478 });479 });480 it('should show deprecated label', 1, function (casper, test) {481 return casper482 .start(lib.buildUrl('base'), function () {483 lib.setDefaultViewport();484 lib.fmock('/api/rules/app', 'app.json');485 lib.fmock('/api/rules/search', 'search-deprecated.json');486 })487 .then(function () {488 casper.evaluate(function () {489 require(['apps/coding-rules/app'], function (App) {490 App.start({ el: '#content' });491 });492 });493 })494 .then(function () {495 casper.waitForSelector('.coding-rule.selected');496 })497 .then(function () {498 test.assertSelectorContains('.coding-rule.selected', 'DEPRECATED');499 });500 });501 it('should show rule details', 20, function (casper, test) {502 return casper503 .start(lib.buildUrl('base'), function () {504 lib.setDefaultViewport();505 lib.fmock('/api/rules/app', 'app.json');506 lib.fmock('/api/rules/search', 'search-show-details.json');507 lib.fmock('/api/rules/show', 'show-show-details.json');508 lib.smock('/api/issues/search', '{}');509 })510 .then(function () {511 casper.evaluate(function () {512 require(['apps/coding-rules/app'], function (App) {513 App.start({ el: '#content' });514 });515 });516 })517 .then(function () {518 casper.waitForSelector('.coding-rule.selected', function () {519 casper.click('.coding-rule.selected .js-rule');520 });521 })522 .then(function () {523 casper.waitForSelector('.coding-rules-detail-header');524 })525 .then(function () {526 test.assertSelectorContains('.search-navigator-workspace-details',527 'Throwable and Error classes should not be caught');528 test.assertSelectorContains('.search-navigator-workspace-details', 'squid:S1181');529 test.assertExists('.coding-rules-detail-properties .icon-severity-blocker');530 test.assertSelectorContains('.coding-rules-detail-properties', 'error-handling');531 test.assertSelectorContains('.coding-rules-detail-properties', '2013');532 test.assertSelectorContains('.coding-rules-detail-properties', 'SonarQube (Java)');533 test.assertSelectorContains('.coding-rules-detail-properties', 'Reliability > Exception handling');534 test.assertSelectorContains('.coding-rules-detail-properties', 'LINEAR');535 test.assertSelectorContains('.coding-rules-detail-properties', '20min');536 test.assertSelectorContains('.coding-rules-detail-description', 'is the superclass of all errors and');537 test.assertSelectorContains('.coding-rules-detail-description', 'its subclasses should be caught.');538 test.assertSelectorContains('.coding-rules-detail-description', 'Noncompliant Code Example');539 test.assertSelectorContains('.coding-rules-detail-description', 'Compliant Solution');540 test.assertSelectorContains('.coding-rules-detail-parameters', 'max');541 test.assertSelectorContains('.coding-rules-detail-parameters', 'Maximum authorized number of parameters');542 test.assertSelectorContains('.coding-rules-detail-parameters', '7');543 test.assertElementCount('.coding-rules-detail-quality-profile-name', 6);544 test.assertSelectorContains('.coding-rules-detail-quality-profile-name', 'Default - Top');545 test.assertElementCount('.coding-rules-detail-quality-profile-inheritance', 4);546 test.assertSelectorContains('.coding-rules-detail-quality-profile-inheritance', 'Default - Top');547 });548 });549 it('should show empty list', 3, function (casper, test) {550 return casper551 .start(lib.buildUrl('base'), function () {552 lib.setDefaultViewport();553 lib.fmock('/api/rules/app', 'app.json');554 lib.fmock('/api/rules/search', 'search-empty.json');555 })556 .then(function () {557 casper.evaluate(function () {558 require(['apps/coding-rules/app'], function (App) {559 App.start({ el: '#content' });560 });561 });562 })563 .then(function () {564 casper.waitForSelector('.search-navigator-facet-box');565 })566 .then(function () {567 test.assertDoesntExist('.coding-rule');568 test.assertSelectorContains('#coding-rules-total', 0);569 test.assertExists('.search-navigator-no-results');570 });571 });572 it('should show facets', 1, function (casper, test) {573 return casper574 .start(lib.buildUrl('base'), function () {575 lib.setDefaultViewport();576 lib.fmock('/api/rules/app', 'app.json');577 lib.fmock('/api/rules/search', 'search.json');578 })579 .then(function () {580 casper.evaluate(function () {581 require(['apps/coding-rules/app'], function (App) {582 App.start({ el: '#content' });583 });584 });585 })586 .then(function () {587 casper.waitForSelector('.search-navigator-facet-box');588 })589 .then(function () {590 test.assertElementCount('.search-navigator-facet-box', 13);591 });592 });593 it('should show rule', 7, function (casper, test) {594 return casper595 .start(lib.buildUrl('base'), function () {596 lib.setDefaultViewport();597 lib.fmock('/api/rules/app', 'app.json');598 lib.fmock('/api/rules/search', 'search.json');599 })600 .then(function () {601 casper.evaluate(function () {602 require(['apps/coding-rules/app'], function (App) {603 App.start({ el: '#content' });604 });605 });606 })607 .then(function () {608 casper.waitForSelector('.coding-rule.selected');609 })610 .then(function () {611 test.assertSelectorContains('.coding-rule.selected', 'Values passed to SQL commands should be sanitized');612 test.assertSelectorContains('.coding-rule.selected', 'Java');613 test.assertSelectorContains('.coding-rule.selected', 'cwe');614 test.assertSelectorContains('.coding-rule.selected', 'owasp-top10');615 test.assertSelectorContains('.coding-rule.selected', 'security');616 test.assertSelectorContains('.coding-rule.selected', 'sql');617 test.assertSelectorContains('.coding-rule.selected', 'custom-tag');618 });619 });620 it('should show rule issues', 5, function (casper, test) {621 return casper622 .start(lib.buildUrl('base'), function () {623 lib.setDefaultViewport();624 lib.fmock('/api/rules/app', 'app.json');625 lib.fmock('/api/rules/search', 'search.json');626 lib.fmock('/api/rules/show', 'show.json');627 lib.fmock('/api/issues/search', 'issues-search.json');628 })629 .then(function () {630 casper.evaluate(function () {631 require(['apps/coding-rules/app'], function (App) {632 App.start({ el: '#content' });633 });634 });635 })636 .then(function () {637 casper.waitForSelector('.coding-rule.selected', function () {638 casper.click('.coding-rule.selected .js-rule');639 });640 })641 .then(function () {642 casper.waitForSelector('.coding-rules-most-violated-projects');643 })644 .then(function () {645 test.assertSelectorContains('.js-rule-issues', '7');646 test.assertSelectorContains('.coding-rules-most-violated-projects', 'SonarQube');647 test.assertSelectorContains('.coding-rules-most-violated-projects', '2');648 test.assertSelectorContains('.coding-rules-most-violated-projects', 'SonarQube Runner');649 test.assertSelectorContains('.coding-rules-most-violated-projects', '1');650 });651 });652 it('should show rules', 4, function (casper, test) {653 return casper654 .start(lib.buildUrl('base'), function () {655 lib.setDefaultViewport();656 lib.fmock('/api/rules/app', 'app.json');657 lib.fmock('/api/rules/search', 'search.json');658 })659 .then(function () {660 casper.evaluate(function () {661 require(['apps/coding-rules/app'], function (App) {662 App.start({ el: '#content' });663 });664 });665 })666 .then(function () {667 casper.waitForSelector('.coding-rule');668 })669 .then(function () {670 test.assertElementCount('.coding-rule', 25);671 test.assertSelectorContains('.coding-rule', 'Values passed to SQL commands should be sanitized');672 test.assertSelectorContains('.coding-rule',673 'An open curly brace should be located at the beginning of a line');674 test.assertSelectorContains('#coding-rules-total', '609');675 });676 });677 it('should move between rules from detailed view', 3, function (casper, test) {678 return casper679 .start(lib.buildUrl('base'), function () {680 lib.setDefaultViewport();681 lib.fmock('/api/rules/app', 'app.json');682 lib.fmock('/api/rules/search', 'search.json');683 this.showMock = lib.fmock('/api/rules/show', 'show.json');684 })685 .then(function () {686 casper.evaluate(function () {687 require(['apps/coding-rules/app'], function (App) {688 App.start({ el: '#content' });689 });690 });691 })692 .then(function () {693 casper.waitForSelector('.coding-rule.selected', function () {694 casper.click('.coding-rule.selected .js-rule');695 });696 })697 .then(function () {698 casper.waitForSelector('.coding-rules-detail-header');699 })700 .then(function () {701 test.assertSelectorContains('.coding-rules-detail-header',702 '".equals()" should not be used to test the values');703 lib.clearRequestMock(this.showMock);704 this.showMock = lib.fmock('/api/rules/show', 'show2.json');705 casper.click('.js-next');706 casper.waitForSelectorTextChange('.coding-rules-detail-header');707 })708 .then(function () {709 test.assertSelectorContains('.coding-rules-detail-header', '"@Override" annotation should be used on any');710 lib.clearRequestMock(this.showMock);711 this.showMock = lib.fmock('/api/rules/show', 'show.json');712 casper.click('.js-prev');713 casper.waitForSelectorTextChange('.coding-rules-detail-header');714 })715 .then(function () {716 test.assertSelectorContains('.coding-rules-detail-header',717 '".equals()" should not be used to test the values');718 });719 });720 it('should filter similar rules', 3, function (casper, test) {721 return casper722 .start(lib.buildUrl('base'), function () {723 lib.setDefaultViewport();724 lib.fmock('/api/rules/app', 'app.json');725 lib.fmock('/api/rules/search', 'search-sql-tag.json', { data: { tags: 'sql' } });726 lib.fmock('/api/rules/search', 'search.json');727 })728 .then(function () {729 casper.evaluate(function () {730 require(['apps/coding-rules/app'], function (App) {731 App.start({ el: '#content' });732 });733 });734 })735 .then(function () {736 casper.waitForSelector('.coding-rule.selected .js-rule-filter');737 })738 .then(function () {739 test.assertSelectorContains('#coding-rules-total', '609');740 casper.click('.js-rule-filter');741 casper.waitForSelector('.bubble-popup');742 })743 .then(function () {744 test.assertExists('.bubble-popup [data-property="languages"][data-value="java"]');745 casper.click('.bubble-popup [data-property="tags"][data-value="sql"]');746 casper.waitForSelectorTextChange('#coding-rules-total');747 })748 .then(function () {749 test.assertSelectorContains('#coding-rules-total', '2');750 });751 });752 it('should show active severity facet', 7, function (casper, test) {753 return casper754 .start(lib.buildUrl('base'), function () {755 lib.setDefaultViewport();756 lib.fmock('/api/rules/app', 'app.json');757 lib.fmock('/api/rules/search', 'search-BLOCKER.json', { data: { active_severities: 'BLOCKER' } });758 lib.fmock('/api/rules/search', 'active-severities-facet.json',759 { data: { facets: 'active_severities', ps: '1' } });760 lib.fmock('/api/rules/search', 'search-qprofile.json',761 { data: { qprofile: 'java-default-with-mojo-conventions-49307' } });762 lib.fmock('/api/rules/search', 'search.json');763 })764 .then(function () {765 casper.evaluate(function () {766 require(['apps/coding-rules/app'], function (App) {767 App.start({ el: '#content' });768 });769 });770 })771 .then(function () {772 casper.waitForSelector('.coding-rule');773 })774 .then(function () {775 test.assertSelectorContains('#coding-rules-total', '609');776 test.assertExists('.search-navigator-facet-box-forbidden[data-property="active_severities"]');777 casper.click('[data-property="qprofile"] .js-facet-toggle');778 casper.waitForSelector('.js-facet[data-value="java-default-with-mojo-conventions-49307"]');779 })780 .then(function () {781 casper.click('.js-facet[data-value="java-default-with-mojo-conventions-49307"]');782 casper.waitForSelectorTextChange('#coding-rules-total');783 })784 .then(function () {785 test.assertSelectorContains('#coding-rules-total', '407');786 test.assertDoesntExist('.search-navigator-facet-box-forbidden[data-property="active_severities"]');787 casper.click('[data-property="active_severities"] .js-facet-toggle');788 casper.waitForSelector('[data-property="active_severities"] [data-value="BLOCKER"]');789 })790 .then(function () {791 casper.click('[data-property="active_severities"] [data-value="BLOCKER"]');792 casper.waitForSelectorTextChange('#coding-rules-total');793 })794 .then(function () {795 test.assertSelectorContains('#coding-rules-total', '4');796 casper.click('[data-property="qprofile"] .js-facet-toggle');797 casper.waitForSelectorTextChange('#coding-rules-total');798 })799 .then(function () {800 test.assertSelectorContains('#coding-rules-total', '609');801 test.assertExists('.search-navigator-facet-box-forbidden[data-property="active_severities"]');802 });803 });804 it('should show available since facet', 2, function (casper, test) {805 return casper806 .start(lib.buildUrl('base'), function () {807 lib.setDefaultViewport();808 lib.fmock('/api/rules/app', 'app.json');809 lib.fmock('/api/rules/search', 'search-limited.json', { data: { available_since: '2014-12-01' } });810 lib.fmock('/api/rules/search', 'search.json');811 })812 .then(function () {813 casper.evaluate(function () {814 require(['apps/coding-rules/app'], function (App) {815 App.start({ el: '#content' });816 });817 });818 })819 .then(function () {820 casper.waitForSelector('.coding-rule');821 })822 .then(function () {823 test.assertSelectorContains('#coding-rules-total', '609');824 casper.click('[data-property="available_since"] .js-facet-toggle');825 casper.evaluate(function () {826 jQuery('[data-property="available_since"] input').val('2014-12-01').change();827 });828 })829 .then(function () {830 casper.waitForSelectorTextChange('#coding-rules-total');831 })832 .then(function () {833 test.assertSelectorContains('#coding-rules-total', '101');834 });835 });836 it('should bulk activate', 7, function (casper, test) {837 return casper838 .start(lib.buildUrl('base'), function () {839 lib.setDefaultViewport();840 lib.fmock('/api/rules/app', 'app.json');841 lib.fmock('/api/rules/search', 'search.json');842 lib.smock('/api/qualityprofiles/activate_rules', '{ "succeeded": 225 }');843 })844 .then(function () {845 casper.evaluate(function () {846 require(['apps/coding-rules/app'], function (App) {847 App.start({ el: '#content' });848 });849 jQuery.ajaxSetup({ dataType: 'json' });850 });851 })852 .then(function () {853 casper.waitForSelector('.coding-rule');854 })855 .then(function () {856 test.assertExists('.js-bulk-change');857 casper.click('.js-bulk-change');858 casper.waitForSelector('.bubble-popup');859 })860 .then(function () {861 test.assertExists('.bubble-popup .js-bulk-change[data-action="activate"]');862 casper.click('.js-bulk-change[data-action="activate"]');863 casper.waitForSelector('.modal');864 })865 .then(function () {866 test.assertExists('.modal #coding-rules-bulk-change-profile');867 test.assertExists('.modal #coding-rules-submit-bulk-change');868 })869 .then(function () {870 casper.evaluate(function () {871 jQuery('#coding-rules-bulk-change-profile').val('java-default-with-mojo-conventions-49307');872 });873 })874 .then(function () {875 casper.click('.modal #coding-rules-submit-bulk-change');876 casper.waitForSelector('.modal .alert-success');877 })878 .then(function () {879 test.assertSelectorContains('.modal', 'Default - Maven Conventions');880 test.assertSelectorContains('.modal', 'Java');881 test.assertSelectorContains('.modal', '225');882 });883 });884 it('should fail to bulk activate', 6, function (casper, test) {885 return casper886 .start(lib.buildUrl('base'), function () {887 lib.setDefaultViewport();888 lib.fmock('/api/rules/app', 'app.json');889 lib.fmock('/api/rules/search', 'search.json');890 lib.smock('/api/qualityprofiles/activate_rules', '{ "succeeded": 225, "failed": 395 }');891 })892 .then(function () {893 casper.evaluate(function () {894 require(['apps/coding-rules/app'], function (App) {895 App.start({ el: '#content' });896 });897 jQuery.ajaxSetup({ dataType: 'json' });898 });899 })900 .then(function () {901 casper.waitForSelector('.coding-rule');902 })903 .then(function () {904 test.assertExists('.js-bulk-change');905 casper.click('.js-bulk-change');906 casper.waitForSelector('.bubble-popup');907 })908 .then(function () {909 test.assertExists('.bubble-popup .js-bulk-change[data-action="activate"]');910 casper.click('.js-bulk-change[data-action="activate"]');911 casper.waitForSelector('.modal');912 })913 .then(function () {914 test.assertExists('.modal #coding-rules-bulk-change-profile');915 test.assertExists('.modal #coding-rules-submit-bulk-change');916 })917 .then(function () {918 casper.evaluate(function () {919 jQuery('#coding-rules-bulk-change-profile').val('java-default-with-mojo-conventions-49307');920 });921 })922 .then(function () {923 casper.click('.modal #coding-rules-submit-bulk-change');924 casper.waitForSelector('.modal .alert-warning');925 })926 .then(function () {927 test.assertSelectorContains('.modal', '225');928 test.assertSelectorContains('.modal', '395');929 });930 });931 it('should filter profiles by language during bulk change', 4, function (casper, test) {932 return casper933 .start(lib.buildUrl('base'), function () {934 lib.setDefaultViewport();935 lib.fmock('/api/rules/app', 'app.json');936 lib.fmock('/api/rules/search', 'search.json');937 })938 .then(function () {939 casper.evaluate(function () {940 require(['apps/coding-rules/app'], function (App) {941 App.start({ el: '#content' });942 });943 jQuery.ajaxSetup({ dataType: 'json' });944 });945 })946 .then(function () {947 casper.waitForSelector('.coding-rule');948 })949 .then(function () {950 casper.click('.js-facet[data-value="java"]');951 test.assertExists('.js-bulk-change');952 casper.click('.js-bulk-change');953 casper.waitForSelector('.bubble-popup');954 })955 .then(function () {956 test.assertExists('.bubble-popup .js-bulk-change[data-action="activate"]');957 casper.click('.js-bulk-change[data-action="activate"]');958 casper.waitForSelector('.modal');959 })960 .then(function () {961 test.assertExists('.modal #coding-rules-bulk-change-profile');962 test.assertEqual(8, casper.evaluate(function () {963 return jQuery('.modal').find('#coding-rules-bulk-change-profile').find('option').length;964 }));965 });966 });967 it('should change selected profile during bulk change', 4, function (casper, test) {968 return casper969 .start(lib.buildUrl('base'), function () {970 lib.setDefaultViewport();971 lib.fmock('/api/rules/app', 'app.json');972 lib.fmock('/api/rules/search', 'search-qprofile-active.json',973 { data: { activation: true } });974 lib.fmock('/api/rules/search', 'search.json');975 lib.smock('/api/qualityprofiles/deactivate_rules', '{ "succeeded": 7 }');976 })977 .then(function () {978 casper.evaluate(function () {979 require(['apps/coding-rules/app'], function (App) {980 App.start({ el: '#content' });981 });982 jQuery.ajaxSetup({ dataType: 'json' });983 });984 })985 .then(function () {986 casper.waitForSelector('.coding-rule');987 })988 .then(function () {989 casper.click('[data-property="qprofile"] .js-facet-toggle');990 casper.waitForSelector('.js-facet[data-value="java-default-with-mojo-conventions-49307"]');991 })992 .then(function () {993 casper.click('.js-facet[data-value="java-default-with-mojo-conventions-49307"]');994 casper.waitForSelectorTextChange('#coding-rules-total');995 })996 .then(function () {997 test.assertExists('.js-bulk-change');998 casper.click('.js-bulk-change');999 casper.waitForSelector('.bubble-popup');1000 })1001 .then(function () {1002 test.assertExists('.bubble-popup .js-bulk-change[data-param="java-default-with-mojo-conventions-49307"]');1003 casper.click('.js-bulk-change[data-param="java-default-with-mojo-conventions-49307"]');1004 casper.waitForSelector('.modal');1005 })1006 .then(function () {1007 test.assertDoesntExist('.modal #coding-rules-bulk-change-profile');1008 casper.click('.modal #coding-rules-submit-bulk-change');1009 casper.waitForSelector('.modal .alert-success');1010 })1011 .then(function () {1012 test.assertSelectorContains('.modal', '7');1013 });1014 });1015 it('should show characteristic facet', 6, function (casper, test) {1016 return casper1017 .start(lib.buildUrl('base'), function () {1018 lib.setDefaultViewport();1019 lib.smock('/api/l10n/index', '{}');1020 lib.fmock('/api/rules/app', 'app.json');1021 lib.fmock('/api/rules/search', 'search-with-portability-characteristic.json',1022 { data: { debt_characteristics: 'PORTABILITY' } });1023 lib.fmock('/api/rules/search', 'search-with-memory-efficiency-characteristic.json',1024 { data: { debt_characteristics: 'MEMORY_EFFICIENCY' } });1025 lib.fmock('/api/rules/search', 'search-without-characteristic.json',1026 { data: { has_debt_characteristic: 'false' } });1027 lib.fmock('/api/rules/search', 'search-characteristic.json',1028 { data: { facets: 'debt_characteristics' } });1029 lib.fmock('/api/rules/search', 'search.json');1030 })1031 .then(function () {1032 casper.evaluate(function () {1033 require(['apps/coding-rules/app'], function (App) {1034 App.start({ el: '#content' });1035 });1036 jQuery.ajaxSetup({ dataType: 'json' });1037 });1038 })1039 .then(function () {1040 casper.waitForSelector('.coding-rule');1041 })1042 .then(function () {1043 // enable facet1044 test.assertExists('.search-navigator-facet-box-collapsed[data-property="debt_characteristics"]');1045 casper.click('[data-property="debt_characteristics"] .js-facet-toggle');1046 casper.waitForSelector('.js-facet[data-value="PORTABILITY"]');1047 })1048 .then(function () {1049 // select characteristic1050 test.assertElementCount('[data-property="debt_characteristics"] .js-facet', 32);1051 test.assertElementCount('[data-property="debt_characteristics"] .js-facet.search-navigator-facet-indent', 24);1052 casper.click('.js-facet[data-value="PORTABILITY"]');1053 casper.waitForSelectorTextChange('#coding-rules-total', function () {1054 test.assertSelectorContains('#coding-rules-total', 21);1055 });1056 })1057 .then(function () {1058 // select uncharacterized1059 casper.click('.js-facet[data-empty-characteristic]');1060 casper.waitForSelectorTextChange('#coding-rules-total', function () {1061 test.assertSelectorContains('#coding-rules-total', 208);1062 });1063 })1064 .then(function () {1065 // select sub-characteristic1066 casper.click('.js-facet[data-value="MEMORY_EFFICIENCY"]');1067 casper.waitForSelectorTextChange('#coding-rules-total', function () {1068 test.assertSelectorContains('#coding-rules-total', 3);1069 });1070 });1071 });1072 it('should disable characteristic facet', 6, function (casper, test) {1073 return casper1074 .start(lib.buildUrl('base'), function () {1075 lib.setDefaultViewport();1076 lib.smock('/api/l10n/index', '{}');1077 lib.fmock('/api/rules/app', 'app.json');1078 lib.fmock('/api/rules/search', 'search-with-portability-characteristic.json',1079 { data: { debt_characteristics: 'PORTABILITY' } });1080 lib.fmock('/api/rules/search', 'search-with-memory-efficiency-characteristic.json',1081 { data: { debt_characteristics: 'MEMORY_EFFICIENCY' } });1082 lib.fmock('/api/rules/search', 'search-without-characteristic.json',1083 { data: { has_debt_characteristic: 'false' } });1084 lib.fmock('/api/rules/search', 'search-characteristic.json',1085 { data: { facets: 'debt_characteristics' } });1086 lib.fmock('/api/rules/search', 'search.json');1087 })1088 .then(function () {1089 casper.evaluate(function () {1090 require(['apps/coding-rules/app'], function (App) {1091 App.start({ el: '#content' });1092 });1093 jQuery.ajaxSetup({ dataType: 'json' });1094 });1095 })1096 .then(function () {1097 casper.waitForSelector('.coding-rule');1098 })1099 .then(function () {1100 // enable facet1101 casper.click('[data-property="debt_characteristics"] .js-facet-toggle');1102 casper.waitForSelector('.js-facet[data-value="PORTABILITY"]');1103 })1104 .then(function () {1105 // select characteristic1106 casper.click('.js-facet[data-value="PORTABILITY"]');1107 casper.waitForSelectorTextChange('#coding-rules-total', function () {1108 test.assertSelectorContains('#coding-rules-total', 21);1109 });1110 })1111 .then(function () {1112 // disable facet1113 casper.click('[data-property="debt_characteristics"] .js-facet-toggle');1114 casper.waitForSelectorTextChange('#coding-rules-total', function () {1115 test.assertSelectorContains('#coding-rules-total', 609);1116 });1117 })1118 .then(function () {1119 // enable facet1120 casper.click('[data-property="debt_characteristics"] .js-facet-toggle');1121 casper.waitForSelector('.js-facet[data-value="MEMORY_EFFICIENCY"]');1122 })1123 .then(function () {1124 // select sub-characteristic1125 casper.click('.js-facet[data-value="MEMORY_EFFICIENCY"]');1126 casper.waitForSelectorTextChange('#coding-rules-total', function () {1127 test.assertSelectorContains('#coding-rules-total', 3);1128 });1129 })1130 .then(function () {1131 // disable facet1132 casper.click('[data-property="debt_characteristics"] .js-facet-toggle');1133 casper.waitForSelectorTextChange('#coding-rules-total', function () {1134 test.assertSelectorContains('#coding-rules-total', 609);1135 });1136 })1137 .then(function () {1138 // enable facet1139 casper.click('[data-property="debt_characteristics"] .js-facet-toggle');1140 casper.waitForSelector('.js-facet[data-empty-characteristic]');1141 })1142 .then(function () {1143 // select uncharacterized1144 casper.click('.js-facet[data-empty-characteristic]');1145 casper.waitForSelectorTextChange('#coding-rules-total', function () {1146 test.assertSelectorContains('#coding-rules-total', 208);1147 });1148 })1149 .then(function () {1150 // disable facet1151 casper.click('[data-property="debt_characteristics"] .js-facet-toggle');1152 casper.waitForSelectorTextChange('#coding-rules-total', function () {1153 test.assertSelectorContains('#coding-rules-total', 609);1154 });1155 });1156 });1157 it('should show template facet', 4, function (casper, test) {1158 return casper1159 .start(lib.buildUrl('base'), function () {1160 lib.setDefaultViewport();1161 lib.smock('/api/l10n/index', '{}');1162 lib.fmock('/api/rules/app', 'app.json');1163 lib.fmock('/api/rules/search', 'search-only-templates.json', { data: { 'is_template': 'true' } });1164 lib.fmock('/api/rules/search', 'search-hide-templates.json', { data: { 'is_template': 'false' } });1165 lib.fmock('/api/rules/search', 'search.json');1166 })1167 .then(function () {1168 casper.evaluate(function () {1169 require(['apps/coding-rules/app'], function (App) {1170 App.start({ el: '#content' });1171 });1172 jQuery.ajaxSetup({ dataType: 'json' });1173 });1174 })1175 .then(function () {1176 casper.waitForSelector('.coding-rule');1177 })1178 .then(function () {1179 // enable facet1180 test.assertExists('.search-navigator-facet-box-collapsed[data-property="is_template"]');1181 casper.click('[data-property="is_template"] .js-facet-toggle');1182 casper.waitForSelector('[data-property="is_template"] .js-facet[data-value="true"]');1183 })1184 .then(function () {1185 // show only templates1186 casper.click('[data-property="is_template"] .js-facet[data-value="true"]');1187 casper.waitForSelectorTextChange('#coding-rules-total', function () {1188 test.assertSelectorContains('#coding-rules-total', 8);1189 });1190 })1191 .then(function () {1192 // hide templates1193 casper.click('[data-property="is_template"] .js-facet[data-value="false"]');1194 casper.waitForSelectorTextChange('#coding-rules-total', function () {1195 test.assertSelectorContains('#coding-rules-total', 7);1196 });1197 })1198 .then(function () {1199 // disable facet1200 casper.click('[data-property="is_template"] .js-facet-toggle');1201 casper.waitForSelectorTextChange('#coding-rules-total', function () {1202 test.assertSelectorContains('#coding-rules-total', 609);1203 });1204 });1205 });1206 it('should show language facet', 5, function (casper, test) {1207 return casper1208 .start(lib.buildUrl('base'), function () {1209 lib.setDefaultViewport();1210 lib.smock('/api/l10n/index', '{}');1211 lib.fmock('/api/rules/app', 'app.json');1212 lib.fmock('/api/rules/search', 'search-with-custom-language.json', { data: { languages: 'custom' } });1213 lib.fmock('/api/rules/search', 'search.json');1214 lib.smock('/api/languages/list', '{"languages":[{"key":"custom","name":"Custom"}]}',1215 { data: { q: 'custom' } });1216 })1217 .then(function () {1218 casper.evaluate(function () {1219 require(['apps/coding-rules/app'], function (App) {1220 App.start({ el: '#content' });1221 });1222 jQuery.ajaxSetup({ dataType: 'json' });1223 });1224 })1225 .then(function () {1226 casper.waitForSelector('.coding-rule');1227 })1228 .then(function () {1229 casper.click('[data-property="languages"] .select2-choice');1230 casper.waitForSelector('.select2-search', function () {1231 casper.evaluate(function () {1232 jQuery('.select2-input').val('custom').trigger('keyup-change');1233 });1234 });1235 })1236 .then(function () {1237 casper.waitForSelector('.select2-result');1238 })1239 .then(function () {1240 test.assertSelectorContains('.select2-result', 'Custom');1241 casper.evaluate(function () {1242 jQuery('.select2-result').mouseup();1243 });1244 })1245 .then(function () {1246 casper.waitForSelectorTextChange('#coding-rules-total');1247 })1248 .then(function () {1249 test.assertSelectorContains('#coding-rules-total', 13);1250 test.assertExists('[data-property="languages"] .js-facet.active');1251 test.assertSelectorContains('[data-property="languages"] .js-facet.active', 'custom');1252 test.assertSelectorContains('[data-property="languages"] .js-facet.active', '13');1253 });1254 });1255 it('should reload results', 2, function (casper, test) {1256 return casper1257 .start(lib.buildUrl('base'), function () {1258 lib.setDefaultViewport();1259 lib.smock('/api/l10n/index', '{}');1260 lib.fmock('/api/rules/app', 'app.json');1261 this.searchMock = lib.fmock('/api/rules/search', 'search.json');1262 })1263 .then(function () {1264 casper.evaluate(function () {1265 require(['apps/coding-rules/app'], function (App) {1266 App.start({ el: '#content' });1267 });1268 jQuery.ajaxSetup({ dataType: 'json' });1269 });1270 })1271 .then(function () {1272 casper.waitForSelector('.coding-rule');1273 })1274 .then(function () {1275 test.assertSelectorContains('#coding-rules-total', 609);1276 lib.clearRequestMock(this.searchMock);1277 lib.fmock('/api/rules/search', 'search2.json');1278 casper.click('.js-reload');1279 casper.waitForSelectorTextChange('#coding-rules-total');1280 })1281 .then(function () {1282 test.assertSelectorContains('#coding-rules-total', 413);1283 });1284 });1285 it('should do a new search', 3, function (casper, test) {1286 return casper1287 .start(lib.buildUrl('base'), function () {1288 lib.setDefaultViewport();1289 lib.smock('/api/l10n/index', '{}');1290 lib.fmock('/api/rules/app', 'app.json');1291 lib.fmock('/api/rules/search', 'search2.json', { data: { languages: 'java' } });1292 lib.fmock('/api/rules/search', 'search.json');1293 })1294 .then(function () {1295 casper.evaluate(function () {1296 require(['apps/coding-rules/app'], function (App) {1297 App.start({ el: '#content' });1298 });1299 jQuery.ajaxSetup({ dataType: 'json' });1300 });1301 })1302 .then(function () {1303 casper.waitForSelector('.coding-rule');1304 })1305 .then(function () {1306 test.assertSelectorContains('#coding-rules-total', 609);1307 casper.click('.js-facet[data-value="java"]');1308 casper.waitForSelectorTextChange('#coding-rules-total');1309 })1310 .then(function () {1311 test.assertSelectorContains('#coding-rules-total', 413);1312 casper.click('.js-new-search');1313 casper.waitForSelectorTextChange('#coding-rules-total');1314 })1315 .then(function () {1316 test.assertSelectorContains('#coding-rules-total', 609);1317 });1318 });1319 it('should go back', 2, function (casper, test) {1320 return casper1321 .start(lib.buildUrl('base'), function () {1322 lib.setDefaultViewport();1323 lib.smock('/api/l10n/index', '{}');1324 lib.fmock('/api/rules/app', 'app.json');1325 lib.fmock('/api/rules/search', 'search.json');1326 lib.fmock('/api/rules/show', 'show.json');1327 })1328 .then(function () {1329 casper.evaluate(function () {1330 require(['apps/coding-rules/app'], function (App) {1331 App.start({ el: '#content' });1332 });1333 jQuery.ajaxSetup({ dataType: 'json' });1334 });1335 })1336 .then(function () {1337 casper.waitForSelector('.coding-rule.selected', function () {1338 casper.click('.coding-rule.selected .js-rule');1339 });1340 })1341 .then(function () {1342 casper.waitForSelector('.coding-rules-detail-header');1343 })1344 .then(function () {1345 casper.click('.js-back');1346 test.assertDoesntExist('.js-back');1347 test.assertDoesntExist('.coding-rules-detail-header');1348 });1349 });1350 it('should show inheritance facet', 11, function (casper, test) {1351 return casper1352 .start(lib.buildUrl('base'), function () {1353 lib.setDefaultViewport();1354 lib.fmock('/api/rules/app', 'app.json');1355 lib.fmock('/api/rules/search', 'search-not-inherited.json', { data: { inheritance: 'NONE' } });1356 lib.fmock('/api/rules/search', 'search-inherited.json', { data: { inheritance: 'INHERITED' } });1357 lib.fmock('/api/rules/search', 'search-overriden.json', { data: { inheritance: 'OVERRIDES' } });1358 lib.fmock('/api/rules/search', 'search-qprofile.json',1359 { data: { qprofile: 'java-default-with-mojo-conventions-49307' } });1360 lib.fmock('/api/rules/search', 'search-qprofile2.json',1361 { data: { qprofile: 'java-top-profile-without-formatting-conventions-50037' } });1362 lib.fmock('/api/rules/search', 'search.json');1363 })1364 .then(function () {1365 casper.evaluate(function () {1366 require(['apps/coding-rules/app'], function (App) {1367 App.start({ el: '#content' });1368 });1369 });1370 })1371 .then(function () {1372 casper.waitForSelector('.coding-rule');1373 })1374 .then(function () {1375 test.assertSelectorContains('#coding-rules-total', '609');1376 test.assertExists('.search-navigator-facet-box-forbidden[data-property="inheritance"]');1377 casper.click('[data-property="qprofile"] .js-facet-toggle');1378 casper.waitForSelector('.js-facet[data-value="java-default-with-mojo-conventions-49307"]');1379 })1380 .then(function () {1381 casper.click('.js-facet[data-value="java-default-with-mojo-conventions-49307"]');1382 casper.waitForSelectorTextChange('#coding-rules-total');1383 })1384 .then(function () {1385 test.assertSelectorContains('#coding-rules-total', '407');1386 test.assertDoesntExist('.search-navigator-facet-box-forbidden[data-property="inheritance"]');1387 casper.click('[data-property="inheritance"] .js-facet-toggle');1388 casper.waitForSelector('[data-property="inheritance"] [data-value="NONE"]');1389 })1390 .then(function () {1391 casper.click('[data-property="inheritance"] [data-value="NONE"]');1392 casper.waitForSelectorTextChange('#coding-rules-total');1393 })1394 .then(function () {1395 test.assertSelectorContains('#coding-rules-total', '103');1396 casper.click('[data-property="inheritance"] [data-value="INHERITED"]');1397 casper.waitForSelectorTextChange('#coding-rules-total');1398 })1399 .then(function () {1400 test.assertSelectorContains('#coding-rules-total', '101');1401 casper.click('[data-property="inheritance"] [data-value="OVERRIDES"]');1402 casper.waitForSelectorTextChange('#coding-rules-total');1403 })1404 .then(function () {1405 test.assertSelectorContains('#coding-rules-total', '102');1406 casper.click('.js-facet[data-value="java-top-profile-without-formatting-conventions-50037"]');1407 casper.waitForSelectorTextChange('#coding-rules-total');1408 })1409 .then(function () {1410 test.assertSelectorContains('#coding-rules-total', '408');1411 test.assertExists('.search-navigator-facet-box-forbidden[data-property="inheritance"]');1412 casper.click('[data-property="qprofile"] .js-facet-toggle');1413 casper.waitForSelectorTextChange('#coding-rules-total');1414 })1415 .then(function () {1416 test.assertSelectorContains('#coding-rules-total', '609');1417 test.assertExists('.search-navigator-facet-box-forbidden[data-property="inheritance"]');1418 });1419 });1420 it('should show activation details', 5, function (casper, test) {1421 return casper1422 .start(lib.buildUrl('base'), function () {1423 lib.setDefaultViewport();1424 lib.smock('/api/l10n/index', '{}');1425 lib.fmock('/api/rules/app', 'app.json');1426 lib.fmock('/api/rules/search', 'search-actives.json', { data: { activation: true } });1427 lib.fmock('/api/rules/search', 'search.json');1428 })1429 .then(function () {1430 casper.evaluate(function () {1431 require(['apps/coding-rules/app'], function (App) {1432 App.start({ el: '#content' });1433 });1434 jQuery.ajaxSetup({ dataType: 'json' });1435 });1436 })1437 .then(function () {1438 casper.waitForSelector('.coding-rule');1439 })1440 .then(function () {1441 test.assertDoesntExist('.coding-rule-activation');1442 casper.click('[data-property="qprofile"] .js-facet-toggle');1443 casper.waitForSelector('.js-facet[data-value="java-default-with-mojo-conventions-49307"]');1444 })1445 .then(function () {1446 casper.click('.js-facet[data-value="java-default-with-mojo-conventions-49307"]');1447 casper.waitForSelectorTextChange('#coding-rules-total');1448 })1449 .then(function () {1450 test.assertElementCount('.coding-rule-activation', 2);1451 test.assertElementCount('.coding-rule-activation .icon-severity-major', 2);1452 test.assertElementCount('.coding-rule-activation .icon-inheritance', 1);1453 test.assertDoesntExist('.coding-rules-detail-quality-profile-activate');1454 });1455 });1456 it('should activate rule', 9, function (casper, test) {1457 return casper1458 .start(lib.buildUrl('base'), function () {1459 lib.setDefaultViewport();1460 lib.smock('/api/l10n/index', '{}');1461 lib.fmock('/api/rules/app', 'app.json');1462 lib.fmock('/api/rules/search', 'search-inactive.json', { data: { activation: 'false' } });1463 lib.fmock('/api/rules/search', 'search.json');1464 lib.smock('/api/qualityprofiles/activate_rule', '{}');1465 })1466 .then(function () {1467 casper.evaluate(function () {1468 require(['apps/coding-rules/app'], function (App) {1469 App.start({ el: '#content' });1470 });1471 jQuery.ajaxSetup({ dataType: 'json' });1472 });1473 })1474 .then(function () {1475 casper.waitForSelector('.coding-rule');1476 })1477 .then(function () {1478 test.assertDoesntExist('.coding-rule-activation');1479 casper.click('[data-property="qprofile"] .js-facet-toggle');1480 casper.waitForSelector('.js-facet[data-value="java-default-with-mojo-conventions-49307"]');1481 })1482 .then(function () {1483 casper.click('.js-facet[data-value="java-default-with-mojo-conventions-49307"]');1484 casper.click('.js-facet[data-value="java-default-with-mojo-conventions-49307"] .js-inactive');1485 casper.waitForSelectorTextChange('#coding-rules-total');1486 })1487 .then(function () {1488 test.assertDoesntExist('.coding-rule-activation .icon-severity-major');1489 test.assertExists('.coding-rules-detail-quality-profile-activate');1490 casper.click('.coding-rules-detail-quality-profile-activate');1491 casper.waitForSelector('.modal');1492 })1493 .then(function () {1494 test.assertExists('#coding-rules-quality-profile-activation-select');1495 test.assertElementCount('#coding-rules-quality-profile-activation-select option', 1);1496 test.assertExists('#coding-rules-quality-profile-activation-severity');1497 casper.click('#coding-rules-quality-profile-activation-activate');1498 casper.waitForSelector('.coding-rule-activation .icon-severity-major');1499 })1500 .then(function () {1501 test.assertExist('.coding-rule-activation .icon-severity-major');1502 test.assertDoesntExist('.coding-rules-detail-quality-profile-activate');1503 test.assertExist('.coding-rules-detail-quality-profile-deactivate');1504 });1505 });1506 it('should deactivate rule', 6, function (casper, test) {1507 return casper1508 .start(lib.buildUrl('base'), function () {1509 lib.setDefaultViewport();1510 lib.smock('/api/l10n/index', '{}');1511 lib.fmock('/api/rules/app', 'app.json');1512 lib.fmock('/api/rules/search', 'search-active.json', { data: { activation: true } });1513 lib.fmock('/api/rules/search', 'search.json');1514 lib.smock('/api/qualityprofiles/deactivate_rule', '{}');1515 })1516 .then(function () {1517 casper.evaluate(function () {1518 require(['apps/coding-rules/app'], function (App) {1519 App.start({ el: '#content' });1520 });1521 jQuery.ajaxSetup({ dataType: 'json' });1522 });1523 })...
quality-profiles.js
Source:quality-profiles.js
...3describe('Quality Profiles App', function () {4 it('should show list', 9, function (casper, test) {5 return casper6 .start(lib.buildUrl('base'), function () {7 lib.setDefaultViewport();8 lib.fmock('/api/users/current', 'user.json');9 lib.fmock('/api/qualityprofiles/search', 'search.json');10 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');11 lib.fmock('/api/languages/list', 'languages.json');12 })13 .then(function () {14 casper.evaluate(function () {15 require(['apps/quality-profiles/app'], function (App) {16 App.start({ el: '#content', urlRoot: '/pages/base' });17 });18 });19 })20 .then(function () {21 casper.waitForSelector('.js-list .list-group-item');22 })23 .then(function () {24 test.assertElementCount('.js-list .list-group-item', 5);25 test.assertSelectorContains('.js-list .list-group-item', 'Sonar way');26 test.assertSelectorContains('.js-list .list-group-item', 'PSR-2');27 test.assertElementCount('.js-list-language', 4);28 test.assertSelectorContains('.js-list-language', 'Java');29 test.assertSelectorContains('.js-list-language', 'JavaScript');30 test.assertSelectorContains('.js-list-language', 'PHP');31 test.assertSelectorContains('.js-list-language', 'Python');32 test.assertElementCount('.js-list .badge', 4);33 });34 });35 it('should filter list by language', 15, function (casper, test) {36 return casper37 .start(lib.buildUrl('base'), function () {38 lib.setDefaultViewport();39 lib.fmock('/api/users/current', 'user.json');40 lib.fmock('/api/qualityprofiles/search', 'search.json');41 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');42 lib.fmock('/api/languages/list', 'languages.json');43 })44 .then(function () {45 casper.evaluate(function () {46 require(['apps/quality-profiles/app'], function (App) {47 App.start({ el: '#content', urlRoot: '/pages/base' });48 });49 });50 })51 .then(function () {52 casper.waitForSelector('.js-list .list-group-item');53 })54 .then(function () {55 test.assertElementCount('.js-list .list-group-item', 5);56 test.assertVisible('.js-list .list-group-item[data-key="java-sonar-way-67887"]');57 test.assertVisible('.js-list .list-group-item[data-key="js-sonar-way-71566"]');58 test.assertElementCount('.js-list-language', 4);59 test.assertVisible('.js-list-language[data-language="java"]');60 test.assertVisible('.js-list-language[data-language="js"]');61 })62 .then(function () {63 test.assertExists('#quality-profiles-filter-by-language');64 casper.click('.js-filter-by-language[data-language="js"]');65 })66 .then(function () {67 test.assertNotVisible('.js-list .list-group-item[data-key="java-sonar-way-67887"]');68 test.assertVisible('.js-list .list-group-item[data-key="js-sonar-way-71566"]');69 test.assertNotVisible('.js-list-language[data-language="java"]');70 test.assertVisible('.js-list-language[data-language="js"]');71 })72 .then(function () {73 casper.click('.js-filter-by-language:nth-child(1)');74 })75 .then(function () {76 test.assertVisible('.js-list .list-group-item[data-key="java-sonar-way-67887"]');77 test.assertVisible('.js-list .list-group-item[data-key="js-sonar-way-71566"]');78 test.assertVisible('.js-list-language[data-language="java"]');79 test.assertVisible('.js-list-language[data-language="js"]');80 });81 });82 it('should show details', 10, function (casper, test) {83 return casper84 .start(lib.buildUrl('base'), function () {85 lib.setDefaultViewport();86 lib.fmock('/api/users/current', 'user.json');87 lib.fmock('/api/qualityprofiles/search', 'search.json');88 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');89 lib.fmock('/api/languages/list', 'languages.json');90 lib.fmock('/api/rules/search', 'rules.json',91 { data: { qprofile: 'java-sonar-way-67887', activation: 'true' } });92 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json', {93 data: { profileKey: 'java-sonar-way-67887' }94 });95 })96 .then(function () {97 casper.evaluate(function () {98 require(['apps/quality-profiles/app'], function (App) {99 App.start({ el: '#content', urlRoot: '/pages/base' });100 });101 });102 })103 .then(function () {104 casper.waitForSelector('.js-list .list-group-item');105 })106 .then(function () {107 casper.click('.js-list .list-group-item[data-key="java-sonar-way-67887"]');108 casper.waitForSelector('.search-navigator-header-component');109 })110 .then(function () {111 test.assertElementCount('.js-list .list-group-item.active', 1);112 test.assertSelectorContains('.js-list .list-group-item.active', 'Sonar way');113 test.assertSelectorContains('.search-navigator-workspace-header', 'Sonar way');114 test.assertSelectorContains('.search-navigator-workspace-header', 'Java');115 test.assertExists('#quality-profile-backup');116 test.assertDoesntExist('#quality-profile-rename');117 test.assertDoesntExist('#quality-profile-copy');118 test.assertDoesntExist('#quality-profile-delete');119 test.assertDoesntExist('#quality-profile-set-as-default');120 test.assertDoesntExist('#quality-profile-change-parent');121 });122 });123 it('should show details for admin', 10, function (casper, test) {124 return casper125 .start(lib.buildUrl('base'), function () {126 lib.setDefaultViewport();127 lib.fmock('/api/users/current', 'user-admin.json');128 lib.fmock('/api/qualityprofiles/search', 'search.json');129 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');130 lib.fmock('/api/languages/list', 'languages.json');131 lib.fmock('/api/rules/search', 'rules.json',132 { data: { qprofile: 'java-sonar-way-67887', activation: 'true' } });133 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json', {134 data: { profileKey: 'java-sonar-way-67887' }135 });136 })137 .then(function () {138 casper.evaluate(function () {139 require(['apps/quality-profiles/app'], function (App) {140 App.start({ el: '#content', urlRoot: '/pages/base' });141 });142 });143 })144 .then(function () {145 casper.waitForSelector('.js-list .list-group-item');146 })147 .then(function () {148 casper.click('.js-list .list-group-item[data-key="java-sonar-way-67887"]');149 casper.waitForSelector('.search-navigator-header-component');150 })151 .then(function () {152 test.assertElementCount('.js-list .list-group-item.active', 1);153 test.assertSelectorContains('.js-list .list-group-item.active', 'Sonar way');154 test.assertSelectorContains('.search-navigator-workspace-header', 'Sonar way');155 test.assertSelectorContains('.search-navigator-workspace-header', 'Java');156 test.assertExists('#quality-profile-backup');157 test.assertExists('#quality-profile-rename');158 test.assertExists('#quality-profile-copy');159 test.assertDoesntExist('#quality-profile-delete');160 test.assertDoesntExist('#quality-profile-set-as-default');161 test.assertExists('#quality-profile-change-parent');162 });163 });164 it('should show inheritance details', 10, function (casper, test) {165 return casper166 .start(lib.buildUrl('base'), function () {167 lib.setDefaultViewport();168 lib.fmock('/api/users/current', 'user-admin.json');169 lib.fmock('/api/qualityprofiles/search', 'search-inheritance.json');170 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');171 lib.fmock('/api/languages/list', 'languages.json');172 lib.fmock('/api/rules/search', 'rules.json');173 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance-plus.json', {174 data: { profileKey: 'java-inherited-profile-85155' }175 });176 })177 .then(function () {178 casper.evaluate(function () {179 require(['apps/quality-profiles/app'], function (App) {180 App.start({ el: '#content', urlRoot: '/pages/base' });181 });182 });183 })184 .then(function () {185 casper.waitForSelector('.js-list .list-group-item');186 })187 .then(function () {188 casper.click('.js-list .list-group-item[data-key="java-inherited-profile-85155"]');189 casper.waitForSelector('.search-navigator-header-component');190 })191 .then(function () {192 test.assertElementCount('#quality-profile-ancestors li', 1);193 test.assertSelectorContains('#quality-profile-ancestors', 'Sonar way');194 test.assertSelectorContains('#quality-profile-ancestors', '161');195 test.assertElementCount('#quality-profile-inheritance-current', 1);196 test.assertSelectorContains('#quality-profile-inheritance-current', 'Inherited Profile');197 test.assertSelectorContains('#quality-profile-inheritance-current', '163');198 test.assertSelectorContains('#quality-profile-inheritance-current', '7');199 test.assertElementCount('#quality-profile-children li', 1);200 test.assertSelectorContains('#quality-profile-children', 'Second Level Inherited Profile');201 test.assertSelectorContains('#quality-profile-children', '165');202 });203 });204 it('should show selected projects', 2, function (casper, test) {205 return casper206 .start(lib.buildUrl('base'), function () {207 lib.setDefaultViewport();208 lib.fmock('/api/users/current', 'user-admin.json');209 lib.fmock('/api/qualityprofiles/search', 'search.json');210 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');211 lib.fmock('/api/languages/list', 'languages.json');212 lib.fmock('/api/rules/search', 'rules.json');213 lib.fmock('/api/qualityprofiles/projects?key=php-psr-2-46772', 'projects.json');214 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');215 })216 .then(function () {217 casper.evaluate(function () {218 require(['apps/quality-profiles/app'], function (App) {219 App.start({ el: '#content', urlRoot: '/pages/base' });220 });221 });222 })223 .then(function () {224 casper.waitForSelector('.js-list .list-group-item');225 })226 .then(function () {227 casper.click('.js-list .list-group-item[data-key="php-psr-2-46772"]');228 casper.waitForSelector('#quality-profile-projects');229 })230 .then(function () {231 lib.waitForElementCount('#quality-profile-projects .select-list-list li', 2);232 })233 .then(function () {234 test.assertSelectorContains('#quality-profile-projects .select-list-list li', 'CSS');235 test.assertSelectorContains('#quality-profile-projects .select-list-list li', 'http-request-parent');236 });237 });238 it('should move between profiles', 1, function (casper, test) {239 return casper240 .start(lib.buildUrl('base'), function () {241 lib.setDefaultViewport();242 lib.fmock('/api/users/current', 'user.json');243 lib.fmock('/api/qualityprofiles/search', 'search-inheritance.json');244 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');245 lib.fmock('/api/languages/list', 'languages.json');246 this.rulesMock = lib.fmock('/api/rules/search', 'rules.json',247 { data: { qprofile: 'java-inherited-profile-85155', activation: 'true' } });248 this.inheritanceMock = lib.fmock('/api/qualityprofiles/inheritance', 'inheritance-plus.json');249 })250 .then(function () {251 casper.evaluate(function () {252 require(['apps/quality-profiles/app'], function (App) {253 App.start({ el: '#content', urlRoot: '/pages/base' });254 });255 });256 })257 .then(function () {258 casper.waitForSelector('.js-list .list-group-item');259 })260 .then(function () {261 casper.click('.js-list .list-group-item[data-key="java-inherited-profile-85155"]');262 casper.waitForSelector('#quality-profile-ancestors');263 })264 .then(function () {265 lib.clearRequestMock(this.rulesMock);266 lib.clearRequestMock(this.inheritanceMock);267 lib.fmock('/api/rules/search', 'rules.json',268 { data: { qprofile: 'java-sonar-way-67887', activation: 'true' } });269 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');270 casper.click('#quality-profile-ancestors .js-profile[data-key="java-sonar-way-67887"]');271 casper.waitForSelectorTextChange('.search-navigator-header-component');272 })273 .then(function () {274 test.assertSelectorContains('.search-navigator-header-component', 'Sonar way');275 });276 });277 it('should copy profile', 5, function (casper, test) {278 return casper279 .start(lib.buildUrl('base'), function () {280 lib.setDefaultViewport();281 lib.fmock('/api/users/current', 'user-admin.json');282 lib.fmock('/api/qualityprofiles/search', 'search.json');283 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');284 lib.fmock('/api/languages/list', 'languages.json');285 lib.fmock('/api/rules/search', 'rules.json');286 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');287 lib.fmock('/api/qualityprofiles/copy', 'copy.json', {288 data: { fromKey: 'java-sonar-way-67887', toName: 'Copied Profile' }289 });290 })291 .then(function () {292 casper.evaluate(function () {293 require(['apps/quality-profiles/app'], function (App) {294 App.start({ el: '#content', urlRoot: '/pages/base' });295 });296 jQuery.ajaxSetup({ dataType: 'json' });297 });298 })299 .then(function () {300 casper.waitForSelector('.js-list .list-group-item');301 })302 .then(function () {303 test.assertElementCount('.js-list .list-group-item', 5);304 casper.click('.js-list .list-group-item[data-key="java-sonar-way-67887"]');305 casper.waitForSelector('#quality-profile-copy');306 })307 .then(function () {308 casper.click('#quality-profile-copy');309 casper.waitForSelector('.modal');310 })311 .then(function () {312 casper.evaluate(function () {313 jQuery('#copy-profile-name').val('Copied Profile');314 });315 casper.click('#copy-profile-submit');316 casper.waitForSelectorTextChange('.search-navigator-header-component');317 })318 .then(function () {319 test.assertElementCount('.js-list .list-group-item', 6);320 test.assertSelectorContains('.js-list .list-group-item.active', 'Copied Profile');321 test.assertSelectorContains('.search-navigator-header-component', 'Copied Profile');322 test.assertSelectorContains('.search-navigator-header-component', 'Java');323 });324 });325 it('should rename profile', 2, function (casper, test) {326 return casper327 .start(lib.buildUrl('base'), function () {328 lib.setDefaultViewport();329 lib.fmock('/api/users/current', 'user-admin.json');330 this.searchMock = lib.fmock('/api/qualityprofiles/search', 'search.json');331 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');332 lib.fmock('/api/languages/list', 'languages.json');333 lib.fmock('/api/rules/search', 'rules.json');334 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');335 lib.smock('/api/qualityprofiles/rename', '{}', {336 data: { key: 'java-sonar-way-67887', name: 'Renamed Profile' }337 });338 })339 .then(function () {340 casper.evaluate(function () {341 require(['apps/quality-profiles/app'], function (App) {342 App.start({ el: '#content', urlRoot: '/pages/base' });343 });344 jQuery.ajaxSetup({ dataType: 'json' });345 });346 })347 .then(function () {348 casper.waitForSelector('.js-list .list-group-item');349 })350 .then(function () {351 casper.click('.js-list .list-group-item[data-key="java-sonar-way-67887"]');352 casper.waitForSelector('#quality-profile-rename');353 })354 .then(function () {355 casper.click('#quality-profile-rename');356 casper.waitForSelector('.modal');357 })358 .then(function () {359 lib.clearRequestMock(this.searchMock);360 lib.fmock('/api/qualityprofiles/search', 'search-renamed.json');361 casper.evaluate(function () {362 jQuery('#rename-profile-name').val('Renamed Profile');363 });364 casper.click('#rename-profile-submit');365 casper.waitForSelectorTextChange('.search-navigator-header-component');366 })367 .then(function () {368 test.assertSelectorContains('.js-list .list-group-item.active', 'Renamed Profile');369 test.assertSelectorContains('.search-navigator-header-component', 'Renamed Profile');370 });371 });372 it('should make profile default', 4, function (casper, test) {373 return casper374 .start(lib.buildUrl('base'), function () {375 lib.setDefaultViewport();376 lib.fmock('/api/users/current', 'user-admin.json');377 this.searchMock = lib.fmock('/api/qualityprofiles/search', 'search.json');378 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');379 lib.fmock('/api/languages/list', 'languages.json');380 lib.fmock('/api/rules/search', 'rules.json');381 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');382 lib.smock('/api/qualityprofiles/set_default', '{}', {383 data: { profileKey: 'php-psr-2-46772' }384 });385 })386 .then(function () {387 casper.evaluate(function () {388 require(['apps/quality-profiles/app'], function (App) {389 App.start({ el: '#content', urlRoot: '/pages/base' });390 });391 jQuery.ajaxSetup({ dataType: 'json' });392 });393 })394 .then(function () {395 casper.waitForSelector('.js-list .list-group-item');396 })397 .then(function () {398 test.assertDoesntExist('.js-list .list-group-item[data-key="php-psr-2-46772"] .badge');399 test.assertExists('.js-list .list-group-item[data-key="php-sonar-way-10778"] .badge');400 casper.click('.js-list .list-group-item[data-key="php-psr-2-46772"]');401 casper.waitForSelector('#quality-profile-set-as-default');402 })403 .then(function () {404 lib.clearRequestMock(this.searchMock);405 lib.fmock('/api/qualityprofiles/search', 'search-another-default.json');406 casper.click('#quality-profile-set-as-default');407 casper.waitWhileSelector('.js-list .list-group-item[data-key="php-sonar-way-10778"] .badge');408 })409 .then(function () {410 test.assertDoesntExist('#quality-profile-set-as-default');411 test.assertExists('.js-list .list-group-item[data-key="php-psr-2-46772"] .badge');412 });413 });414 it('should delete profile', 2, function (casper, test) {415 return casper416 .start(lib.buildUrl('base'), function () {417 lib.setDefaultViewport();418 lib.fmock('/api/users/current', 'user-admin.json');419 this.searchMock = lib.fmock('/api/qualityprofiles/search', 'search-with-copy.json');420 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');421 lib.fmock('/api/languages/list', 'languages.json');422 lib.fmock('/api/rules/search', 'rules.json');423 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');424 lib.smock('/api/qualityprofiles/delete', '{}', {425 data: { profileKey: 'java-copied-profile-11711' }426 });427 })428 .then(function () {429 casper.evaluate(function () {430 require(['apps/quality-profiles/app'], function (App) {431 App.start({ el: '#content', urlRoot: '/pages/base' });432 });433 jQuery.ajaxSetup({ dataType: 'json' });434 });435 })436 .then(function () {437 casper.waitForSelector('.js-list .list-group-item');438 })439 .then(function () {440 test.assertElementCount('.js-list .list-group-item', 6);441 casper.click('.js-list .list-group-item[data-key="java-copied-profile-11711"]');442 casper.waitForSelector('#quality-profile-delete');443 })444 .then(function () {445 casper.click('#quality-profile-delete');446 casper.waitForSelector('.modal');447 })448 .then(function () {449 lib.clearRequestMock(this.searchMock);450 lib.fmock('/api/qualityprofiles/search', 'search.json');451 casper.click('#delete-profile-submit');452 lib.waitForElementCount('.js-list .list-group-item', 5);453 })454 .then(function () {455 test.assertSelectorDoesntContain('.js-list .list-group-item', 'Copied Profile');456 });457 });458 it('should create profile', 1, function (casper, test) {459 return casper460 .start(lib.buildUrl('base'), function () {461 lib.setDefaultViewport();462 lib.fmock('/api/users/current', 'user-admin.json');463 this.searchMock = lib.fmock('/api/qualityprofiles/search', 'search.json');464 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');465 lib.fmock('/api/rules/search', 'rules.json');466 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');467 lib.fmock('/api/languages/list', 'languages.json');468 lib.fmock('/api/qualityprofiles/importers', 'importers-empty.json');469 })470 .then(function () {471 casper.evaluate(function () {472 require(['apps/quality-profiles/app'], function (App) {473 App.start({ el: '#content', urlRoot: '/pages/base' });474 });475 jQuery.ajaxSetup({ dataType: 'json' });476 });477 })478 .then(function () {479 casper.waitForSelector('.js-list .list-group-item');480 })481 .then(function () {482 test.assertElementCount('.js-list .list-group-item', 5);483 casper.click('#quality-profiles-create');484 casper.waitForSelector('.modal');485 })486 .then(function () {487 lib.clearRequestMock(this.searchMock);488 lib.fmock('/api/qualityprofiles/search', 'search-with-copy.json');489 casper.evaluate(function () {490 jQuery('#create-profile-name').val('Copied Profile');491 jQuery('#create-profile-language').val('java');492 });493 casper.click('#create-profile-submit');494 lib.waitForElementCount('.js-list .list-group-item', 6);495 });496 });497 it('should restore profile', 1, function (casper, test) {498 return casper499 .start(lib.buildUrl('base'), function () {500 lib.setDefaultViewport();501 lib.fmock('/api/users/current', 'user-admin.json');502 this.searchMock = lib.fmock('/api/qualityprofiles/search', 'search.json');503 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');504 lib.fmock('/api/languages/list', 'languages.json');505 lib.fmock('/api/rules/search', 'rules.json');506 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');507 })508 .then(function () {509 casper.evaluate(function () {510 require(['apps/quality-profiles/app'], function (App) {511 App.start({ el: '#content', urlRoot: '/pages/base' });512 });513 jQuery.ajaxSetup({ dataType: 'json' });514 });515 })516 .then(function () {517 casper.waitForSelector('.js-list .list-group-item');518 })519 .then(function () {520 test.assertElementCount('.js-list .list-group-item', 5);521 casper.click('#quality-profiles-restore');522 casper.waitForSelector('.modal');523 })524 .then(function () {525 casper.click('#restore-profile-submit');526 lib.waitForElementCount('.js-list .list-group-item', 6);527 });528 });529 it('should show importers', 6, function (casper, test) {530 return casper531 .start(lib.buildUrl('base'), function () {532 lib.setDefaultViewport();533 lib.fmock('/api/users/current', 'user-admin.json');534 lib.fmock('/api/qualityprofiles/search', 'search.json');535 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');536 lib.fmock('/api/rules/search', 'rules.json');537 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');538 lib.fmock('/api/languages/list', 'languages.json');539 lib.fmock('/api/qualityprofiles/importers', 'importers.json');540 })541 .then(function () {542 casper.evaluate(function () {543 require(['apps/quality-profiles/app'], function (App) {544 App.start({ el: '#content', urlRoot: '/pages/base' });545 });546 jQuery.ajaxSetup({ dataType: 'json' });547 });548 })549 .then(function () {550 casper.waitForSelector('.js-list .list-group-item');551 })552 .then(function () {553 casper.click('#quality-profiles-create');554 casper.waitForSelector('.modal');555 })556 .then(function () {557 test.assertVisible('.js-importer[data-key="pmd"]');558 test.assertVisible('.js-importer[data-key="random"]');559 casper.evaluate(function () {560 jQuery('#create-profile-language').val('js').change();561 });562 })563 .then(function () {564 test.assertNotVisible('.js-importer[data-key="pmd"]');565 test.assertVisible('.js-importer[data-key="random"]');566 casper.evaluate(function () {567 jQuery('#create-profile-language').val('py').change();568 });569 })570 .then(function () {571 test.assertNotVisible('.js-importer[data-key="pmd"]');572 test.assertNotVisible('.js-importer[data-key="random"]');573 });574 });575 it('should restore built-in profiles', 3, function (casper, test) {576 return casper577 .start(lib.buildUrl('base'), function () {578 lib.setDefaultViewport();579 lib.fmock('/api/users/current', 'user-admin.json');580 this.searchMock = lib.fmock('/api/qualityprofiles/search', 'search-modified.json');581 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');582 lib.fmock('/api/rules/search', 'rules.json');583 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');584 lib.smock('/api/qualityprofiles/restore_built_in', '{}', {585 data: { language: 'java' }586 });587 lib.fmock('/api/languages/list', 'languages.json');588 })589 .then(function () {590 casper.evaluate(function () {591 require(['apps/quality-profiles/app'], function (App) {592 App.start({ el: '#content', urlRoot: '/pages/base' });593 });594 jQuery.ajaxSetup({ dataType: 'json' });595 });596 })597 .then(function () {598 casper.waitForSelector('.js-list .list-group-item');599 })600 .then(function () {601 test.assertElementCount('.js-list .list-group-item', 1);602 casper.click('#quality-profiles-restore-built-in');603 casper.waitForSelector('.modal');604 })605 .then(function () {606 lib.clearRequestMock(this.searchMock);607 lib.fmock('/api/qualityprofiles/search', 'search.json');608 casper.evaluate(function () {609 jQuery('#restore-built-in-profiles-language').val('java');610 });611 casper.click('#restore-built-in-profiles-submit');612 lib.waitForElementCount('.js-list .list-group-item', 5);613 })614 .then(function () {615 test.assertSelectorContains('.js-list .list-group-item', 'Sonar way');616 test.assertDoesntExist('.search-navigator-header-component');617 });618 });619 it('should change profile\'s parent', 1, function (casper, test) {620 return casper621 .start(lib.buildUrl('base'), function () {622 lib.setDefaultViewport();623 lib.fmock('/api/users/current', 'user-admin.json');624 this.searchMock = lib.fmock('/api/qualityprofiles/search', 'search-change-parent.json');625 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');626 lib.fmock('/api/languages/list', 'languages.json');627 lib.fmock('/api/rules/search', 'rules.json');628 this.inheritanceMock = lib.fmock('/api/qualityprofiles/inheritance',629 'inheritance-change-parent.json');630 lib.smock('/api/qualityprofiles/change_parent', '{}', {631 data: { profileKey: 'java-inherited-profile-85155', parentKey: 'java-another-profile-00609' }632 });633 })634 .then(function () {635 casper.evaluate(function () {636 require(['apps/quality-profiles/app'], function (App) {637 App.start({ el: '#content', urlRoot: '/pages/base' });638 });639 jQuery.ajaxSetup({ dataType: 'json' });640 });641 })642 .then(function () {643 casper.waitForSelector('.js-list .list-group-item');644 })645 .then(function () {646 casper.click('.js-list .list-group-item[data-key="java-inherited-profile-85155"]');647 casper.waitForSelector('#quality-profile-change-parent');648 })649 .then(function () {650 casper.click('#quality-profile-change-parent');651 casper.waitForSelector('.modal');652 })653 .then(function () {654 lib.clearRequestMock(this.searchMock);655 lib.fmock('/api/qualityprofiles/search', 'search-changed-parent.json');656 lib.clearRequestMock(this.inheritanceMock);657 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance-changed-parent.json');658 casper.evaluate(function () {659 jQuery('#change-profile-parent').val('java-another-profile-00609');660 });661 casper.click('#change-profile-parent-submit');662 casper.waitForSelectorTextChange('#quality-profile-ancestors');663 })664 .then(function () {665 test.assertSelectorContains('#quality-profile-ancestors', 'Another Profile');666 });667 });668 it('should open permalink', 9, function (casper, test) {669 return casper670 .start(lib.buildUrl('base#show?key=java-sonar-way-67887'), function () {671 lib.setDefaultViewport();672 lib.fmock('/api/users/current', 'user-admin.json');673 lib.fmock('/api/qualityprofiles/search', 'search.json');674 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');675 lib.fmock('/api/languages/list', 'languages.json');676 lib.fmock('/api/rules/search', 'rules.json');677 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');678 })679 .then(function () {680 casper.evaluate(function () {681 require(['apps/quality-profiles/app'], function (App) {682 App.start({ el: '#content', urlRoot: '/pages/base' });683 });684 });685 })686 .then(function () {687 casper.waitForSelector('#quality-profile-rename');688 })689 .then(function () {690 test.assertElementCount('.js-list .list-group-item.active', 1);691 test.assertSelectorContains('.js-list .list-group-item.active', 'Sonar way');692 test.assertSelectorContains('.search-navigator-workspace-header', 'Sonar way');693 test.assertSelectorContains('.search-navigator-workspace-header', 'Java');694 test.assertExists('#quality-profile-backup');695 test.assertExists('#quality-profile-rename');696 test.assertExists('#quality-profile-copy');697 test.assertDoesntExist('#quality-profile-delete');698 test.assertDoesntExist('#quality-profile-set-as-default');699 });700 });701 it('should show changelog', 22, function (casper, test) {702 return casper703 .start(lib.buildUrl('base#show?key=java-sonar-way-67887'), function () {704 lib.setDefaultViewport();705 lib.fmock('/api/users/current', 'user.json');706 lib.fmock('/api/qualityprofiles/search', 'search.json');707 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');708 lib.fmock('/api/languages/list', 'languages.json');709 lib.fmock('/api/rules/search', 'rules.json');710 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');711 lib.fmock('/api/qualityprofiles/changelog', 'changelog2.json', {712 data: { p: '2', profileKey: 'java-sonar-way-67887' }713 });714 lib.fmock('/api/qualityprofiles/changelog', 'changelog.json', {715 data: { profileKey: 'java-sonar-way-67887' }716 });717 })718 .then(function () {719 casper.evaluate(function () {720 require(['apps/quality-profiles/app'], function (App) {721 App.start({ el: '#content', urlRoot: '/pages/base' });722 });723 });724 })725 .then(function () {726 casper.waitForSelector('#quality-profile-changelog-form-submit');727 })728 .then(function () {729 test.assertDoesntExist('.js-show-more-changelog');730 casper.click('#quality-profile-changelog-form-submit');731 casper.waitForSelector('#quality-profile-changelog table');732 })733 .then(function () {734 test.assertExists('.js-show-more-changelog');735 test.assertElementCount('#quality-profile-changelog tbody tr', 2);736 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(1)', 'April 13 2015');737 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(1)', 'System');738 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(1)', 'ACTIVATED');739 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(1)', 'Synchronisation should not');740 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(1)', 'BLOCKER');741 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'April 13 2015');742 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'Anakin Skywalker');743 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'ACTIVATED');744 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'Double.longBitsToDouble');745 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'threshold');746 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', '3');747 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'emptyParameter');748 casper.click('.js-show-more-changelog');749 lib.waitForElementCount('#quality-profile-changelog tbody tr', 3);750 })751 .then(function () {752 test.assertDoesntExist('.js-show-changelog');753 test.assertDoesntExist('.js-show-more-changelog');754 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(3)', 'April 13 2015');755 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(3)', 'System');756 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(3)', 'DEACTIVATED');757 test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(3)', 'runFinalizersOnExit');758 })759 .then(function () {760 casper.click('.js-hide-changelog');761 test.assertDoesntExist('#quality-profile-changelog tbody tr');762 });763 });764 it('should open changelog permalink', 2, function (casper, test) {765 return casper766 .start(lib.buildUrl('base#changelog?since=2015-03-25&key=java-sonar-way-67887&to=2015-03-26'), function () {767 lib.setDefaultViewport();768 lib.fmock('/api/users/current', 'user.json');769 lib.fmock('/api/qualityprofiles/search', 'search.json');770 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');771 lib.fmock('/api/languages/list', 'languages.json');772 lib.fmock('/api/rules/search', 'rules.json');773 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');774 lib.fmock('/api/qualityprofiles/changelog', 'changelog2.json', {775 data: {776 p: '2',777 since: '2015-03-25',778 to: '2015-03-26',779 profileKey: 'java-sonar-way-67887'780 }781 });782 lib.fmock('/api/qualityprofiles/changelog', 'changelog.json', {783 data: {784 since: '2015-03-25',785 to: '2015-03-26',786 profileKey: 'java-sonar-way-67887'787 }788 });789 })790 .then(function () {791 casper.evaluate(function () {792 require(['apps/quality-profiles/app'], function (App) {793 App.start({ el: '#content', urlRoot: '/pages/base' });794 });795 });796 })797 .then(function () {798 casper.waitForSelector('.js-show-more-changelog');799 })800 .then(function () {801 test.assertElementCount('#quality-profile-changelog tbody tr', 2);802 casper.click('.js-show-more-changelog');803 lib.waitForElementCount('#quality-profile-changelog tbody tr', 3);804 })805 .then(function () {806 test.assertDoesntExist('.js-show-more-changelog');807 });808 });809 it('should show comparison', 12, function (casper, test) {810 return casper811 .start(lib.buildUrl('base#show?key=java-sonar-way-67887'), function () {812 lib.setDefaultViewport();813 lib.fmock('/api/users/current', 'user.json');814 lib.fmock('/api/qualityprofiles/search', 'search-with-copy.json');815 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');816 lib.fmock('/api/languages/list', 'languages.json');817 lib.fmock('/api/rules/search', 'rules.json');818 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');819 lib.fmock('/api/qualityprofiles/compare', 'compare.json', {820 data: { leftKey: 'java-sonar-way-67887', rightKey: 'java-copied-profile-11711' }821 });822 })823 .then(function () {824 casper.evaluate(function () {825 require(['apps/quality-profiles/app'], function (App) {826 App.start({ el: '#content', urlRoot: '/pages/base' });827 });828 });829 })830 .then(function () {831 casper.waitForSelector('#quality-profile-comparison-form-submit');832 })833 .then(function () {834 test.assertElementCount('#quality-profile-comparison-with-key option', 1);835 casper.click('#quality-profile-comparison-form-submit');836 casper.waitForSelector('#quality-profile-comparison table');837 })838 .then(function () {839 test.assertElementCount('.js-comparison-in-left', 2);840 test.assertElementCount('.js-comparison-in-right', 2);841 test.assertElementCount('.js-comparison-modified', 2);842 test.assertSelectorContains('.js-comparison-in-left', '".equals()" should not be used to test');843 test.assertSelectorContains('.js-comparison-in-left', '"@Override" annotation should be used on');844 test.assertSelectorContains('.js-comparison-in-right', '"ConcurrentLinkedQueue.size()" should not be used');845 test.assertSelectorContains('.js-comparison-in-right', '"compareTo" results should not be checked');846 test.assertSelectorContains('.js-comparison-modified', 'Control flow statements');847 test.assertSelectorContains('.js-comparison-modified', '"Cloneables" should implement "clone"');848 test.assertSelectorContains('.js-comparison-modified', 'max: 5');849 test.assertSelectorContains('.js-comparison-modified', 'max: 3');850 });851 });852 it('should open comparison permalink', 4, function (casper, test) {853 return casper854 .start(lib.buildUrl('base#compare?key=java-sonar-way-67887&withKey=java-copied-profile-11711'),855 function () {856 lib.setDefaultViewport();857 lib.fmock('/api/users/current', 'user.json');858 lib.fmock('/api/qualityprofiles/search', 'search-with-copy.json');859 lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');860 lib.fmock('/api/languages/list', 'languages.json');861 lib.fmock('/api/rules/search', 'rules.json');862 lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');863 lib.fmock('/api/qualityprofiles/compare', 'compare.json', {864 data: { leftKey: 'java-sonar-way-67887', rightKey: 'java-copied-profile-11711' }865 });866 })867 .then(function () {868 casper.evaluate(function () {869 require(['apps/quality-profiles/app'], function (App) {870 App.start({ el: '#content', urlRoot: '/pages/base' });...
quality-gates-spec.js
Source:quality-gates-spec.js
...3describe('Quality Gates App', function () {4 it('should show list', 5, function (casper, test) {5 return casper6 .start(lib.buildUrl('base'), function () {7 lib.setDefaultViewport();8 lib.fmock('/api/qualitygates/app', 'app.json');9 lib.fmock('/api/qualitygates/list', 'list.json');10 })11 .then(function () {12 casper.evaluate(function () {13 require(['apps/quality-gates/app'], function (App) {14 App.start({ el: '#content', urlRoot: '/pages/base' });15 });16 });17 })18 .then(function () {19 casper.waitForSelector('.js-list .list-group-item');20 })21 .then(function () {22 test.assertElementCount('.js-list .list-group-item', 3);23 test.assertSelectorContains('.js-list .list-group-item', 'SonarQube way');24 test.assertSelectorContains('.js-list .list-group-item', 'Simple Gate');25 test.assertSelectorContains('.js-list .list-group-item', 'Another Gate');26 test.assertElementCount('.js-list .badge', 1);27 });28 });29 it('should show details for anonymous', 14, function (casper, test) {30 return casper31 .start(lib.buildUrl('base'), function () {32 lib.setDefaultViewport();33 lib.fmock('/api/qualitygates/app', 'app-anonymous.json');34 lib.fmock('/api/qualitygates/list', 'list.json');35 lib.fmock('/api/qualitygates/show', 'show.json', { data: { id: '1' } });36 })37 .then(function () {38 casper.evaluate(function () {39 require(['apps/quality-gates/app'], function (App) {40 App.start({ el: '#content', urlRoot: '/pages/base' });41 });42 });43 })44 .then(function () {45 casper.waitForSelector('.js-list .list-group-item');46 })47 .then(function () {48 casper.click('.js-list .list-group-item[data-id="1"]');49 casper.waitForSelector('.search-navigator-header-component');50 })51 .then(function () {52 test.assertElementCount('.js-list .list-group-item.active', 1);53 test.assertSelectorContains('.js-list .list-group-item.active', 'SonarQube way');54 test.assertSelectorContains('.search-navigator-workspace-header', 'SonarQube way');55 test.assertDoesntExist('#quality-gate-rename');56 test.assertDoesntExist('#quality-gate-copy');57 test.assertDoesntExist('#quality-gate-unset-as-default');58 test.assertDoesntExist('#quality-gate-delete');59 test.assertExists('.js-conditions');60 test.assertElementCount('.js-conditions tbody tr', 8);61 test.assertDoesntExist('.js-conditions .update-condition');62 test.assertDoesntExist('.js-conditions .delete-condition');63 test.assertExists('.quality-gate-default-message');64 })65 .then(function () {66 test.assertNotVisible('.js-more');67 casper.click('.js-show-more');68 test.assertVisible('.js-more');69 });70 });71 it('should show details for admin', 12, function (casper, test) {72 return casper73 .start(lib.buildUrl('base'), function () {74 lib.setDefaultViewport();75 lib.fmock('/api/qualitygates/app', 'app.json');76 lib.fmock('/api/qualitygates/list', 'list.json');77 lib.fmock('/api/qualitygates/show', 'show.json', { data: { id: '1' } });78 })79 .then(function () {80 casper.evaluate(function () {81 require(['apps/quality-gates/app'], function (App) {82 App.start({ el: '#content', urlRoot: '/pages/base' });83 });84 });85 })86 .then(function () {87 casper.waitForSelector('.js-list .list-group-item');88 })89 .then(function () {90 casper.click('.js-list .list-group-item[data-id="1"]');91 casper.waitForSelector('.search-navigator-header-component');92 })93 .then(function () {94 test.assertElementCount('.js-list .list-group-item.active', 1);95 test.assertSelectorContains('.js-list .list-group-item.active', 'SonarQube way');96 test.assertSelectorContains('.search-navigator-workspace-header', 'SonarQube way');97 test.assertExists('#quality-gate-rename');98 test.assertExists('#quality-gate-copy');99 test.assertExists('#quality-gate-toggle-default');100 test.assertExists('#quality-gate-delete');101 test.assertExists('.js-conditions');102 test.assertElementCount('.js-conditions tbody tr', 8);103 test.assertElementCount('.js-conditions .update-condition', 8);104 test.assertElementCount('.js-conditions .delete-condition', 8);105 test.assertExists('.quality-gate-default-message');106 });107 });108 it('should show projects', 2, function (casper, test) {109 return casper110 .start(lib.buildUrl('base#show/5'), function () {111 lib.setDefaultViewport();112 lib.fmock('/api/qualitygates/app', 'app-anonymous.json');113 lib.fmock('/api/qualitygates/list', 'list.json');114 lib.fmock('/api/qualitygates/show', 'show-another.json', { data: { id: '5' } });115 lib.fmock('/api/qualitygates/search?gateId=5', 'projects.json');116 })117 .then(function () {118 casper.evaluate(function () {119 require(['apps/quality-gates/app'], function (App) {120 App.start({ el: '#content', urlRoot: '/pages/base' });121 });122 });123 })124 .then(function () {125 casper.waitForSelector('.select-list-list li');126 })127 .then(function () {128 test.assertElementCount('.select-list-list li', 1);129 test.assertSelectorContains('.select-list-list li', 'SonarQube');130 });131 });132 it('should rename', 2, function (casper, test) {133 return casper134 .start(lib.buildUrl('base#show/1'), function () {135 lib.setDefaultViewport();136 lib.fmock('/api/qualitygates/app', 'app.json');137 lib.fmock('/api/qualitygates/list', 'list.json');138 lib.fmock('/api/qualitygates/show', 'show.json', { data: { id: '1' } });139 lib.fmock('/api/qualitygates/rename', 'rename.json', { data: { id: '1', name: 'New Name' } });140 })141 .then(function () {142 casper.evaluate(function () {143 require(['apps/quality-gates/app'], function (App) {144 App.start({ el: '#content', urlRoot: '/pages/base' });145 });146 jQuery.ajaxSetup({ dataType: 'json' });147 });148 })149 .then(function () {150 casper.waitForSelector('.search-navigator-header-component');151 })152 .then(function () {153 casper.click('#quality-gate-rename');154 casper.waitUntilVisible('#quality-gate-form-name');155 })156 .then(function () {157 casper.evaluate(function () {158 jQuery('#quality-gate-form-name').val('New Name');159 });160 casper.click('.modal-foot button');161 casper.waitForSelectorTextChange('.search-navigator-header-component');162 })163 .then(function () {164 test.assertSelectorContains('.search-navigator-header-component', 'New Name');165 test.assertSelectorContains('.js-list .list-group-item.active', 'New Name');166 });167 });168 it('should copy', 3, function (casper, test) {169 return casper170 .start(lib.buildUrl('base#show/1'), function () {171 lib.setDefaultViewport();172 lib.fmock('/api/qualitygates/app', 'app.json');173 lib.fmock('/api/qualitygates/list', 'list.json');174 lib.fmock('/api/qualitygates/show', 'show.json', { data: { id: '1' } });175 lib.fmock('/api/qualitygates/show', 'show-created.json', { data: { id: '6' } });176 lib.fmock('/api/qualitygates/copy', 'copy.json', { data: { id: '1', name: 'New Name' } });177 })178 .then(function () {179 casper.evaluate(function () {180 require(['apps/quality-gates/app'], function (App) {181 App.start({ el: '#content', urlRoot: '/pages/base' });182 });183 jQuery.ajaxSetup({ dataType: 'json' });184 });185 })186 .then(function () {187 casper.waitForSelector('.search-navigator-header-component');188 })189 .then(function () {190 casper.click('#quality-gate-copy');191 casper.waitUntilVisible('#quality-gate-form-name');192 })193 .then(function () {194 casper.evaluate(function () {195 jQuery('#quality-gate-form-name').val('New Name');196 });197 casper.click('.modal-foot button');198 casper.waitForSelectorTextChange('.search-navigator-header-component');199 })200 .then(function () {201 test.assertSelectorContains('.search-navigator-header-component', 'New Name');202 test.assertSelectorContains('.js-list .list-group-item.active', 'New Name');203 test.assertSelectorContains('.js-list .list-group-item', 'SonarQube way');204 });205 });206 it('should set as default', 4, function (casper, test) {207 return casper208 .start(lib.buildUrl('base#show/5'), function () {209 lib.setDefaultViewport();210 lib.fmock('/api/qualitygates/app', 'app.json');211 lib.fmock('/api/qualitygates/list', 'list.json');212 lib.fmock('/api/qualitygates/show', 'show-another.json', { data: { id: '5' } });213 lib.smock('/api/qualitygates/set_as_default', '{}', { data: { id: '5' } });214 })215 .then(function () {216 casper.evaluate(function () {217 require(['apps/quality-gates/app'], function (App) {218 App.start({ el: '#content', urlRoot: '/pages/base' });219 });220 jQuery.ajaxSetup({ dataType: 'json' });221 });222 })223 .then(function () {224 casper.waitForSelector('.search-navigator-header-component');225 })226 .then(function () {227 test.assertDoesntExist('.js-list .list-group-item.active .badge');228 test.assertDoesntExist('.quality-gate-default-message');229 casper.click('#quality-gate-toggle-default');230 casper.waitForSelector('.js-list .list-group-item.active .badge');231 })232 .then(function () {233 test.assertExists('.quality-gate-default-message');234 test.assertElementCount('.js-list .badge', 1);235 });236 });237 it('should unset as default', 4, function (casper, test) {238 return casper239 .start(lib.buildUrl('base#show/1'), function () {240 lib.setDefaultViewport();241 lib.fmock('/api/qualitygates/app', 'app.json');242 lib.fmock('/api/qualitygates/list', 'list.json');243 lib.fmock('/api/qualitygates/show', 'show.json', { data: { id: '1' } });244 lib.smock('/api/qualitygates/unset_default', '{}', { data: { id: '1' } });245 })246 .then(function () {247 casper.evaluate(function () {248 require(['apps/quality-gates/app'], function (App) {249 App.start({ el: '#content', urlRoot: '/pages/base' });250 });251 jQuery.ajaxSetup({ dataType: 'json' });252 });253 })254 .then(function () {255 casper.waitForSelector('.search-navigator-header-component');256 })257 .then(function () {258 test.assertExists('.js-list .list-group-item.active .badge');259 test.assertExists('.quality-gate-default-message');260 casper.click('#quality-gate-toggle-default');261 casper.waitWhileSelector('.js-list .list-group-item.active .badge');262 })263 .then(function () {264 test.assertDoesntExist('.quality-gate-default-message');265 test.assertDoesntExist('.js-list .badge');266 });267 });268 it('should create', 2, function (casper, test) {269 return casper270 .start(lib.buildUrl('base'), function () {271 lib.setDefaultViewport();272 lib.fmock('/api/qualitygates/app', 'app.json');273 lib.fmock('/api/qualitygates/list', 'list.json');274 lib.smock('/api/qualitygates/create', '{"errors":[{"msg": "error"}]}',275 { status: 400, data: { name: 'Bad' } });276 lib.fmock('/api/qualitygates/create', 'create.json', { data: { name: 'New Name' } });277 lib.fmock('/api/qualitygates/show', 'show-created.json', { data: { id: '6' } });278 })279 .then(function () {280 casper.evaluate(function () {281 require(['apps/quality-gates/app'], function (App) {282 App.start({ el: '#content', urlRoot: '/pages/base' });283 });284 jQuery.ajaxSetup({ dataType: 'json' });285 });286 })287 .then(function () {288 casper.waitForSelector('.js-list .list-group-item');289 })290 .then(function () {291 casper.click('#quality-gate-add');292 casper.waitUntilVisible('#quality-gate-form-name');293 })294 .then(function () {295 casper.evaluate(function () {296 jQuery('#quality-gate-form-name').val('Bad');297 });298 casper.click('.modal-foot button');299 casper.waitForSelector('.alert-danger');300 })301 .then(function () {302 casper.evaluate(function () {303 jQuery('#quality-gate-form-name').val('New Name');304 });305 casper.click('.modal-foot button');306 casper.waitForSelector('.search-navigator-header-component');307 })308 .then(function () {309 test.assertSelectorContains('.search-navigator-header-component', 'New Name');310 test.assertSelectorContains('.js-list .list-group-item.active', 'New Name');311 });312 });313 it('should delete', 2, function (casper, test) {314 return casper315 .start(lib.buildUrl('base#show/5'), function () {316 lib.setDefaultViewport();317 lib.fmock('/api/qualitygates/app', 'app.json');318 lib.fmock('/api/qualitygates/list', 'list.json');319 lib.fmock('/api/qualitygates/show', 'show-another.json', { data: { id: '5' } });320 this.deleteMock = lib.smock('/api/qualitygates/destroy', '{"errors":[{"msg": "error"}]}',321 { status: 400 });322 })323 .then(function () {324 casper.evaluate(function () {325 require(['apps/quality-gates/app'], function (App) {326 App.start({ el: '#content', urlRoot: '/pages/base' });327 });328 jQuery.ajaxSetup({ dataType: 'json' });329 });330 })331 .then(function () {332 casper.waitForSelector('.search-navigator-header-component');333 })334 .then(function () {335 test.assertElementCount('.js-list .list-group-item', 3);336 casper.click('#quality-gate-delete');337 casper.waitForSelector('#delete-gate-submit');338 })339 .then(function () {340 casper.click('#delete-gate-submit');341 casper.waitForSelector('.alert-danger');342 })343 .then(function () {344 lib.clearRequestMock(this.deleteMock);345 lib.smock('/api/qualitygates/destroy', '{}', { data: { id: '5' } });346 casper.click('#delete-gate-submit');347 casper.waitWhileSelector('.search-navigator-header-component');348 })349 .then(function () {350 test.assertElementCount('.js-list .list-group-item', 2);351 });352 });353 it('should add condition', 6, function (casper, test) {354 return casper355 .start(lib.buildUrl('base#show/5'), function () {356 lib.setDefaultViewport();357 lib.fmock('/api/qualitygates/app', 'app.json');358 lib.fmock('/api/qualitygates/list', 'list.json');359 lib.fmock('/api/qualitygates/show', 'show-another.json', { data: { id: '5' } });360 lib.fmock('/api/qualitygates/create_condition', 'create-condition.json',361 { data: { gateId: '5', metric: 'complexity', op: 'GT', period: '1', warning: '3', error: '4' } });362 })363 .then(function () {364 casper.evaluate(function () {365 require(['apps/quality-gates/app'], function (App) {366 App.start({ el: '#content', urlRoot: '/pages/base' });367 });368 jQuery.ajaxSetup({ dataType: 'json' });369 });370 })371 .then(function () {372 casper.waitForSelector('.search-navigator-header-component');373 })374 .then(function () {375 test.assertElementCount('.js-conditions [name="error"]', 0);376 casper.evaluate(function () {377 jQuery('#quality-gate-new-condition-metric').val('complexity').change();378 });379 test.assertElementCount('.js-conditions [name="error"]', 1);380 })381 .then(function () {382 casper.click('.cancel-add-condition');383 casper.waitWhileSelector('.cancel-add-condition');384 })385 .then(function () {386 test.assertElementCount('.js-conditions [name="error"]', 0);387 casper.evaluate(function () {388 jQuery('#quality-gate-new-condition-metric').val('complexity').change();389 });390 test.assertElementCount('.js-conditions [name="error"]', 1);391 casper.evaluate(function () {392 jQuery('[name="period"]').val('1');393 jQuery('[name="operator"]').val('GT');394 jQuery('[name="warning"]').val('3');395 jQuery('[name="error"]').val('4');396 });397 casper.click('.add-condition');398 casper.waitForSelector('.update-condition');399 })400 .then(function () {401 test.assertExists('.update-condition[disabled]');402 test.assertExists('.delete-condition');403 });404 });405 it('should update condition', 3, function (casper, test) {406 return casper407 .start(lib.buildUrl('base#show/1'), function () {408 lib.setDefaultViewport();409 lib.fmock('/api/qualitygates/app', 'app.json');410 lib.fmock('/api/qualitygates/list', 'list.json');411 lib.fmock('/api/qualitygates/show', 'show.json', { data: { id: '1' } });412 lib.fmock('/api/qualitygates/update_condition', 'update-condition.json',413 { data: { id: '1', warning: '173' } });414 })415 .then(function () {416 casper.evaluate(function () {417 require(['apps/quality-gates/app'], function (App) {418 App.start({ el: '#content', urlRoot: '/pages/base' });419 });420 jQuery.ajaxSetup({ dataType: 'json' });421 });422 })423 .then(function () {424 casper.waitForSelector('.update-condition');425 })426 .then(function () {427 test.assertExists('.js-conditions tr:first-child .update-condition[disabled]');428 casper.evaluate(function () {429 jQuery('.js-conditions tr:first-child [name="warning"]').val('173').change();430 });431 test.assertDoesntExist('.js-conditions tr:first-child .update-condition[disabled]');432 casper.click('.js-conditions tr:first-child .update-condition');433 casper.waitWhileSelector('.js-conditions tr:first-child .update-condition:not([disabled])');434 })435 .then(function () {436 test.assertExists('.js-conditions tr:first-child .update-condition[disabled]');437 });438 });439 it('should delete condition', 1, function (casper, test) {440 return casper441 .start(lib.buildUrl('base#show/1'), function () {442 lib.setDefaultViewport();443 lib.fmock('/api/qualitygates/app', 'app.json');444 lib.fmock('/api/qualitygates/list', 'list.json');445 lib.fmock('/api/qualitygates/show', 'show.json', { data: { id: '1' } });446 this.deleteMock = lib.smock('/api/qualitygates/delete_condition', '{"errors":[{"msg": "error"}]}',447 { status: 400 });448 })449 .then(function () {450 casper.evaluate(function () {451 require(['apps/quality-gates/app'], function (App) {452 App.start({ el: '#content', urlRoot: '/pages/base' });453 });454 jQuery.ajaxSetup({ dataType: 'json' });455 });456 })...
update-center-spec.js
Source:update-center-spec.js
...3describe('Update Center App', function () {4 it('should show plugin card', 16, function (casper, test) {5 return casper6 .start(lib.buildUrl('base#installed'), function () {7 lib.setDefaultViewport();8 lib.fmock('/api/plugins/installed', 'installed.json');9 lib.fmock('/api/plugins/updates', 'updates.json');10 lib.fmock('/api/plugins/pending', 'pending.json');11 })12 .then(function () {13 casper.evaluate(function () {14 require(['apps/update-center/app'], function (App) {15 App.start({ el: '#content', urlRoot: '/pages/base' });16 });17 });18 })19 .then(function () {20 casper.waitForSelector('.js-plugin-name');21 })22 .then(function () {23 test.assertElementCount('li[data-id]', 5);24 test.assertSelectorContains('li[data-id="scmgit"] .js-plugin-name', 'Git');25 test.assertSelectorContains('li[data-id="scmgit"] .js-plugin-category', 'Integration');26 test.assertSelectorContains('li[data-id="scmgit"] .js-plugin-description', 'Git SCM Provider.');27 test.assertSelectorContains('li[data-id="scmgit"] .js-plugin-installed-version', '1.0');28 test.assertElementCount('li[data-id="scmgit"] .js-update-version', 1);29 test.assertSelectorContains('li[data-id="scmgit"] .js-update-version', '1.1');30 test.assertElementCount('li[data-id="scmgit"] .js-changelog', 1);31 test.assertElementCount('li[data-id="scmgit"] .js-plugin-homepage', 1);32 test.assertElementCount('li[data-id="scmgit"] .js-plugin-issues', 1);33 test.assertDoesntExist('li[data-id="scmgit"] .js-plugin-terms');34 test.assertSelectorContains('li[data-id="scmgit"] .js-plugin-license', 'GNU LGPL 3');35 test.assertSelectorContains('li[data-id="scmgit"] .js-plugin-organization', 'SonarSource');36 test.assertElementCount('li[data-id="scmgit"] .js-update', 1);37 test.assertElementCount('li[data-id="scmgit"] .js-uninstall', 1);38 test.assertDoesntExist('li[data-id="scmgit"] .js-install');39 });40 });41 it('should show system update', 8, function (casper, test) {42 return casper43 .start(lib.buildUrl('base#updates'), function () {44 lib.setDefaultViewport();45 lib.fmock('/api/plugins/installed', 'installed.json');46 lib.fmock('/api/plugins/updates', 'updates.json');47 lib.fmock('/api/plugins/pending', 'pending.json');48 lib.fmock('/api/system/upgrades', 'system-updates.json');49 })50 .then(function () {51 casper.evaluate(function () {52 require(['apps/update-center/app'], function (App) {53 App.start({ el: '#content', urlRoot: '/pages/base' });54 });55 });56 })57 .then(function () {58 casper.waitForSelector('.js-plugin-name');59 })60 .then(function () {61 test.assertElementCount('li[data-system]', 1);62 test.assertSelectorContains('li[data-system] .js-plugin-name', 'SonarQube 5.3');63 test.assertSelectorContains('li[data-system] .js-plugin-category', 'System Update');64 test.assertSelectorContains('li[data-system] .js-plugin-description', 'New!');65 test.assertElementCount('li[data-system] .js-plugin-release-notes', 1);66 test.assertElementCount('li[data-system] .js-plugin-date', 1);67 test.assertElementCount('li[data-system] .js-plugin-update-steps', 1);68 test.assertElementCount('li[data-system] .js-plugin-update-steps > li', 4);69 });70 });71 it('should show installed', 3, function (casper, test) {72 return casper73 .start(lib.buildUrl('base#installed'), function () {74 lib.setDefaultViewport();75 lib.fmock('/api/plugins/installed', 'installed.json');76 lib.fmock('/api/plugins/updates', 'updates.json');77 lib.fmock('/api/plugins/pending', 'pending.json');78 })79 .then(function () {80 casper.evaluate(function () {81 require(['apps/update-center/app'], function (App) {82 App.start({ el: '#content', urlRoot: '/pages/base' });83 });84 });85 })86 .then(function () {87 casper.waitForSelector('.js-plugin-name');88 })89 .then(function () {90 test.assertElementCount('li[data-id]', 5);91 test.assertExists('li[data-id="scmgit"]');92 test.assertExists('li[data-id="javascript"]');93 });94 });95 it('should show updates', 3, function (casper, test) {96 return casper97 .start(lib.buildUrl('base#updates'), function () {98 lib.setDefaultViewport();99 lib.fmock('/api/plugins/installed', 'installed.json');100 lib.fmock('/api/plugins/updates', 'updates.json');101 lib.fmock('/api/plugins/pending', 'pending.json');102 lib.fmock('/api/system/upgrades', 'system-updates.json');103 })104 .then(function () {105 casper.evaluate(function () {106 require(['apps/update-center/app'], function (App) {107 App.start({ el: '#content', urlRoot: '/pages/base' });108 });109 });110 })111 .then(function () {112 casper.waitForSelector('.js-plugin-name');113 })114 .then(function () {115 test.assertElementCount('li[data-id]', 4);116 test.assertExists('li[data-id="scmgit"]');117 test.assertDoesntExist('li[data-id="javascript"]');118 });119 });120 it('should show available', 3, function (casper, test) {121 return casper122 .start(lib.buildUrl('base#available'), function () {123 lib.setDefaultViewport();124 lib.fmock('/api/plugins/available', 'available.json');125 lib.fmock('/api/plugins/pending', 'pending.json');126 })127 .then(function () {128 casper.evaluate(function () {129 require(['apps/update-center/app'], function (App) {130 App.start({ el: '#content', urlRoot: '/pages/base' });131 });132 });133 })134 .then(function () {135 casper.waitForSelector('.js-plugin-name');136 })137 .then(function () {138 test.assertElementCount('li[data-id]', 3);139 test.assertDoesntExist('li[data-id="scmgit"]');140 test.assertExists('li[data-id="abap"]');141 });142 });143 it('should switch between views', 18, function (casper, test) {144 return casper145 .start(lib.buildUrl('base#installed'), function () {146 lib.setDefaultViewport();147 lib.fmock('/api/plugins/installed', 'installed.json');148 lib.fmock('/api/plugins/updates', 'updates.json');149 lib.fmock('/api/plugins/pending', 'pending.json');150 lib.fmock('/api/plugins/available', 'available.json');151 lib.fmock('/api/system/upgrades', 'system-updates.json');152 })153 .then(function () {154 casper.evaluate(function () {155 require(['apps/update-center/app'], function (App) {156 App.start({ el: '#content', urlRoot: '/pages/base' });157 });158 });159 })160 .then(function () {161 casper.waitForSelector('.js-plugin-name');162 })163 .then(function () {164 test.assertElementCount('li[data-id]', 5);165 test.assertExists('li[data-id="javascript"]');166 test.assertExists('#update-center-filter-installed:checked');167 casper.click('#update-center-filter-available');168 casper.waitForSelector('li[data-id="abap"]');169 })170 .then(function () {171 test.assertElementCount('li[data-id]', 3);172 test.assertExists('li[data-id="abap"]');173 test.assertExists('#update-center-filter-available:checked');174 casper.click('#update-center-filter-updates');175 casper.waitForSelector('li[data-id="scmgit"]');176 })177 .then(function () {178 test.assertElementCount('li[data-id]', 4);179 test.assertExists('li[data-id="scmgit"]');180 test.assertExists('#update-center-filter-updates:checked');181 casper.click('#update-center-filter-installed');182 casper.waitForSelector('li[data-id="javascript"]');183 })184 .then(function () {185 test.assertElementCount('li[data-id]', 5);186 test.assertExists('li[data-id="javascript"]');187 test.assertExists('#update-center-filter-installed:checked');188 casper.click('#update-center-filter-available');189 casper.waitForSelector('li[data-id="abap"]');190 })191 .then(function () {192 test.assertElementCount('li[data-id]', 3);193 test.assertExists('li[data-id="abap"]');194 test.assertExists('#update-center-filter-available:checked');195 casper.click('#update-center-filter-updates');196 casper.waitForSelector('li[data-id="scmgit"]');197 })198 .then(function () {199 test.assertElementCount('li[data-id]', 4);200 test.assertExists('li[data-id="scmgit"]');201 test.assertExists('#update-center-filter-updates:checked');202 });203 });204 it('should search', 5, function (casper, test) {205 return casper206 .start(lib.buildUrl('base#installed'), function () {207 lib.setDefaultViewport();208 lib.fmock('/api/plugins/installed', 'installed.json');209 lib.fmock('/api/plugins/updates', 'updates.json');210 lib.fmock('/api/plugins/pending', 'pending.json');211 })212 .then(function () {213 casper.evaluate(function () {214 require(['apps/update-center/app'], function (App) {215 App.start({ el: '#content', urlRoot: '/pages/base' });216 });217 });218 })219 .then(function () {220 casper.waitForSelector('.js-plugin-name');221 })222 .then(function () {223 test.assertElementCount('li[data-id]', 5);224 test.assertDoesntExist('li.hidden[data-id]');225 casper.evaluate(function () {226 jQuery('#update-center-search-query').val('jA');227 });228 casper.click('#update-center-search-submit');229 casper.waitForSelector('li.hidden[data-id]');230 })231 .then(function () {232 test.assertElementCount('li[data-id]', 5);233 test.assertElementCount('li.hidden[data-id]', 3);234 test.assertSelectorContains('li:not(.hidden)[data-id] .js-plugin-name', 'JavaScript');235 });236 });237 it('should show plugin changelog', 4, function (casper, test) {238 return casper239 .start(lib.buildUrl('base#installed'), function () {240 lib.setDefaultViewport();241 lib.fmock('/api/plugins/installed', 'installed.json');242 lib.fmock('/api/plugins/updates', 'updates.json');243 lib.fmock('/api/plugins/pending', 'pending.json');244 })245 .then(function () {246 casper.evaluate(function () {247 require(['apps/update-center/app'], function (App) {248 App.start({ el: '#content', urlRoot: '/pages/base' });249 });250 });251 })252 .then(function () {253 casper.waitForSelector('.js-plugin-name');254 })255 .then(function () {256 casper.click('li[data-id="python"] .js-changelog');257 casper.waitForSelector('.bubble-popup');258 })259 .then(function () {260 test.assertElementCount('.bubble-popup .js-plugin-changelog-version', 2);261 test.assertElementCount('.bubble-popup .js-plugin-changelog-date', 2);262 test.assertElementCount('.bubble-popup .js-plugin-changelog-link', 2);263 test.assertElementCount('.bubble-popup .js-plugin-changelog-description', 2);264 });265 });266 it('should update plugin', 1, function (casper, test) {267 return casper268 .start(lib.buildUrl('base'), function () {269 lib.setDefaultViewport();270 lib.fmock('/api/plugins/installed', 'installed.json');271 lib.fmock('/api/plugins/updates', 'updates.json');272 lib.fmock('/api/plugins/pending', 'pending.json');273 lib.smock('/api/plugins/update', '{}', { data: { key: 'scmgit' } });274 })275 .then(function () {276 casper.evaluate(function () {277 require(['apps/update-center/app'], function (App) {278 App.start({ el: '#content', urlRoot: '/pages/base' });279 });280 });281 })282 .then(function () {283 casper.waitForSelector('.js-plugin-name');284 })285 .then(function () {286 casper.click('li[data-id="scmgit"] .js-update');287 casper.waitWhileSelector('li[data-id="scmgit"] .js-spinner');288 })289 .then(function () {290 test.assertSelectorContains('li[data-id="scmgit"]', 'To Be Installed');291 });292 });293 it('should uninstall plugin', 1, function (casper, test) {294 return casper295 .start(lib.buildUrl('base'), function () {296 lib.setDefaultViewport();297 lib.fmock('/api/plugins/installed', 'installed.json');298 lib.fmock('/api/plugins/updates', 'updates.json');299 lib.fmock('/api/plugins/pending', 'pending.json');300 lib.smock('/api/plugins/uninstall', '{}', { data: { key: 'scmgit' } });301 })302 .then(function () {303 casper.evaluate(function () {304 require(['apps/update-center/app'], function (App) {305 App.start({ el: '#content', urlRoot: '/pages/base' });306 });307 });308 })309 .then(function () {310 casper.waitForSelector('.js-plugin-name');311 })312 .then(function () {313 casper.click('li[data-id="scmgit"] .js-uninstall');314 casper.waitWhileSelector('li[data-id="scmgit"] .js-spinner');315 })316 .then(function () {317 test.assertSelectorContains('li[data-id="scmgit"]', 'To Be Uninstalled');318 });319 });320 it('should install plugin', 1, function (casper, test) {321 return casper322 .start(lib.buildUrl('base#available'), function () {323 lib.setDefaultViewport();324 lib.fmock('/api/plugins/available', 'available.json');325 lib.fmock('/api/plugins/pending', 'pending.json');326 lib.smock('/api/plugins/install', '{}', { data: { key: 'abap' } });327 })328 .then(function () {329 casper.evaluate(function () {330 require(['apps/update-center/app'], function (App) {331 App.start({ el: '#content', urlRoot: '/pages/base' });332 });333 });334 })335 .then(function () {336 casper.waitForSelector('.js-plugin-name');337 })338 .then(function () {339 casper.click('li[data-id="abap"] .js-install');340 casper.waitWhileSelector('li[data-id="abap"] .js-spinner');341 })342 .then(function () {343 test.assertSelectorContains('li[data-id="abap"]', 'To Be Installed');344 });345 });346 it('should cancel all pending', 1, function (casper, test) {347 return casper348 .start(lib.buildUrl('base#available'), function () {349 lib.setDefaultViewport();350 lib.fmock('/api/plugins/available', 'available.json');351 lib.fmock('/api/plugins/pending', 'pending.json');352 lib.smock('/api/plugins/cancel_all', '{}');353 })354 .then(function () {355 casper.evaluate(function () {356 require(['apps/update-center/app'], function (App) {357 App.start({ el: '#content', urlRoot: '/pages/base' });358 });359 });360 })361 .then(function () {362 casper.waitForSelector('.js-plugin-name');363 })...
Target.js
Source:Target.js
1const Page = require('./Page');2const {helper} = require('./helper');3class Target {4 /**5 * @param {!Puppeteer.TargetInfo} targetInfo6 * @param {!Puppeteer.Browser} browser7 * @param {!function():!Promise<!Puppeteer.CDPSession>} sessionFactory8 * @param {boolean} ignoreHTTPSErrors9 * @param {boolean} setDefaultViewport10 * @param {!Puppeteer.TaskQueue} screenshotTaskQueue11 */12 constructor(targetInfo, browser, sessionFactory, ignoreHTTPSErrors, setDefaultViewport, screenshotTaskQueue) {13 this._targetInfo = targetInfo;14 this._browser = browser;15 this._targetId = targetInfo.targetId;16 this._sessionFactory = sessionFactory;17 this._ignoreHTTPSErrors = ignoreHTTPSErrors;18 this._setDefaultViewport = setDefaultViewport;19 this._screenshotTaskQueue = screenshotTaskQueue;20 /** @type {?Promise<!Puppeteer.Page>} */21 this._pagePromise = null;22 this._initializedPromise = new Promise(fulfill => this._initializedCallback = fulfill);23 this._isClosedPromise = new Promise(fulfill => this._closedCallback = fulfill);24 this._isInitialized = this._targetInfo.type !== 'page' || this._targetInfo.url !== '';25 if (this._isInitialized)26 this._initializedCallback(true);27 }28 /**29 * @return {!Promise<!Puppeteer.CDPSession>}30 */31 createCDPSession() {32 return this._sessionFactory();33 }34 /**35 * @return {!Promise<?Page>}36 */37 async page() {38 if (this._targetInfo.type === 'page' && !this._pagePromise) {39 this._pagePromise = this._sessionFactory()40 .then(client => Page.create(client, this, this._ignoreHTTPSErrors, this._setDefaultViewport, this._screenshotTaskQueue));41 }42 return this._pagePromise;43 }44 /**45 * @return {string}46 */47 url() {48 return this._targetInfo.url;49 }50 /**51 * @return {"page"|"service_worker"|"other"|"browser"}52 */53 type() {54 const type = this._targetInfo.type;55 if (type === 'page' || type === 'service_worker' || type === 'browser')56 return type;57 return 'other';58 }59 /**60 * @return {!Puppeteer.Browser}61 */62 browser() {63 return this._browser;64 }65 /**66 * @param {!Puppeteer.TargetInfo} targetInfo67 */68 _targetInfoChanged(targetInfo) {69 this._targetInfo = targetInfo;70 if (!this._isInitialized && (this._targetInfo.type !== 'page' || this._targetInfo.url !== '')) {71 this._isInitialized = true;72 this._initializedCallback(true);73 return;74 }75 }76}77helper.tracePublicAPI(Target);...
DeckGLMap.js
Source:DeckGLMap.js
...24 // bounds && setBounds(bounds);25 // }, [bounds, setBounds]);26 // update default viewport on set27 useEffect(() => {28 initialViewport && setDefaultViewport(initialViewport);29 }, [initialViewport, setDefaultViewport]);30 // update the viewport in state on change31 const handleViewportChange = (e) => {32 return setViewport(e.viewState);33 };34 return (35 <DeckGL36 ref={ref}37 viewState={viewport}38 onViewStateChange={handleViewportChange}39 controller={true}40 {...props}41 >42 {children}...
index.js
Source:index.js
1import { Transform } from './transform.js';2import calculateTransform from './calculateTransform.js';3import drawImage from './drawImage.js';4import generateLut from './generateLut.js';5import getDefaultViewport from './getDefaultViewport.js';6import getTransform from './getTransform.js';7import requestAnimationFrame from './requestAnimationFrame.js';8import setDefaultViewport from './setDefaultViewport.js';9import storedColorPixelDataToCanvasImageData from './storedColorPixelDataToCanvasImageData.js';10import storedPixelDataToCanvasImageData from './storedPixelDataToCanvasImageData.js';11import storedPixelDataToCanvasImageDataColorLUT from './storedPixelDataToCanvasImageDataColorLUT.js';12import storedPixelDataToCanvasImageDataPseudocolorLUT from './storedPixelDataToCanvasImageDataPseudocolorLUT.js';13import storedPixelDataToCanvasImageDataRGBA from './storedPixelDataToCanvasImageDataRGBA.js';14/**15 * @module Internal16 */17export default {18 drawImage,19 generateLut,20 getDefaultViewport,21 requestAnimationFrame,22 setDefaultViewport,23 storedPixelDataToCanvasImageData,24 storedPixelDataToCanvasImageDataRGBA,25 storedPixelDataToCanvasImageDataColorLUT,26 storedPixelDataToCanvasImageDataPseudocolorLUT,27 storedColorPixelDataToCanvasImageData,28 getTransform,29 calculateTransform,30 Transform...
setDefaultViewport_test.js
Source:setDefaultViewport_test.js
...5 beforeEach(function () {6 state.viewport = {};7 });8 it('should default to an empty object if no value is provided', function () {9 setDefaultViewport();10 const currentDefaultViewport = state.viewport;11 const expectedDefaultViewport = {};12 expect(currentDefaultViewport).to.deep.equal(expectedDefaultViewport);13 });14 it('should equal the value of the provided object', function () {15 const exampleViewportDefaults = {16 pixelReplication: true,17 someOtherProperty: 'hello'18 };19 setDefaultViewport(exampleViewportDefaults);20 const currentDefaultViewport = state.viewport;21 const expectedDefaultViewport = exampleViewportDefaults;22 expect(currentDefaultViewport).to.deep.equal(expectedDefaultViewport);23 });...
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 for (const browserType of ['chromium', 'firefox', 'webkit']) {4 const browser = await playwright[browserType].launch();5 const context = await browser.newContext();6 await context.setDefaultViewport({width: 500, height: 500});7 const page = await context.newPage();8 await page.screenshot({ path: `example-${browserType}.png` });9 await browser.close();10 }11})();12- `setExtraHTTPHeaders(headers)`13const playwright = require('playwright');14(async () => {15 const browser = await playwright.chromium.launch();16 const context = await browser.newContext();17 await context.setExtraHTTPHeaders({18 });19 const page = await context.newPage();20 await page.screenshot({ path: `example.png` });21 await browser.close();22})();23- `setGeolocation(options)`24const playwright = require('playwright');25(async () => {26 const browser = await playwright.chromium.launch();27 const context = await browser.newContext();28 await context.setGeolocation({ longitude: 12.492507, latitude: 41.889938 });29 const page = await context.newPage();
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 for (const browserType of BROWSER) {4 const browser = await playwright[browserType].launch({headless: false});5 const context = await browser.newContext();6 await context.setDefaultViewport({ width: 1920, height: 1080 });7 const page = await context.newPage();8 await page.screenshot({ path: `example-${browserType}.png` });9 await browser.close();10 }11})();12const playwright = require('playwright');13(async () => {14 for (const browserType of BROWSER) {15 const browser = await playwright[browserType].launch({headless: false});16 const context = await browser.newContext();17 const page = await context.newPage();18 await page.setViewportSize({ width: 1920, height: 1080 });19 await page.screenshot({ path: `example-${browserType}.png` });20 await browser.close();21 }22})();23const playwright = require('playwright');24(async () => {25 for (const browserType of BROWSER) {26 const browser = await playwright[browserType].launch({headless: false});27 const context = await browser.newContext();28 const page = await context.newPage();29 await page.emulate({ viewport: { width: 1920, height: 1080 }, userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36' });30 await page.screenshot({ path: `example-${browserType}.png` });31 await browser.close();32 }33})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext({ viewport: null });5 const page = await context.newPage();6 await page.screenshot({ path: 'example.png' });7 await browser.close();8})();9const { chromium } = require('playwright');10(async () => {11 const browser = await chromium.launch();12 const context = await browser.newContext({ viewport: { width: 1280, height: 720 } });13 const page = await context.newPage();14 await page.screenshot({ path: 'example.png' });15 await browser.close();16})();17const { chromium } = require('playwright');18(async () => {19 const browser = await chromium.launch();20 const context = await browser.newContext({ viewport: null });21 const page = await context.newPage();22 await page.screenshot({ path: 'example.png' });23 await browser.close();24})();25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch();28 const context = await browser.newContext({ viewport: { width: 1280, height: 720 } });29 const page = await context.newPage();30 await page.screenshot({ path: 'example.png' });31 await browser.close();32})();33const { chromium } = require('playwright');34(async () => {35 const browser = await chromium.launch();36 const context = await browser.newContext({ viewport: null });37 const page = await context.newPage();38 await page.screenshot({ path: 'example.png' });39 await browser.close();40})();41const { chromium } =
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const browser = await playwright.chromium.launch();4 const context = await browser.newContext({ viewport: null });5 const page = await context.newPage();6 await page.screenshot({ path: 'example.png' });7 await browser.close();8})();9const playwright = require('playwright');10(async () => {11 const browser = await playwright.chromium.launch();12 const context = await browser.newContext({ deviceScaleFactor: 2 });13 const page = await context.newPage();14 await page.screenshot({ path: 'example.png' });15 await browser.close();16})();17const playwright = require('playwright');18(async () => {19 const browser = await playwright.chromium.launch();20 const context = await browser.newContext({ isMobile: true });21 const page = await context.newPage();22 await page.screenshot({ path: 'example.png' });23 await browser.close();24})();25const playwright = require('playwright');26(async () => {27 const browser = await playwright.chromium.launch();28 const context = await browser.newContext({ hasTouch: true });29 const page = await context.newPage();30 await page.goto('https
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const browser = await playwright.chromium.launch();4 const context = await browser.newContext({5 viewport: {6 },7 });8 const page = await context.newPage();9 await browser.close();10})();11const playwright = require('playwright');12(async () => {13 const browser = await playwright.chromium.launch();14 const context = await browser.newContext({15 viewport: {16 },17 });18 const page = await context.newPage();19 await browser.close();20})();21const playwright = require('playwright');22test.use({23 viewport: {24 },25});26test('test', async ({ page }) => {27});28const playwright = require('playwright');29(async () => {30 const browser = await playwright.chromium.launch();31 const context = await browser.launchPersistentContext('data-path', {32 viewport: {33 },34 });35 const page = await context.newPage();36 await browser.close();37})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({headless: false});4 const page = await browser.newPage({viewport: null});5 await page.screenshot({ path: 'example.png' });6 await browser.close();7})();8const { chromium } = require('playwright');9(async () => {10 const browser = await chromium.launch({headless: false});11 const page = await browser.newPage({viewport: null});12 await page.setViewportSize({width: 500, height: 500});13 await page.screenshot({ path: 'example.png' });14 await browser.close();15})();16const { chromium } = require('playwright');17(async () => {18 const browser = await chromium.launch({headless: false});19 const page = await browser.newPage({viewport: null});20 await page.emulate({viewport: {width: 500, height: 500}});21 await page.screenshot({ path: 'example.png' });22 await browser.close();23})();24const { chromium } = require('playwright');25(async () => {26 const browser = await chromium.launch({headless: false});27 const page = await browser.newPage({viewport: null});28 await page.setExtraHTTPHeaders({ 'viewport-width': 500, 'viewport-height': 500 });29 await page.screenshot({ path: 'example.png' });30 await browser.close();31})();32const { chromium } = require('play
Using AI Code Generation
1await page.setDefaultViewport({ width: 1920, height: 1080 });2await page.setViewportSize({ width: 1920, height: 1080 });3await page.emulateViewportSize({ width: 1920, height: 1080 });4await page.emulateMedia({ colorScheme: 'dark' });5await page.emulateMediaFeatures([6 { name: 'prefers-color-scheme', value: 'dark' },7]);8await page.emulateTimezone('America/Los_Angeles');9await page.emulate({10 viewport: { width: 1920, height: 1080 },11 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36',12});13await page.emulateMedia({ colorScheme: 'dark' });14await page.emulateMediaFeatures([15 { name: 'prefers-color-scheme', value: 'dark' },16]);17await page.emulateTimezone('America/Los_Angeles');18await page.emulate({19 viewport: { width: 1920, height: 1080 },20 'Mozilla/5.0 (
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext({ viewport: { width: 1920, height: 1080 } });5 const page = await context.newPage();6 await browser.close();7})();8const { chromium } = require('playwright');9(async () => {10 const browser = await chromium.launch();11 const context = await browser.newContext();12 const page = await context.newPage();13 await page.setDefaultViewport({ width: 1920, height: 1080 });14 await browser.close();15})();16const { chromium } = require('playwright');17(async () => {18 const browser = await chromium.launch();19 const context = await browser.newContext();20 const page = await context.newPage();21 await page.setViewportSize({ width: 1920, height: 1080 });22 await browser.close();23})();24const { chromium } = require('playwright');25(async () => {26 const browser = await chromium.launch();27 const context = await browser.newContext();28 const page = await context.newPage();29 await page.setViewportSize({ width: 1920, height: 1080 });30 await browser.close();31})();32const { chromium } = require('playwright');33(async () => {34 const browser = await chromium.launch();35 const context = await browser.newContext();
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!