Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(948)

Unified Diff: appengine/config_service/ui/test/config-ui/config-set_test.html

Issue 2959833002: config_service: add last import validation and tests (Closed)
Patch Set: Add tests for config-set page and front-page. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/config_service/ui/test/config-ui/config-set_test.html
diff --git a/appengine/config_service/ui/test/config-ui/config-set_test.html b/appengine/config_service/ui/test/config-ui/config-set_test.html
new file mode 100644
index 0000000000000000000000000000000000000000..a4b4128396762bb2ea4962fdd31c3490166e3e65
--- /dev/null
+++ b/appengine/config_service/ui/test/config-ui/config-set_test.html
@@ -0,0 +1,186 @@
+<!--
+ Copyright 2017 The LUCI Authors. All rights reserved.
+ Use of this source code is governed under the Apache License, Version 2.0
+ that can be found in the LICENSE file.
+-->
+
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
+
+ <title>config-set test</title>
+
+ <script src="../../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
+ <script src="../../bower_components/web-component-tester/browser.js"></script>
+
+ <link rel="import" href="../../src/config-ui/config-set.html">
+ </head>
+ <body>
+
+ <test-fixture id="valid-project-with-config-files">
+ <template>
+ <config-set category="projects"
+ name="valid-project-with-config-files"></config-set>
+ </template>
+ </test-fixture>
+
+ <test-fixture id="invalid-project-without-config-files">
+ <template>
+ <config-set category="projects"
+ name="invalid-project-without-config-files"></config-set>
+ </template>
+ </test-fixture>
+
+ <script>
+ suite('Valid project with config files:' +
+ '- has correct category' +
+ '- has correct name' +
+ '- contains 2 config files' +
+ '- sets isLoading by default' +
+ '- has valid last import attempt', function() {
+
+ var ajax;
+ var request;
+ var server;
+ var responseHeaders = {
+ json: { 'Content-Type': 'application/json' }
+ };
+ var config_set;
+
+ setup(function() {
+ server = sinon.fakeServer.create();
+ server.respondWith(
+ 'GET',
+ /\/_ah\/api\/config\/v1\/config-sets\?config_set=([a-z\-]+)%2F([a-z\-]+)&include_files=true&include_last_import_attempt=true/,
+ [
+ 200,
+ responseHeaders.json,
+ '{"event": ' +
Ryan Tseng 2017/07/10 19:37:01 Just build a normal object and then use JSON.strin
ayanaadylova 2017/07/10 20:33:34 Done. It includes a javascript event object becau
+ '{"detail": ' +
+ '{"response": ' +
+ '{"config_sets": [ ' +
+ '{"files": ' +
+ '[{"path": "OWNERS"}, ' +
+ '{"path": "README.md"}], ' +
+ '"location": "https://chromium.googlesource.com/valid-project-with-config-files", ' +
+ '"last_import_attempt": {"success": true} ' +
+ '}] ' +
+ '} ' +
+ '} ' +
+ '} ' +
+ '} '
+ ]
+ );
+ config_set = fixture('valid-project-with-config-files');
+ ajax = Polymer.dom(config_set.root).querySelector('iron-ajax');
+ });
+
+ teardown(function() {
+ server.restore();
+ });
+
+ test('checks the category of config set', function() {
+ assert.equal(config_set.category, 'projects');
+ });
+
+ test('checks the name of config set', function() {
+ assert.equal(config_set.name, 'valid-project-with-config-files');
+ });
+
+ test('checks that isLoading property is true by default', function() {
+ assert.equal(config_set.isLoading, true);
+ });
+
+ test('gets iron-ajax response', function () {
+ request = ajax.generateRequest();
+ server.respond();
+ expect(request.response).to.be.ok;
+ expect(request.response).to.be.an('object');
+ expect(request.response.event).to.be.an('object');
+ config_set._onGotConfigFiles(request.response.event);
Ryan Tseng 2017/07/10 19:37:01 Doesn't this get triggered twice then? Once when i
ayanaadylova 2017/07/10 20:33:34 I thought it will trigger when when iron-ajax comp
+ assert.equal(config_set.isLoading, false);
+ assert.equal(config_set.files.length, 2);
+ assert.equal(config_set.lastImportAttempt.success, true);
+ assert.equal(config_set.location,
+ "https://chromium.googlesource.com/valid-project-with-config-files");
+ });
+
+ });
+
+ suite('Inalid project without config files:' +
+ '- has correct category' +
+ '- has correct name' +
+ '- contains 0 config files' +
+ '- sets isLoading by default' +
+ '- has invalid last import attempt', function() {
+ var ajax;
+ var request;
+ var server;
+ var responseHeaders = {
+ json: { 'Content-Type': 'application/json' }
+ };
+ var config_set;
+
+ setup(function() {
+ server = sinon.fakeServer.create();
+ server.respondWith(
+ 'GET',
+ /\/_ah\/api\/config\/v1\/config-sets\?config_set=([a-z\-]+)%2F([a-z\-]+)&include_files=true&include_last_import_attempt=true/,
+ [
+ 200,
+ responseHeaders.json,
+ '{"event": ' +
+ '{"detail": ' +
+ '{"response": ' +
+ '{"config_sets": [ ' +
+ '{' +
+ '"location": "https://chromium.googlesource.com/invalid-project-without-config-files", ' +
+ '"last_import_attempt": {"success": false} ' +
+ '}] ' +
+ '} ' +
+ '} ' +
+ '} ' +
+ '} '
+ ]
+ );
+ config_set = fixture('invalid-project-without-config-files');
+ ajax = Polymer.dom(config_set.root).querySelector('iron-ajax');
+ });
+
+ teardown(function() {
+ server.restore();
+ });
+
+ test('checks the category of config set', function() {
+ assert.equal(config_set.category, 'projects');
+ });
+
+ test('checks the name of config set', function() {
+ assert.equal(config_set.name, 'invalid-project-without-config-files');
+ });
+
+ test('checks that isLoading property is true by default', function() {
+ assert.equal(config_set.isLoading, true);
+ });
+
+ test('gets iron-ajax response', function () {
+ request = ajax.generateRequest();
+ server.respond();
+ expect(request.response).to.be.ok;
+ expect(request.response).to.be.an('object');
+ expect(request.response.event).to.be.an('object');
+ config_set._onGotConfigFiles(request.response.event);
+ assert.equal(config_set.isLoading, false);
+ assert.equal(config_set.files.length, 0);
+ assert.equal(config_set.lastImportAttempt.success, false);
+ assert.equal(config_set.location,
+ "https://chromium.googlesource.com/invalid-project-without-config-files");
+ });
+
+ });
+
+ </script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698