Skip to content

Commit

Permalink
Reverse Order Button is now disabled instead of removed upon empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
donatbrzoska authored and Jonas Grabber committed Nov 9, 2020
1 parent 4e58c0f commit df5495f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions webapp/dojo_news/src/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ describe("Reverse Order Button", () => {
}
});

expect(wrapperWithEmptyList.text()).not.toContain("Reverse Order");
expect(wrapperWithEmptyList.find("#reverse-order-button").element.hasAttribute("disabled")).toBeTruthy();
expect(wrapperWithEmptyList.find("#reverse-order-button").element.getAttribute("disabled")).toEqual("disabled");
});

it('Reverse-Button is hidden upon empty list', async () => {
Expand All @@ -190,14 +191,16 @@ describe("Reverse Order Button", () => {
]
}
});
expect(wrapper.text()).toContain("Reverse Order");
expect(wrapper.find("#reverse-order-button").element.hasAttribute("disabled")).not.toBeTruthy();
expect(wrapper.find("#reverse-order-button").element.getAttribute("disabled")).not.toEqual("disabled");

wrapper.vm.removeNewsListItem(0);
wrapper.vm.removeNewsListItem(1);
wrapper.vm.removeNewsListItem(2);
await Vue.nextTick();

expect(wrapper.text()).not.toContain("Reverse Order");
expect(wrapper.find("#reverse-order-button").element.hasAttribute("disabled")).toBeTruthy();
expect(wrapper.find("#reverse-order-button").element.getAttribute("disabled")).toEqual("disabled");
});

it('Reverse-Button shows up again upon non-empty list', async () => {
Expand All @@ -206,11 +209,13 @@ describe("Reverse Order Button", () => {
initialNewsListItems: []
}
});
expect(wrapperWithEmptyList.text()).not.toContain("Reverse Order");
expect(wrapperWithEmptyList.find("#reverse-order-button").element.hasAttribute("disabled")).toBeTruthy();
expect(wrapperWithEmptyList.find("#reverse-order-button").element.getAttribute("disabled")).toEqual("disabled");

wrapperWithEmptyList.vm.createNewsListItem("Test");
await Vue.nextTick();

expect(wrapperWithEmptyList.text()).toContain("Reverse Order");
expect(wrapperWithEmptyList.find("#reverse-order-button").element.hasAttribute("disabled")).not.toBeTruthy();
expect(wrapperWithEmptyList.find("#reverse-order-button").element.getAttribute("disabled")).not.toEqual("disabled");
});
});
2 changes: 1 addition & 1 deletion webapp/dojo_news/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</div>
</div>
<NewsListItemInput @create="createNewsListItem($event);"/>
<button type="button" @click="toggleOrder()" v-if="newsListItems.length" id="reverse-order-button">Reverse Order
<button type="button" @click="toggleOrder()" :disabled="!newsListItems.length" id="reverse-order-button">Reverse Order
</button>
</div>
</template>
Expand Down

0 comments on commit df5495f

Please sign in to comment.