Skip to content

Commit

Permalink
Add a skeleton for the RadioManager object
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellLVP committed Dec 17, 2017
1 parent d43a6ba commit 0f3a741
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
6 changes: 2 additions & 4 deletions javascript/features/radio/channel_selection.test.js
Expand Up @@ -13,10 +13,8 @@ describe('ChannelSelection', (it, beforeEach, afterEach) => {
settings = server.featureManager.loadFeature('settings');
selection = new ChannelSelection(() => new MockAnnounce(), () => settings);
});
afterEach(() => {
if (selection)
selection.dispose();
});

afterEach(() => selection.dispose());

// Radio configuration that should be used for testing purposes.
const TEST_RADIO_CONFIGURATION = [
Expand Down
4 changes: 4 additions & 0 deletions javascript/features/radio/radio.js
Expand Up @@ -5,6 +5,7 @@
const Feature = require('components/feature_manager/feature.js');

const ChannelSelection = require('features/radio/channel_selection.js');
const RadioManager = require('features/radio/radio_manager.js');

// Implementation of the Radio feature that allows players to listen to a variety of radio channels
// while playing on Las Venturas Playground.
Expand All @@ -20,9 +21,12 @@ class Radio extends Feature {

this.selection_ = new ChannelSelection(announce, settings);
this.selection_.loadConfiguration();

this.manager_ = new RadioManager(this.selection_, settings);
}

dispose() {
this.manager_.dispose();
this.selection_.dispose();
}
}
Expand Down
18 changes: 18 additions & 0 deletions javascript/features/radio/radio_manager.js
@@ -0,0 +1,18 @@
// Copyright 2017 Las Venturas Playground. All rights reserved.
// Use of this source code is governed by the MIT license, a copy of which can
// be found in the LICENSE file.

//
class RadioManager {
constructor(selection, settings) {
this.selection_ = selection;
this.settings_ = settings;
}

// Returns whether the radio feature should be enabled at all.
isEnabled() { return this.settings_().getValue('radio/enabled'); }

dispose() {}
}

exports = RadioManager;
42 changes: 42 additions & 0 deletions javascript/features/radio/radio_manager.test.js
@@ -0,0 +1,42 @@
// Copyright 2017 Las Venturas Playground. All rights reserved.
// Use of this source code is governed by the MIT license, a copy of which can
// be found in the LICENSE file.

const ChannelSelection = require('features/radio/channel_selection.js');
const MockAnnounce = require('features/announce/test/mock_announce.js');
const RadioManager = require('features/radio/radio_manager.js');

describe('RadioManager', (it, beforeEach, afterEach) => {
let manager = null;
let settings = null;

beforeEach(() => {
settings = server.featureManager.loadFeature('settings');

const announce = new MockAnnounce();
const selection = new ChannelSelection(() => announce, () => settings);
selection.loadConfigurationFromArray([
{
name: "LVP Radio",
stream: "https://play.sa-mp.nl/stream.pls"
}
]);

manager = new RadioManager(selection, () => settings);
});

afterEach(() => {
manager.selection_.dispose();
manager.dispose();
});

it('should keep track of whether the feature is enabled', assert => {
assert.isTrue(settings.getValue('radio/enabled'));
assert.isTrue(manager.isEnabled());

settings.setValue('radio/enabled', false);

assert.isFalse(settings.getValue('radio/enabled'));
assert.isFalse(manager.isEnabled());
});
});

0 comments on commit 0f3a741

Please sign in to comment.