Search in sources :

Example 1 with ProjectNotification

use of com.kickstarter.models.ProjectNotification in project android-oss by kickstarter.

the class ProjectNotificationViewModelTest method testNotificationsEmitProjectNameAndEnabledSwitch.

@Test
public void testNotificationsEmitProjectNameAndEnabledSwitch() {
    final ProjectNotificationViewModel vm = new ProjectNotificationViewModel(environment());
    final TestSubscriber<String> projectNameTest = new TestSubscriber<>();
    vm.outputs.projectName().subscribe(projectNameTest);
    final TestSubscriber<Boolean> enabledSwitchTest = new TestSubscriber<>();
    vm.outputs.enabledSwitch().subscribe(enabledSwitchTest);
    // Start with an enabled notification.
    final ProjectNotification enabledNotification = ProjectNotificationFactory.enabled();
    vm.inputs.projectNotification(enabledNotification);
    // Project name and enabled values should match enabled notification.
    projectNameTest.assertValue(enabledNotification.project().name());
    enabledSwitchTest.assertValue(true);
    // Change to a disabled notification.
    final ProjectNotification disabledNotification = ProjectNotificationFactory.disabled();
    vm.inputs.projectNotification(disabledNotification);
    // Project name and enabled values should match disabled notification.
    projectNameTest.assertValues(enabledNotification.project().name(), disabledNotification.project().name());
    enabledSwitchTest.assertValues(true, false);
}
Also used : TestSubscriber(rx.observers.TestSubscriber) ProjectNotification(com.kickstarter.models.ProjectNotification) Test(org.junit.Test)

Example 2 with ProjectNotification

use of com.kickstarter.models.ProjectNotification in project android-oss by kickstarter.

the class ProjectNotificationViewHolder method bindData.

@Override
public void bindData(@Nullable final Object data) throws Exception {
    final ProjectNotification projectNotification = requireNonNull((ProjectNotification) data, ProjectNotification.class);
    viewModel.projectNotification(projectNotification);
}
Also used : ProjectNotification(com.kickstarter.models.ProjectNotification)

Example 3 with ProjectNotification

use of com.kickstarter.models.ProjectNotification in project android-oss by kickstarter.

the class ProjectNotificationViewModelTest method testSwitchClickEmitsEnabledSwitch.

@Test
public void testSwitchClickEmitsEnabledSwitch() {
    final ProjectNotificationViewModel vm = new ProjectNotificationViewModel(environment());
    final TestSubscriber<Boolean> enabledSwitchTest = new TestSubscriber<>();
    vm.outputs.enabledSwitch().subscribe(enabledSwitchTest);
    // Start with a disabled notification.
    final ProjectNotification disabledNotification = ProjectNotificationFactory.disabled();
    vm.inputs.projectNotification(disabledNotification);
    // Enabled switch should be disabled.
    enabledSwitchTest.assertValues(false);
    // Enable the previously disabled notification.
    vm.inputs.enabledSwitchClick(true);
    // Enabled switch should now be enabled.
    enabledSwitchTest.assertValues(false, true);
}
Also used : TestSubscriber(rx.observers.TestSubscriber) ProjectNotification(com.kickstarter.models.ProjectNotification) Test(org.junit.Test)

Example 4 with ProjectNotification

use of com.kickstarter.models.ProjectNotification in project android-oss by kickstarter.

the class ProjectNotificationViewModelTest method testShowUnableToSaveNotificationError.

@Test
public void testShowUnableToSaveNotificationError() {
    final ApiClientType client = new MockApiClient() {

        @Override
        @NonNull
        public Observable<ProjectNotification> updateProjectNotifications(@NonNull final ProjectNotification projectNotification, final boolean checked) {
            return Observable.error(ApiExceptionFactory.badRequestException());
        }
    };
    final Environment environment = environment().toBuilder().apiClient(client).build();
    final ProjectNotificationViewModel vm = new ProjectNotificationViewModel(environment);
    final TestSubscriber<Void> showUnableToSaveNotificationErrorTest = new TestSubscriber<>();
    vm.errors.showUnableToSaveProjectNotificationError().subscribe(showUnableToSaveNotificationErrorTest);
    final TestSubscriber<Boolean> enabledSwitchTest = new TestSubscriber<>();
    vm.outputs.enabledSwitch().subscribe(enabledSwitchTest);
    // Start with a disabled notification.
    final ProjectNotification projectNotification = ProjectNotificationFactory.disabled();
    vm.inputs.projectNotification(projectNotification);
    // Switch should be disabled.
    enabledSwitchTest.assertValue(false);
    // Attempt to toggle the notification to true. This should error, and the switch should still be disabled.
    vm.enabledSwitchClick(true);
    showUnableToSaveNotificationErrorTest.assertValueCount(1);
    enabledSwitchTest.assertValue(false);
}
Also used : MockApiClient(com.kickstarter.services.MockApiClient) NonNull(android.support.annotation.NonNull) ProjectNotification(com.kickstarter.models.ProjectNotification) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Aggregations

ProjectNotification (com.kickstarter.models.ProjectNotification)4 Test (org.junit.Test)3 TestSubscriber (rx.observers.TestSubscriber)3 NonNull (android.support.annotation.NonNull)1 Environment (com.kickstarter.libs.Environment)1 ApiClientType (com.kickstarter.services.ApiClientType)1 MockApiClient (com.kickstarter.services.MockApiClient)1