Commit adb9d920 by Torkel Ödegaard

test: added first react snapshot test

parent a06ccaa4
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
"test-ci": "./node_modules/.bin/grunt test --coverage=true", "test-ci": "./node_modules/.bin/grunt test --coverage=true",
"lint": "./node_modules/.bin/tslint -c tslint.json --project tsconfig.json --type-check", "lint": "./node_modules/.bin/tslint -c tslint.json --project tsconfig.json --type-check",
"karma": "./node_modules/grunt-cli/bin/grunt karma:dev", "karma": "./node_modules/grunt-cli/bin/grunt karma:dev",
"jest": "./node_modules/jest-cli/bin/jest --notify --watch" "jest": "./node_modules/jest-cli/bin/jest.js --notify --watch"
}, },
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
......
...@@ -27,7 +27,7 @@ _.move = function (array, fromIndex, toIndex) { ...@@ -27,7 +27,7 @@ _.move = function (array, fromIndex, toIndex) {
return array; return array;
}; };
import {coreModule} from './core/core'; import {coreModule, registerAngularDirectives} from './core/core';
export class GrafanaApp { export class GrafanaApp {
registerFunctions: any; registerFunctions: any;
...@@ -109,6 +109,9 @@ export class GrafanaApp { ...@@ -109,6 +109,9 @@ export class GrafanaApp {
// makes it possible to add dynamic stuff // makes it possible to add dynamic stuff
this.useModule(coreModule); this.useModule(coreModule);
// register react angular wrappers
registerAngularDirectives();
var preBootRequires = [System.import('app/features/all')]; var preBootRequires = [System.import('app/features/all')];
Promise.all(preBootRequires).then(() => { Promise.all(preBootRequires).then(() => {
......
import { react2AngularDirective } from 'app/core/utils/react2angular'; import { react2AngularDirective } from 'app/core/utils/react2angular';
import { PasswordStrength } from './ui/PasswordStrength'; import { PasswordStrength } from './components/PasswordStrength';
export function registerAngularDirectives() { export function registerAngularDirectives() {
......
...@@ -6,7 +6,7 @@ export interface IProps { ...@@ -6,7 +6,7 @@ export interface IProps {
onColorSelect: (c: string) => void; onColorSelect: (c: string) => void;
} }
export class GfColorPalette extends React.Component<IProps, any> { export class ColorPalette extends React.Component<IProps, any> {
paletteColors: string[]; paletteColors: string[];
constructor(props) { constructor(props) {
......
import React from 'react'; import React from 'react';
import $ from 'jquery'; import $ from 'jquery';
import tinycolor from 'tinycolor2'; import tinycolor from 'tinycolor2';
import { GfColorPalette } from './ColorPalette'; import { ColorPalette } from './ColorPalette';
import { GfSpectrumPicker } from './SpectrumPicker'; import { SpectrumPicker } from './SpectrumPicker';
const DEFAULT_COLOR = '#000000'; const DEFAULT_COLOR = '#000000';
...@@ -82,12 +82,12 @@ export class ColorPickerPopover extends React.Component<IProps, any> { ...@@ -82,12 +82,12 @@ export class ColorPickerPopover extends React.Component<IProps, any> {
render() { render() {
const paletteTab = ( const paletteTab = (
<div id="palette"> <div id="palette">
<GfColorPalette color={this.state.color} onColorSelect={this.sampleColorSelected.bind(this)} /> <ColorPalette color={this.state.color} onColorSelect={this.sampleColorSelected.bind(this)} />
</div> </div>
); );
const spectrumTab = ( const spectrumTab = (
<div id="spectrum"> <div id="spectrum">
<GfSpectrumPicker color={this.state.color} onColorSelect={this.spectrumColorSelected.bind(this)} options={{}} /> <SpectrumPicker color={this.state.color} onColorSelect={this.spectrumColorSelected.bind(this)} options={{}} />
</div> </div>
); );
const currentTab = this.state.tab === 'palette' ? paletteTab : spectrumTab; const currentTab = this.state.tab === 'palette' ? paletteTab : spectrumTab;
......
...@@ -9,7 +9,7 @@ export interface IProps { ...@@ -9,7 +9,7 @@ export interface IProps {
onColorSelect: (c: string) => void; onColorSelect: (c: string) => void;
} }
export class GfSpectrumPicker extends React.Component<IProps, any> { export class SpectrumPicker extends React.Component<IProps, any> {
elem: any; elem: any;
isMoving: boolean; isMoving: boolean;
......
...@@ -47,9 +47,8 @@ import {JsonExplorer} from './components/json_explorer/json_explorer'; ...@@ -47,9 +47,8 @@ import {JsonExplorer} from './components/json_explorer/json_explorer';
import {NavModelSrv, NavModel} from './nav_model_srv'; import {NavModelSrv, NavModel} from './nav_model_srv';
import {registerAngularDirectives} from './angular_wrappers'; import {registerAngularDirectives} from './angular_wrappers';
registerAngularDirectives();
export { export {
registerAngularDirectives,
arrayJoin, arrayJoin,
coreModule, coreModule,
grafanaAppDirective, grafanaAppDirective,
......
import React from 'react';
import renderer from 'react-test-renderer';
import { ColorPalette } from '../components/colorpicker/ColorPalette';
describe('CollorPalette', () => {
it('renders correctly', () => {
const tree = renderer.create(<ColorPalette color="#EAB839" />).toJSON();
expect(tree).toMatchSnapshot();
});
});
import React from 'react'; import React from 'react';
import {shallow} from 'enzyme'; import {shallow} from 'enzyme';
import {PasswordStrength} from '../ui/PasswordStrength'; import {PasswordStrength} from '../components/PasswordStrength';
describe('PasswordStrength', () => { describe('PasswordStrength', () => {
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`CollorPalette renders correctly 1`] = `
<div
className="graph-legend-popover"
>
<p
className="m-b-0"
>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#890f02",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#58140c",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#99440a",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#c15c17",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#967302",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#cca300",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#3f6833",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#2f575e",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#64b0c8",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#052b51",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#0a50a1",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#584477",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#3f2b5b",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#511749",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#e24d42",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#bf1b00",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#ef843c",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#f4d598",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#e5ac0e",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#9ac48a",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#508642",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#6ed0e0",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#65c5db",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#0a437c",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#447ebc",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#614d93",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#d683ce",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#6d1f62",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#ea6460",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#e0752d",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#f9934e",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#fceaca",
}
}
>
 
</i>
<i
className="pointer fa fa-circle-o"
onClick={[Function]}
style={
Object {
"color": "#eab839",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#b7dbab",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#629e51",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#70dbed",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#82b5d8",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#1f78c1",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#aea2e0",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#705da0",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#e5a8e2",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#962d82",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#f29191",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#fce2de",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#f9ba8f",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#f9e2d2",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#f2c96d",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#e0f9d7",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#7eb26d",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#cffaff",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#badff4",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#5195ce",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#dedaf7",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#806eb7",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#f9d9f9",
}
}
>
 
</i>
<i
className="pointer fa fa-circle"
onClick={[Function]}
style={
Object {
"color": "#ba43a9",
}
}
>
 
</i>
</p>
</div>
`;
import {describe, it, expect} from 'test/lib/common';
import {containsVariable, assignModelProperties} from '../variable'; import {containsVariable, assignModelProperties} from '../variable';
describe('containsVariable', function() { describe('containsVariable', function() {
...@@ -8,37 +6,37 @@ describe('containsVariable', function() { ...@@ -8,37 +6,37 @@ describe('containsVariable', function() {
it('should find it with $var syntax', function() { it('should find it with $var syntax', function() {
var contains = containsVariable('this.$test.filters', 'test'); var contains = containsVariable('this.$test.filters', 'test');
expect(contains).to.be(true); expect(contains).toBe(true);
}); });
it('should not find it if only part matches with $var syntax', function() { it('should not find it if only part matches with $var syntax', function() {
var contains = containsVariable('this.$serverDomain.filters', 'server'); var contains = containsVariable('this.$serverDomain.filters', 'server');
expect(contains).to.be(false); expect(contains).toBe(false);
}); });
it('should find it if it ends with variable and passing multiple test strings', function() { it('should find it if it ends with variable and passing multiple test strings', function() {
var contains = containsVariable('show field keys from $pgmetric', 'test string2', 'pgmetric'); var contains = containsVariable('show field keys from $pgmetric', 'test string2', 'pgmetric');
expect(contains).to.be(true); expect(contains).toBe(true);
}); });
it('should find it with [[var]] syntax', function() { it('should find it with [[var]] syntax', function() {
var contains = containsVariable('this.[[test]].filters', 'test'); var contains = containsVariable('this.[[test]].filters', 'test');
expect(contains).to.be(true); expect(contains).toBe(true);
}); });
it('should find it when part of segment', function() { it('should find it when part of segment', function() {
var contains = containsVariable('metrics.$env.$group-*', 'group'); var contains = containsVariable('metrics.$env.$group-*', 'group');
expect(contains).to.be(true); expect(contains).toBe(true);
}); });
it('should find it its the only thing', function() { it('should find it its the only thing', function() {
var contains = containsVariable('$env', 'env'); var contains = containsVariable('$env', 'env');
expect(contains).to.be(true); expect(contains).toBe(true);
}); });
it('should be able to pass in multiple test strings', function() { it('should be able to pass in multiple test strings', function() {
var contains = containsVariable('asd','asd2.$env', 'env'); var contains = containsVariable('asd','asd2.$env', 'env');
expect(contains).to.be(true); expect(contains).toBe(true);
}); });
}); });
...@@ -50,14 +48,14 @@ describe('assignModelProperties', function() { ...@@ -50,14 +48,14 @@ describe('assignModelProperties', function() {
it('only set properties defined in defaults', function() { it('only set properties defined in defaults', function() {
var target: any = {test: 'asd'}; var target: any = {test: 'asd'};
assignModelProperties(target, {propA: 1, propB: 2}, {propB: 0}); assignModelProperties(target, {propA: 1, propB: 2}, {propB: 0});
expect(target.propB).to.be(2); expect(target.propB).toBe(2);
expect(target.test).to.be('asd'); expect(target.test).toBe('asd');
}); });
it('use default value if not found on source', function() { it('use default value if not found on source', function() {
var target: any = {test: 'asd'}; var target: any = {test: 'asd'};
assignModelProperties(target, {propA: 1, propB: 2}, {propC: 10}); assignModelProperties(target, {propA: 1, propB: 2}, {propC: 10});
expect(target.propC).to.be(10); expect(target.propC).toBe(10);
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment