Search in sources :

Example 1 with Config

use of com.kickstarter.libs.Config in project android-oss by kickstarter.

the class RewardViewModelTest method testUsdConversionNotShownForUSProject.

@Test
public void testUsdConversionNotShownForUSProject() {
    // Set user's country to US.
    final Config config = ConfigFactory.configForUSUser();
    final Environment environment = environment();
    final CurrentConfigType currentConfig = environment.currentConfig();
    environment.currentConfig().config(config);
    final RewardViewModel vm = new RewardViewModel(environment);
    // Set project's country to US.
    final Project project = ProjectFactory.project().toBuilder().country("US").build();
    final Reward reward = RewardFactory.reward();
    final TestSubscriber<String> usdConversionTextViewText = TestSubscriber.create();
    vm.outputs.usdConversionTextViewText().subscribe(usdConversionTextViewText);
    final TestSubscriber<Boolean> usdConversionSectionIsHidden = TestSubscriber.create();
    vm.outputs.usdConversionTextViewIsHidden().subscribe(usdConversionSectionIsHidden);
    // USD conversion should not be shown.
    vm.inputs.projectAndReward(project, reward);
    usdConversionTextViewText.assertNoValues();
    usdConversionSectionIsHidden.assertValue(true);
    // Set user's country to CA.
    currentConfig.config(ConfigFactory.configForCAUser());
    // USD conversion should still not be shown (distinct until changed).
    usdConversionTextViewText.assertNoValues();
    usdConversionSectionIsHidden.assertValues(true);
}
Also used : Project(com.kickstarter.models.Project) Config(com.kickstarter.libs.Config) CurrentConfigType(com.kickstarter.libs.CurrentConfigType) Environment(com.kickstarter.libs.Environment) Reward(com.kickstarter.models.Reward) Test(org.junit.Test)

Example 2 with Config

use of com.kickstarter.libs.Config in project android-oss by kickstarter.

the class RewardViewModelTest method testUsdConversionForNonUSProject.

@Test
public void testUsdConversionForNonUSProject() {
    // Set user's country to US.
    final Config config = ConfigFactory.configForUSUser();
    final Environment environment = environment();
    final CurrentConfigType currentConfig = environment.currentConfig();
    environment.currentConfig().config(config);
    final RewardViewModel vm = new RewardViewModel(environment);
    // Set project's country to CA.
    final Project project = ProjectFactory.caProject();
    final Reward reward = RewardFactory.reward();
    final TestSubscriber<String> usdConversionTextViewText = TestSubscriber.create();
    vm.outputs.usdConversionTextViewText().subscribe(usdConversionTextViewText);
    final TestSubscriber<Boolean> usdConversionSectionIsHidden = TestSubscriber.create();
    vm.outputs.usdConversionTextViewIsHidden().subscribe(usdConversionSectionIsHidden);
    // USD conversion should be shown.
    vm.inputs.projectAndReward(project, reward);
    usdConversionTextViewText.assertValueCount(1);
    usdConversionSectionIsHidden.assertValue(false);
    // Set user's country to CA (any country except the US is fine).
    currentConfig.config(ConfigFactory.configForCAUser());
    // USD conversion should now be hidden.
    usdConversionTextViewText.assertValueCount(1);
    usdConversionSectionIsHidden.assertValues(false, true);
}
Also used : Project(com.kickstarter.models.Project) Config(com.kickstarter.libs.Config) CurrentConfigType(com.kickstarter.libs.CurrentConfigType) Environment(com.kickstarter.libs.Environment) Reward(com.kickstarter.models.Reward) Test(org.junit.Test)

Example 3 with Config

use of com.kickstarter.libs.Config in project android-oss by kickstarter.

the class RewardViewModelTest method testUsdConversionTextRoundsUp.

@Test
public void testUsdConversionTextRoundsUp() {
    // Set user's country to US.
    final Config config = ConfigFactory.configForUSUser();
    final Environment environment = environment();
    environment.currentConfig().config(config);
    final RewardViewModel vm = new RewardViewModel(environment);
    // Set project's country to CA and reward minimum to $0.30.
    final Project project = ProjectFactory.caProject();
    final Reward reward = RewardFactory.reward().toBuilder().minimum(0.3f).build();
    final TestSubscriber<String> usdConversionTextViewText = TestSubscriber.create();
    vm.outputs.usdConversionTextViewText().subscribe(usdConversionTextViewText);
    // USD conversion should be rounded up.
    vm.inputs.projectAndReward(project, reward);
    usdConversionTextViewText.assertValue("$1");
}
Also used : Project(com.kickstarter.models.Project) Config(com.kickstarter.libs.Config) Environment(com.kickstarter.libs.Environment) Reward(com.kickstarter.models.Reward) Test(org.junit.Test)

Example 4 with Config

use of com.kickstarter.libs.Config in project android-oss by kickstarter.

the class KSCurrencyTest method createKSCurrency.

private static KSCurrency createKSCurrency(final String countryCode) {
    final Config config = ConfigFactory.config().toBuilder().countryCode(countryCode).build();
    final CurrentConfigType currentConfig = new MockCurrentConfig();
    currentConfig.config(config);
    return new KSCurrency(currentConfig);
}
Also used : MockCurrentConfig(com.kickstarter.mock.MockCurrentConfig) KSCurrency(com.kickstarter.libs.KSCurrency) MockCurrentConfig(com.kickstarter.mock.MockCurrentConfig) Config(com.kickstarter.libs.Config) CurrentConfigType(com.kickstarter.libs.CurrentConfigType)

Aggregations

Config (com.kickstarter.libs.Config)4 CurrentConfigType (com.kickstarter.libs.CurrentConfigType)3 Environment (com.kickstarter.libs.Environment)3 Project (com.kickstarter.models.Project)3 Reward (com.kickstarter.models.Reward)3 Test (org.junit.Test)3 KSCurrency (com.kickstarter.libs.KSCurrency)1 MockCurrentConfig (com.kickstarter.mock.MockCurrentConfig)1