Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Adding tab change event emitter #85

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
:locale="selectedLocale"
:cronSyntax="selectedSyntax"
v-model="sample1CronExpression"
@change-selected-tab="handleChangeSelectedTab"
></VueCronEditorBuefy>
</section>
{{ sample1CronExpression }}
Expand Down Expand Up @@ -136,6 +137,10 @@
</template>
</v-data-table>
</section>

<v-snackbar v-model="snackbar" timeout="1000">
{{ snackbarText }}
</v-snackbar>
</v-container>
</v-app>
</template>
Expand Down Expand Up @@ -178,6 +183,10 @@ export default {
this.expressions[newIndex - 1].id = newIndex;
}
this.close();
},
handleChangeSelectedTab(selectedTab) {
this.snackbar = true;
this.snackbarText = `Selected tab: ${selectedTab.key}, id: ${selectedTab.id}`;
}
},
data: () => ({
Expand All @@ -202,7 +211,9 @@ export default {
"monthly",
"advanced"
],
syntaxes: ["basic", "quartz"]
syntaxes: ["basic", "quartz"],
snackbar: false,
snackbarText: ""
})
};
</script>
4 changes: 4 additions & 0 deletions src/buefy/VueCronEditorBuefy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ export default {
watch: {
currentTab() {
this.activeTab = this.tabs.find(t => t.key === this.currentTab).id;
this.activeTab &&
this.$emit("change-selected-tab", {
...this.tabs[this.activeTab]
});
}
},
computed: {
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/changingSelectedTab.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { shallowMount } from "@vue/test-utils";
import VueCronEditorBuefy from "../../src/buefy/VueCronEditorBuefy.vue";

function getMountedComponent(Component: any, propsData: any) {
return shallowMount(Component, {
propsData
});
}

describe("changingSelectedTab", () => {
it("triggers an $emit event", async () => {
let component = getMountedComponent(VueCronEditorBuefy, {});
await component.setData({ currentTab: "monthly" });
let emitted = component.emitted("change-selected-tab");
expect(emitted).toBeTruthy();
expect(emitted && emitted[0][0]).toEqual({ id: "4", key: "monthly" });

await component.setData({ currentTab: "weekly" });
emitted = component.emitted("change-selected-tab");
expect(emitted).toBeTruthy();
expect(emitted && emitted[1][0]).toEqual({ id: "3", key: "weekly" });
});
});