homehub/packages/homehub_components/tests/FatalError.spec.js
2021-08-26 12:33:15 +02:00

76 lines
1.6 KiB
JavaScript

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);
});
});