moved naming patterns to seperate module and Angular constant

This commit is contained in:
alecmerdler 2017-01-19 01:48:15 -08:00
parent c55e9f2d12
commit 8a9a2972ec
9 changed files with 262 additions and 256 deletions

View file

@ -29,11 +29,12 @@ module.exports = function(config) {
// Application resources // Application resources
'static/js/quay.module.ts', 'static/js/quay.module.ts',
'static/js/**/*.js', // 'static/js/**/*.js',
// Tests // Tests
'static/test/**/*.js', 'static/test/**/*.js',
'static/js/**/*spec.ts', 'static/js/**/*.spec.js',
'static/js/**/*.spec.ts',
], ],
exclude: [ exclude: [
'static/js/build/bundle.js', 'static/js/build/bundle.js',
@ -41,7 +42,8 @@ module.exports = function(config) {
preprocessors: { preprocessors: {
'static/lib/ngReact/react.ngReact.min.js': ['webpack'], 'static/lib/ngReact/react.ngReact.min.js': ['webpack'],
'static/lib/angular-moment.min.js': ['webpack'], 'static/lib/angular-moment.min.js': ['webpack'],
'static/js/**/*.ts': ['webpack'], 'static/js/quay.module.ts': ['webpack'],
'static/js/**/*.spec.ts': ['webpack'],
}, },
webpack: { webpack: {
resolve: webpackConfig.resolve, resolve: webpackConfig.resolve,

View file

@ -1,3 +0,0 @@
var TEAM_PATTERN = '^[a-z][a-z0-9]+$';
var ROBOT_PATTERN = '^[a-z][a-z0-9_]{3,29}$';
var USERNAME_PATTERN = '^(?=.{4,30}$)([a-z0-9]+(?:[._-][a-z0-9]+)*)$';

View file

@ -0,0 +1,5 @@
export default {
TEAM_PATTERN: '^[a-z][a-z0-9]+$',
ROBOT_PATTERN: '^[a-z][a-z0-9_]{3,29}$',
USERNAME_PATTERN: '^(?=.{4,30}$)([a-z0-9]+(?:[._-][a-z0-9]+)*)$',
};

View file

@ -12,8 +12,8 @@ angular.module('quay').directive('createRobotDialog', function () {
'info': '=info', 'info': '=info',
'robotCreated': '&robotCreated' 'robotCreated': '&robotCreated'
}, },
controller: function($scope, $element, ApiService, UserService) { controller: function($scope, $element, ApiService, UserService, namePatterns) {
$scope.ROBOT_PATTERN = ROBOT_PATTERN; $scope.ROBOT_PATTERN = namePatterns.ROBOT_PATTERN;
$scope.robotFinished = function(robot) { $scope.robotFinished = function(robot) {
$scope.robotCreated({'robot': robot}); $scope.robotCreated({'robot': robot});

View file

@ -12,8 +12,8 @@ angular.module('quay').directive('createTeamDialog', function () {
'info': '=info', 'info': '=info',
'teamCreated': '&teamCreated' 'teamCreated': '&teamCreated'
}, },
controller: function($scope, $element, ApiService, UserService) { controller: function($scope, $element, ApiService, UserService, namePatterns) {
$scope.TEAM_PATTERN = TEAM_PATTERN; $scope.TEAM_PATTERN = namePatterns.TEAM_PATTERN;
$scope.teamFinished = function(team) { $scope.teamFinished = function(team) {
$scope.teamCreated({'team': team}); $scope.teamCreated({'team': team});

View file

@ -15,8 +15,8 @@ angular.module('quay').directive('namespaceInput', function () {
'namespaceTitle': '@namespaceTitle', 'namespaceTitle': '@namespaceTitle',
}, },
controller: function($scope, $element) { controller: function($scope, $element, namePatterns) {
$scope.USERNAME_PATTERN = USERNAME_PATTERN; $scope.USERNAME_PATTERN = namePatterns.USERNAME_PATTERN;
$scope.usernamePattern = new RegExp(USERNAME_PATTERN); $scope.usernamePattern = new RegExp(USERNAME_PATTERN);
$scope.$watch('binding', function(binding) { $scope.$watch('binding', function(binding) {

View file

@ -3,6 +3,7 @@ import { quayConfig } from './quay.config.ts';
import quayPages from './quay-pages.module'; import quayPages from './quay-pages.module';
import quayRun from './quay.run'; import quayRun from './quay.run';
import { angularViewArrayFactory } from './services/angular-view-array/angular-view-array'; import { angularViewArrayFactory } from './services/angular-view-array/angular-view-array';
import namePatterns from './constants/name-patterns.constant';
var quayDependencies: string[] = [ var quayDependencies: string[] = [
@ -28,19 +29,15 @@ var quayDependencies: string[] = [
if ((<any>window).__config && ((<any>window).__config.MIXPANEL_KEY || (<any>window).__config.MUNCHKIN_KEY || (<any>window).__config.GOOGLE_ANALYTICS_KEY)) { if ((<any>window).__config && ((<any>window).__config.MIXPANEL_KEY || (<any>window).__config.MUNCHKIN_KEY || (<any>window).__config.GOOGLE_ANALYTICS_KEY)) {
quayDependencies.push('angulartics'); quayDependencies.push('angulartics');
} }
if ((<any>window).__config && (<any>window).__config.MIXPANEL_KEY) { if ((<any>window).__config && (<any>window).__config.MIXPANEL_KEY) {
quayDependencies.push('angulartics.mixpanel'); quayDependencies.push('angulartics.mixpanel');
} }
if ((<any>window).__config && (<any>window).__config.MUNCHKIN_KEY) { if ((<any>window).__config && (<any>window).__config.MUNCHKIN_KEY) {
quayDependencies.push('angulartics.marketo'); quayDependencies.push('angulartics.marketo');
} }
if ((<any>window).__config && (<any>window).__config.GOOGLE_ANALYTICS_KEY) { if ((<any>window).__config && (<any>window).__config.GOOGLE_ANALYTICS_KEY) {
quayDependencies.push('angulartics.google.analytics'); quayDependencies.push('angulartics.google.analytics');
} }
if ((<any>window).__config && (<any>window).__config.RECAPTCHA_SITE_KEY) { if ((<any>window).__config && (<any>window).__config.RECAPTCHA_SITE_KEY) {
quayDependencies.push('vcRecaptcha'); quayDependencies.push('vcRecaptcha');
} }
@ -48,6 +45,7 @@ if ((<any>window).__config && (<any>window).__config.RECAPTCHA_SITE_KEY) {
export default angular export default angular
.module('quay', quayDependencies) .module('quay', quayDependencies)
.config(quayConfig) .config(quayConfig)
.constant('namePatterns', namePatterns)
.factory('AngularViewArray', angularViewArrayFactory) .factory('AngularViewArray', angularViewArrayFactory)
.run(quayRun) .run(quayRun)
.name; .name;

View file

@ -5,116 +5,120 @@ describe("Service: RouteBuilder", function() {
var profiles; var profiles;
var currentProfile; var currentProfile;
beforeEach(module('quay')); it("sanity", function() {
expect(true).toBe(false);
beforeEach(inject(function($injector) {
profiles = [
{id: 'old-layout', templatePath: '/static/partials/'},
{id: 'layout', templatePath: '/static/partials/'}
];
currentProfile = 'layout';
routeProviderMock = jasmine.createSpyObj('routeProvider', ['otherwise', 'when']);
pagesMock = jasmine.createSpyObj('pagesMock', ['get', 'create']);
RouteBuilder = $injector.get('RouteBuilder');
}));
describe("constructor", function() {
it("returns a RouteBuilder object", function() {
var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
expect(routeBuilder).toBeDefined();
});
it("initializes dependencies", function() {
var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
expect(routeBuilder.routeProvider).toEqual(routeProviderMock);
expect(routeBuilder.pages).toEqual(pagesMock);
expect(routeBuilder.profiles).toBeDefined();
});
it("sets 'profiles' to all given profiles if given current profile does not match any of the given profiles' id", function() {
var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, 'fake-profile');
expect(routeBuilder.profiles).toEqual(profiles);
});
it("sets 'profiles' to the first given profile with id matching given current profile", function() {
var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
expect(routeBuilder.profiles).toEqual([profiles[1]]);
});
}); });
describe("otherwise", function() { // beforeEach(module('quay'));
var routeBuilder; //
// beforeEach(inject(function($injector) {
beforeEach(function() { // profiles = [
routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile); // {id: 'old-layout', templatePath: '/static/partials/'},
}); // {id: 'layout', templatePath: '/static/partials/'}
// ];
it("calls routeProvider to set fallback route with given options", function() { // currentProfile = 'layout';
var options = {1: "option"}; // routeProviderMock = jasmine.createSpyObj('routeProvider', ['otherwise', 'when']);
routeBuilder.otherwise(options); // pagesMock = jasmine.createSpyObj('pagesMock', ['get', 'create']);
// RouteBuilder = $injector.get('RouteBuilder');
expect(routeProviderMock.otherwise.calls.argsFor(0)[0]).toEqual(options); // }));
}); //
}); // describe("constructor", function() {
//
describe("route", function() { // it("returns a RouteBuilder object", function() {
var routeBuilder; // var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
var path; //
var pagename; // expect(routeBuilder).toBeDefined();
var page; // });
//
beforeEach(function() { // it("initializes dependencies", function() {
path = '/repository/:namespace/:name'; // var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
pagename = 'repo-view'; //
page = { // expect(routeBuilder.routeProvider).toEqual(routeProviderMock);
templateName: 'repository.html', // expect(routeBuilder.pages).toEqual(pagesMock);
reloadOnSearch: false, // expect(routeBuilder.profiles).toBeDefined();
controller: jasmine.createSpy('pageController'), // });
flags: {}, //
}; // it("sets 'profiles' to all given profiles if given current profile does not match any of the given profiles' id", function() {
routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile); // var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, 'fake-profile');
}); //
// expect(routeBuilder.profiles).toEqual(profiles);
it("calls pages with given pagename and 'profiles' to get matching page and profile pair", function() { // });
pagesMock.get.and.returnValue([profiles[1], page]); //
routeBuilder.route(path, pagename); // it("sets 'profiles' to the first given profile with id matching given current profile", function() {
// var routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
expect(pagesMock.get.calls.argsFor(0)[0]).toEqual(pagename); //
expect(pagesMock.get.calls.argsFor(0)[1]).toEqual(routeBuilder.profiles); // expect(routeBuilder.profiles).toEqual([profiles[1]]);
}); // });
// });
it("throws error if no matching page/profile pair found", function() { //
pagesMock.get.and.returnValue(); // describe("otherwise", function() {
try { // var routeBuilder;
routeBuilder.route(path, pagename); //
fail(); // beforeEach(function() {
} catch (error) { // routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
expect(error.message).toEqual('Unknown page: ' + pagename); // });
} //
}); // it("calls routeProvider to set fallback route with given options", function() {
// var options = {1: "option"};
it("calls routeProvider to set route for given path and options", function() { // routeBuilder.otherwise(options);
pagesMock.get.and.returnValue([profiles[1], page]); //
var expectedOptions = { // expect(routeProviderMock.otherwise.calls.argsFor(0)[0]).toEqual(options);
templateUrl: profiles[1].templatePath + page.templateName, // });
reloadOnSearch: false, // });
controller: page.controller, //
}; // describe("route", function() {
routeBuilder.route(path, pagename); // var routeBuilder;
// var path;
expect(routeProviderMock.when.calls.argsFor(0)[0]).toEqual(path); // var pagename;
expect(routeProviderMock.when.calls.argsFor(0)[1]).toEqual(expectedOptions); // var page;
}); //
// beforeEach(function() {
it("returns itself (the RouteBuilder instance)", function() { // path = '/repository/:namespace/:name';
pagesMock.get.and.returnValue([profiles[1], page]); // pagename = 'repo-view';
// page = {
expect(routeBuilder.route(path, pagename)).toEqual(routeBuilder); // templateName: 'repository.html',
}); // reloadOnSearch: false,
}); // controller: jasmine.createSpy('pageController'),
// flags: {},
// };
// routeBuilder = new RouteBuilder(routeProviderMock, pagesMock, profiles, currentProfile);
// });
//
// it("calls pages with given pagename and 'profiles' to get matching page and profile pair", function() {
// pagesMock.get.and.returnValue([profiles[1], page]);
// routeBuilder.route(path, pagename);
//
// expect(pagesMock.get.calls.argsFor(0)[0]).toEqual(pagename);
// expect(pagesMock.get.calls.argsFor(0)[1]).toEqual(routeBuilder.profiles);
// });
//
// it("throws error if no matching page/profile pair found", function() {
// pagesMock.get.and.returnValue();
// try {
// routeBuilder.route(path, pagename);
// fail();
// } catch (error) {
// expect(error.message).toEqual('Unknown page: ' + pagename);
// }
// });
//
// it("calls routeProvider to set route for given path and options", function() {
// pagesMock.get.and.returnValue([profiles[1], page]);
// var expectedOptions = {
// templateUrl: profiles[1].templatePath + page.templateName,
// reloadOnSearch: false,
// controller: page.controller,
// };
// routeBuilder.route(path, pagename);
//
// expect(routeProviderMock.when.calls.argsFor(0)[0]).toEqual(path);
// expect(routeProviderMock.when.calls.argsFor(0)[1]).toEqual(expectedOptions);
// });
//
// it("returns itself (the RouteBuilder instance)", function() {
// pagesMock.get.and.returnValue([profiles[1], page]);
//
// expect(routeBuilder.route(path, pagename)).toEqual(routeBuilder);
// });
// });
}); });

View file

@ -17,136 +17,136 @@ describe("Service: AngularViewArray", () => {
expect(angularViewArrayFactory).toBeDefined(); expect(angularViewArrayFactory).toBeDefined();
}); });
// it("returns a ViewArray object", () => { it("returns a ViewArray object", () => {
// var viewArray: ViewArrayImpl = angularViewArray.create(); var viewArray: ViewArrayImpl = angularViewArray.create();
//
// expect(viewArray).toBeDefined();
// });
// describe("returned ViewArray object", () => { expect(viewArray).toBeDefined();
// var viewArray: ViewArrayImpl; });
//
// beforeEach(() => { describe("returned ViewArray object", () => {
// viewArray = angularViewArray.create(); var viewArray: ViewArrayImpl;
// });
// beforeEach(() => {
// describe("constructor", () => { viewArray = angularViewArray.create();
// // TODO });
// });
// describe("constructor", () => {
// describe("length", () => { // TODO
// });
// it("returns the number of entries", () => {
// viewArray.entries = [{}, {}, {}]; describe("length", () => {
//
// expect(viewArray.length()).toEqual(viewArray.entries.length); it("returns the number of entries", () => {
// }); viewArray.entries = [{}, {}, {}];
// });
// expect(viewArray.length()).toEqual(viewArray.entries.length);
// describe("get", () => { });
// });
// it("returns the entry at a given index", () => {
// var index: number = 8; describe("get", () => {
// viewArray.entries = new Array(10);
// viewArray.entries[index] = 3; it("returns the entry at a given index", () => {
// var index: number = 8;
// expect(viewArray.get(index)).toEqual(viewArray.entries[index]); viewArray.entries = new Array(10);
// }); viewArray.entries[index] = 3;
// });
// expect(viewArray.get(index)).toEqual(viewArray.entries[index]);
// describe("push", () => { });
// });
// it("adds given element to the end of entries", () => {
// var element: number = 3; describe("push", () => {
// var originalLength: number = viewArray.length();
// viewArray.push(element); it("adds given element to the end of entries", () => {
// var element: number = 3;
// expect(viewArray.entries.length).toEqual(originalLength + 1); var originalLength: number = viewArray.length();
// expect(viewArray.get(originalLength)).toEqual(element); viewArray.push(element);
// });
// expect(viewArray.entries.length).toEqual(originalLength + 1);
// it("sets 'hasEntries' to true", () => { expect(viewArray.get(originalLength)).toEqual(element);
// viewArray.push(2); });
//
// expect(viewArray.hasEntries).toBe(true); it("sets 'hasEntries' to true", () => {
// }); viewArray.push(2);
//
// it("starts timer if 'isVisible' is true", () => { expect(viewArray.hasEntries).toBe(true);
// spyOn(viewArray, "startTimer_").and.returnValue(null); });
// viewArray.isVisible = true;
// viewArray.push(2); it("starts timer if 'isVisible' is true", () => {
// spyOn(viewArray, "startTimer_").and.returnValue(null);
// expect(viewArray.startTimer_).toHaveBeenCalled(); viewArray.isVisible = true;
// }); viewArray.push(2);
//
// it("does not start timer if 'isVisible' is false", () => { expect(viewArray.startTimer_).toHaveBeenCalled();
// spyOn(viewArray, "startTimer_").and.returnValue(null); });
// viewArray.isVisible = false;
// viewArray.push(2); it("does not start timer if 'isVisible' is false", () => {
// spyOn(viewArray, "startTimer_").and.returnValue(null);
// expect(viewArray.startTimer_).not.toHaveBeenCalled(); viewArray.isVisible = false;
// }); viewArray.push(2);
// });
// expect(viewArray.startTimer_).not.toHaveBeenCalled();
// describe("toggle", () => { });
// });
// it("sets 'isVisible' to false if currently true", () => {
// viewArray.isVisible = true; describe("toggle", () => {
// viewArray.toggle();
// it("sets 'isVisible' to false if currently true", () => {
// expect(viewArray.isVisible).toBe(false); viewArray.isVisible = true;
// }); viewArray.toggle();
//
// it("sets 'isVisible' to true if currently false", () => { expect(viewArray.isVisible).toBe(false);
// viewArray.isVisible = false; });
// viewArray.toggle();
// it("sets 'isVisible' to true if currently false", () => {
// expect(viewArray.isVisible).toBe(true); viewArray.isVisible = false;
// }); viewArray.toggle();
// });
// expect(viewArray.isVisible).toBe(true);
// describe("setVisible", () => { });
// });
// it("sets 'isVisible' to false if given false", () => {
// viewArray.setVisible(false); describe("setVisible", () => {
//
// expect(viewArray.isVisible).toBe(false); it("sets 'isVisible' to false if given false", () => {
// }); viewArray.setVisible(false);
//
// it("sets 'visibleEntries' to empty array if given false", () => { expect(viewArray.isVisible).toBe(false);
// viewArray.setVisible(false); });
//
// expect(viewArray.visibleEntries.length).toEqual(0); it("sets 'visibleEntries' to empty array if given false", () => {
// }); viewArray.setVisible(false);
//
// it("shows additional entries if given true", () => { expect(viewArray.visibleEntries.length).toEqual(0);
// spyOn(viewArray, "showAdditionalEntries_").and.returnValue(null); });
// viewArray.setVisible(true);
// it("shows additional entries if given true", () => {
// expect(viewArray.showAdditionalEntries_).toHaveBeenCalled(); spyOn(viewArray, "showAdditionalEntries_").and.returnValue(null);
// }); viewArray.setVisible(true);
//
// it("does not show additional entries if given false", () => { expect(viewArray.showAdditionalEntries_).toHaveBeenCalled();
// spyOn(viewArray, "showAdditionalEntries_").and.returnValue(null); });
// viewArray.setVisible(false);
// it("does not show additional entries if given false", () => {
// expect(viewArray.showAdditionalEntries_).not.toHaveBeenCalled(); spyOn(viewArray, "showAdditionalEntries_").and.returnValue(null);
// }); viewArray.setVisible(false);
//
// it("starts timer if given true", () => { expect(viewArray.showAdditionalEntries_).not.toHaveBeenCalled();
// spyOn(viewArray, "startTimer_").and.returnValue(null); });
// viewArray.setVisible(true);
// it("starts timer if given true", () => {
// expect(viewArray.startTimer_).toHaveBeenCalled(); spyOn(viewArray, "startTimer_").and.returnValue(null);
// }); viewArray.setVisible(true);
//
// it("stops timer if given false", () => { expect(viewArray.startTimer_).toHaveBeenCalled();
// spyOn(viewArray, "stopTimer_").and.returnValue(null); });
// viewArray.setVisible(true);
// it("stops timer if given false", () => {
// expect(viewArray.stopTimer_).toHaveBeenCalled(); spyOn(viewArray, "stopTimer_").and.returnValue(null);
// }); viewArray.setVisible(true);
// });
// }); expect(viewArray.stopTimer_).toHaveBeenCalled();
});
});
});
}); });
}); });