-
-
Notifications
You must be signed in to change notification settings - Fork 180
Addition of Unit Tests for LicenseDropdown.vue #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fe7bce8
eb3f3a9
a5045b0
1a80a0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,67 +1,69 @@ | ||
| <template> | ||
| <b-field class="license-dropdown"> | ||
| <b-select | ||
| :placeholder="this.$t('stepper.DD.placeholder')" | ||
| :value="shortName" | ||
| @input="setCurrentLicense" | ||
| > | ||
| <option | ||
| v-for="license in licenseList" | ||
| :key="license" | ||
| :value="license" | ||
| > | ||
| {{ license }} | ||
| </option> | ||
| </b-select> | ||
| </b-field> | ||
| <b-field class="license-dropdown"> | ||
| <b-select | ||
| class="select" | ||
| :placeholder="this.$t('stepper.DD.placeholder')" | ||
| :value="shortName" | ||
| @input="setCurrentLicense" | ||
| > | ||
| <option | ||
| class="options" | ||
| v-for="license in licenseList" | ||
| :key="license" | ||
| :value="license" | ||
| >{{ license }}</option> | ||
| </b-select> | ||
| </b-field> | ||
| </template> | ||
| <script> | ||
| import { mapGetters } from 'vuex' | ||
| import { mapGetters } from "vuex"; | ||
| export default { | ||
| name: 'SelectedLicenseDropdown', | ||
| data() { | ||
| return { | ||
| licenseList: [ | ||
| 'CC0 1.0', | ||
| 'CC BY 4.0', | ||
| 'CC BY-SA 4.0', | ||
| 'CC BY-ND 4.0', | ||
| 'CC BY-NC 4.0', | ||
| 'CC BY-NC-SA 4.0', | ||
| 'CC BY-NC-ND 4.0' | ||
| ], | ||
| currentLicense: undefined | ||
| } | ||
| }, | ||
| computed: { | ||
| ...mapGetters(['shortName', 'fullName']) | ||
| }, | ||
| methods: { | ||
| setCurrentLicense(currentLicense) { | ||
| this.$store.commit('updateAttributesFromShort', currentLicense) | ||
| this.$emit('input') | ||
| if (process.env.NODE_ENV === 'production') { | ||
| this.$ga.event({ | ||
| eventCategory: 'LicenseDropdown', | ||
| eventAction: 'licenseSelected', | ||
| eventLabel: currentLicense | ||
| }) | ||
| } | ||
| } | ||
| name: "SelectedLicenseDropdown", | ||
| data() { | ||
| return { | ||
| licenseList: [ | ||
| "CC0 1.0", | ||
| "CC BY 4.0", | ||
| "CC BY-SA 4.0", | ||
| "CC BY-ND 4.0", | ||
| "CC BY-NC 4.0", | ||
| "CC BY-NC-SA 4.0", | ||
| "CC BY-NC-ND 4.0" | ||
| ], | ||
| currentLicense: undefined | ||
| }; | ||
| }, | ||
| computed: { | ||
| ...mapGetters(["shortName", "fullName"]) | ||
| }, | ||
| methods: { | ||
| setCurrentLicense(currentLicense) { | ||
| this.$store.commit("updateAttributesFromShort", currentLicense); | ||
| this.$emit("input"); | ||
| if (process.env.NODE_ENV === "production") { | ||
| this.$ga.event({ | ||
| eventCategory: "LicenseDropdown", | ||
| eventAction: "licenseSelected", | ||
| eventLabel: currentLicense | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| </script> | ||
| <style lang="scss"> | ||
| .license-dropdown { | ||
| margin-top: 1rem; | ||
| .label{ | ||
| font-weight: normal; | ||
| opacity: 0.8; | ||
| font-size: 1em; | ||
| } | ||
| .select, select { | ||
| width: 100%; | ||
| } | ||
| } | ||
| .license-dropdown { | ||
| margin-top: 1rem; | ||
| .label { | ||
| font-weight: normal; | ||
| opacity: 0.8; | ||
| font-size: 1em; | ||
| } | ||
| .select, | ||
| select { | ||
| width: 100%; | ||
| } | ||
| } | ||
| </style> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { mount, createLocalVue, config } from "@vue/test-utils"; | ||
| import LicenseDropdown from "@/Components/LicenseDropdown.vue"; | ||
| import VueI18n from "vue-i18n"; | ||
| import Vuex from "vuex"; | ||
| import Buefy from "buefy"; | ||
|
|
||
| describe("LicenseDropdown.vue", () => { | ||
| let wrapper; | ||
| let getters; | ||
| let store; | ||
| let state; | ||
|
|
||
| beforeEach(() => { | ||
| const localVue = createLocalVue(); | ||
| localVue.use(VueI18n); | ||
| localVue.use(Vuex); | ||
| localVue.use(Buefy); | ||
|
|
||
| getters = { | ||
| shortName: state => { | ||
| return "name"; | ||
| }, | ||
|
|
||
| fullName: state => { | ||
| return "fullName"; | ||
| } | ||
| }; | ||
| store = new Vuex.Store({ | ||
| store, | ||
| getters | ||
| }); | ||
| const messages = require("@/locales/en.json"); | ||
| const i18n = new VueI18n({ | ||
| locale: "en", | ||
| fallbackLocale: "en", | ||
| messages: messages | ||
| }); | ||
| config.mocks.i18n = i18n; | ||
| config.mocks.$t = key => { | ||
| return i18n.messages[key]; | ||
| }; | ||
| wrapper = mount(LicenseDropdown, { | ||
| localVue, | ||
| store | ||
| }); | ||
| }); | ||
|
|
||
| it("Has the field tag", () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When testing multiple markup features (field tag, option tag, etc) it is better to use snapshot testing, because it checks for multiple features in one test. |
||
| expect(wrapper.contains(".license-dropdown")).toBe(true); | ||
| }); | ||
|
|
||
| it("Has the option tag", () => { | ||
| expect(wrapper.contains(".options")).toBe(true); | ||
| }); | ||
|
|
||
| it("should emit input event from setCurrentLicense method", async () => { | ||
| wrapper.vm.$emit("input"); | ||
| await wrapper.vm.$nextTick(); | ||
| expect(wrapper.emitted().input).toBeTruthy(); | ||
| }); | ||
|
|
||
| it("Checks whether select element is getting triggered", () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test doesn't seem to test anything. |
||
| wrapper | ||
| .findAll(".select") | ||
| .at(0) | ||
| .trigger("input"); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that your editor is applying some styling changes that are incompatible with the style of this repo. Could you please run a linter before committing files? (
npm run-script lint)