|
| 1 | +/* |
| 2 | + * #%L |
| 3 | + * GwtMaterial |
| 4 | + * %% |
| 5 | + * Copyright (C) 2015 - 2021 GwtMaterialDesign |
| 6 | + * %% |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + * #L% |
| 19 | + */ |
| 20 | +package gwt.material.design.client.mixin; |
| 21 | + |
| 22 | +import gwt.material.design.client.base.mixin.StatusTextMixin; |
| 23 | +import gwt.material.design.client.constants.CssName; |
| 24 | +import gwt.material.design.client.ui.MaterialLabel; |
| 25 | +import gwt.material.design.client.ui.MaterialTextBox; |
| 26 | + |
| 27 | +public class StatusTextMixinTest extends AbstractMixinTest<StatusTextMixin<MaterialTextBox, MaterialLabel>> { |
| 28 | + |
| 29 | + @Override |
| 30 | + protected void runTest(StatusTextMixin<MaterialTextBox, MaterialLabel> mixin) { |
| 31 | + // Given |
| 32 | + MaterialLabel label = mixin.getTextObject(); |
| 33 | + String SUCCESS_TEXT = "Success"; |
| 34 | + String ERROR_TEXT = "Error"; |
| 35 | + String HELPER_TEXT = "Helper"; |
| 36 | + |
| 37 | + // When Apply Success Text |
| 38 | + mixin.setSuccessText(SUCCESS_TEXT); |
| 39 | + |
| 40 | + // Then |
| 41 | + assertEquals(label.getText(), SUCCESS_TEXT); |
| 42 | + assertTrue(label.isVisible()); |
| 43 | + assertTrue(label.getElement().hasClassName(CssName.FIELD_SUCCESS_LABEL)); |
| 44 | + |
| 45 | + // When Success Text is Cleared |
| 46 | + mixin.clearSuccessText(); |
| 47 | + |
| 48 | + // Then |
| 49 | + assertEquals("", label.getText()); |
| 50 | + assertFalse(label.isVisible()); |
| 51 | + assertFalse(label.getElement().hasClassName(CssName.FIELD_SUCCESS_LABEL)); |
| 52 | + |
| 53 | + // When Apply Error Text |
| 54 | + mixin.setErrorText(ERROR_TEXT); |
| 55 | + |
| 56 | + // Then |
| 57 | + assertEquals(label.getText(), ERROR_TEXT); |
| 58 | + assertTrue(label.isVisible()); |
| 59 | + assertTrue(label.getElement().hasClassName(CssName.FIELD_ERROR_LABEL)); |
| 60 | + |
| 61 | + // When Error Text is Cleared |
| 62 | + mixin.clearErrorText(); |
| 63 | + assertEquals("", label.getText()); |
| 64 | + assertFalse(label.isVisible()); |
| 65 | + assertFalse(label.getElement().hasClassName(CssName.FIELD_ERROR_LABEL)); |
| 66 | + |
| 67 | + // When Apply Helper Text |
| 68 | + mixin.setHelperText(HELPER_TEXT); |
| 69 | + |
| 70 | + // Then |
| 71 | + assertEquals(label.getText(), HELPER_TEXT); |
| 72 | + assertTrue(label.isVisible()); |
| 73 | + assertTrue(label.getElement().hasClassName(CssName.FIELD_HELPER_LABEL)); |
| 74 | + |
| 75 | + // When Helper Text is cleared |
| 76 | + mixin.clearHelperText(); |
| 77 | + |
| 78 | + // Then |
| 79 | + assertEquals("", label.getText()); |
| 80 | + assertFalse(label.isVisible()); |
| 81 | + assertFalse(label.getElement().hasClassName(CssName.FIELD_HELPER_LABEL)); |
| 82 | + |
| 83 | + // Given |
| 84 | + mixin.setSuccessText(SUCCESS_TEXT); |
| 85 | + mixin.setErrorText(ERROR_TEXT); |
| 86 | + mixin.setHelperText(HELPER_TEXT); |
| 87 | + |
| 88 | + // When Status Text is cleared |
| 89 | + mixin.clearStatusText(); |
| 90 | + |
| 91 | + // Then |
| 92 | + assertFalse(label.getElement().hasClassName(CssName.FIELD_ERROR_LABEL)); |
| 93 | + assertFalse(label.getElement().hasClassName(CssName.FIELD_SUCCESS_LABEL)); |
| 94 | + assertTrue(label.getElement().hasClassName(CssName.FIELD_HELPER_LABEL)); |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + protected StatusTextMixin<MaterialTextBox, MaterialLabel> setupMixin() { |
| 99 | + return new StatusTextMixin<>(new MaterialTextBox(), new MaterialLabel()); |
| 100 | + } |
| 101 | +} |
0 commit comments