You've already forked homehub
Release 1.3.0
This commit is contained in:
75
packages/homehub_components/tests/FatalError.spec.js
Normal file
75
packages/homehub_components/tests/FatalError.spec.js
Normal file
@@ -0,0 +1,75 @@
|
||||
import {BaseService, ServiceState} from '@bthlabs/homehub-core';
|
||||
import {shallow} from 'enzyme';
|
||||
import React from 'react';
|
||||
|
||||
import {FatalError} from 'src/FatalError';
|
||||
|
||||
class FakeService extends BaseService {
|
||||
static kind = 'FakeService';
|
||||
static widget = 'FakeWidget';
|
||||
}
|
||||
|
||||
describe('src/FatalError', () => {
|
||||
let service = null;
|
||||
let serviceState = null;
|
||||
|
||||
beforeEach(() => {
|
||||
service = new FakeService({
|
||||
instance: 'testing',
|
||||
characteristics: {},
|
||||
});
|
||||
serviceState = new ServiceState({
|
||||
error: {
|
||||
message: 'FIAL',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('allows passing an arbitrary class name', () => {
|
||||
// Given
|
||||
const component = shallow(
|
||||
<FatalError
|
||||
className="test"
|
||||
service={service}
|
||||
serviceState={serviceState}
|
||||
/>
|
||||
);
|
||||
|
||||
// Then
|
||||
expect(component.hasClass('test')).toBe(true);
|
||||
});
|
||||
|
||||
it('renders the service kind and instance', () => {
|
||||
// Given
|
||||
const component = shallow(
|
||||
<FatalError
|
||||
className="test"
|
||||
service={service}
|
||||
serviceState={serviceState}
|
||||
/>
|
||||
);
|
||||
|
||||
// When
|
||||
const code = component.find('code').at(0);
|
||||
|
||||
// Then
|
||||
expect(code.text()).toEqual(`${service.kind}:${service.instance}`);
|
||||
});
|
||||
|
||||
it('renders the error message', () => {
|
||||
// Given
|
||||
const component = shallow(
|
||||
<FatalError
|
||||
className="test"
|
||||
service={service}
|
||||
serviceState={serviceState}
|
||||
/>
|
||||
);
|
||||
|
||||
// When
|
||||
const code = component.find('code').at(1);
|
||||
|
||||
// Then
|
||||
expect(code.text()).toEqual(serviceState.error().message);
|
||||
});
|
||||
});
|
||||
49
packages/homehub_components/tests/Widget.spec.js
Normal file
49
packages/homehub_components/tests/Widget.spec.js
Normal file
@@ -0,0 +1,49 @@
|
||||
import {shallow} from 'enzyme';
|
||||
import React from 'react';
|
||||
|
||||
import {Widget} from 'src/Widget';
|
||||
|
||||
describe('src/Widget', () => {
|
||||
it('allows passing an arbitrary class name', () => {
|
||||
// Given
|
||||
const component = shallow(
|
||||
<Widget className="test">
|
||||
<span>It works!</span>
|
||||
</Widget>
|
||||
);
|
||||
|
||||
// Then
|
||||
expect(component.hasClass('test')).toBe(true);
|
||||
});
|
||||
|
||||
it('uses the appearance to change the style', () => {
|
||||
// Given
|
||||
const component = shallow(
|
||||
<Widget appearance={{color: 'red'}}>
|
||||
<span>It works!</span>
|
||||
</Widget>
|
||||
);
|
||||
|
||||
// When
|
||||
const style = component.prop('style');
|
||||
|
||||
// Then
|
||||
expect(style.backgroundColor).toEqual('red');
|
||||
});
|
||||
|
||||
it('renders the children', () => {
|
||||
// Given
|
||||
const component = shallow(
|
||||
<Widget>
|
||||
<span>It works!</span>
|
||||
</Widget>
|
||||
);
|
||||
|
||||
// When
|
||||
const span = component.find('span').at(0);
|
||||
|
||||
// Then
|
||||
expect(span.exists()).toBe(true);
|
||||
expect(span.text()).toEqual('It works!');
|
||||
});
|
||||
});
|
||||
4
packages/homehub_components/tests/__entry__.js
Normal file
4
packages/homehub_components/tests/__entry__.js
Normal file
@@ -0,0 +1,4 @@
|
||||
require('tests/__setup__/enzyme.setup.js');
|
||||
|
||||
let testsContext = require.context('.', true, /\.spec\.js$/);
|
||||
testsContext.keys().forEach(testsContext);
|
||||
@@ -0,0 +1,7 @@
|
||||
import Enzyme from 'enzyme';
|
||||
import Adapter from 'enzyme-adapter-react-16';
|
||||
|
||||
Enzyme.configure({
|
||||
adapter: new Adapter(),
|
||||
disableLifecycleMethods: true,
|
||||
});
|
||||
Reference in New Issue
Block a user