Skip to content

Commit

Permalink
Merge pull request learningequality#12105 from AlexVelezLl/fix-vtl-ro…
Browse files Browse the repository at this point in the history
…uting-bugs

Fix Vue Tesing Library routes bug
  • Loading branch information
rtibbles authored Apr 24, 2024
2 parents 71f2f64 + 3e30d2c commit 0de2806
Show file tree
Hide file tree
Showing 15 changed files with 12 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { render, screen } from '@testing-library/vue';
import VueRouter from 'vue-router';
import userEvent from '@testing-library/user-event';
import ContentRendererError from '../ContentRendererError.vue';

// Helper function to render the component with given props and a router
const renderComponent = props => {
return render(ContentRendererError, {
props,
routes: new VueRouter(),
});
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { render, screen } from '@testing-library/vue';
import VueRouter from 'vue-router';
import ContentRendererLoading from '../ContentRendererLoading.vue';

describe('ContentRendererLoading', () => {
test('the component should render correctly', () => {
render(ContentRendererLoading, {
routes: new VueRouter(),
});
render(ContentRendererLoading);

expect(screen.getByRole('progressbar')).toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Vue from 'vue';
import { render, screen } from '@testing-library/vue';
import VueRouter from 'vue-router';
import useUser, { useUserMock } from 'kolibri.coreVue.composables.useUser';
import DownloadButton from '../DownloadButton.vue';
import { RENDERER_SUFFIX } from '../constants';
Expand Down Expand Up @@ -35,7 +34,6 @@ const renderComponent = props => {
);

return render(DownloadButton, {
routes: new VueRouter(),
props: {
files: [],
nodeTitle: '',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { render, screen } from '@testing-library/vue';
import VueRouter from 'vue-router';
import CoreMenuDivider from '../CoreMenuDivider.vue';

describe('CoreMenuDivider', () => {
test('renders the component', () => {
render(CoreMenuDivider, {
routes: new VueRouter(),
});
render(CoreMenuDivider);

expect(screen.getByRole('listitem')).toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { render, screen } from '@testing-library/vue';
import '@testing-library/jest-dom';
import VueRouter from 'vue-router';
import { themeTokens } from 'kolibri-design-system/lib/styles/theme';
import AttemptIconDiff from '../AttemptIconDiff.vue';

Expand All @@ -14,7 +13,6 @@ const renderComponent = props => {
diff: 1,
...props,
},
routes: new VueRouter(),
});
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { render, screen } from '@testing-library/vue';
import '@testing-library/jest-dom';
import VueRouter from 'vue-router';
import AttemptTextDiff from '../AttemptTextDiff.vue';

const renderComponent = props => {
return render(AttemptTextDiff, {
routes: new VueRouter(),
props,
store: {
getters: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { render, screen } from '@testing-library/vue';
import '@testing-library/jest-dom';
import VueRouter from 'vue-router';
import TriesOverview from '../TriesOverview.vue';
import * as tryValidatorModule from '../utils';

Expand Down Expand Up @@ -33,7 +32,6 @@ const renderComponent = props => {
...defaultProps,
...props,
},
routes: new VueRouter(),
mixins: [commonCoreStrings],
});
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { render, screen } from '@testing-library/vue';
import VueRouter from 'vue-router';
import { themeTokens } from 'kolibri-design-system/lib/styles/theme';
import InteractionItem from '../InteractionItem.vue';

Expand All @@ -11,7 +10,6 @@ const renderComponent = props => {

return render(InteractionItem, {
props: { ...defaultProps, ...props },
routes: new VueRouter(),
});
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { render, fireEvent, screen } from '@testing-library/vue';
import VueRouter from 'vue-router';
import InteractionList from '../';

const renderComponent = props => {
Expand All @@ -13,7 +12,6 @@ const renderComponent = props => {
...defaultProps,
...props,
},
routes: new VueRouter(),
});
};

Expand Down
2 changes: 0 additions & 2 deletions kolibri/core/assets/src/views/__tests__/TotalPoints.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import VueRouter from 'vue-router';
import { render, screen, fireEvent } from '@testing-library/vue';
import TotalPoints from '../TotalPoints.vue';
import '@testing-library/jest-dom';
Expand All @@ -24,7 +23,6 @@ const getMockStore = () => {
const renderComponent = store => {
return render(TotalPoints, {
store,
routes: new VueRouter(),
});
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { render, screen, fireEvent, waitFor } from '@testing-library/vue';
import VueRouter from 'vue-router';
import { PortalResource, FacilityDatasetResource } from 'kolibri.resources';
import { ERROR_CONSTANTS } from 'kolibri.coreVue.vuex.constants';
import ConfirmationRegisterModal from '../ConfirmationRegisterModal.vue';
Expand All @@ -20,7 +19,6 @@ const renderComponent = props => {
token: sampleToken,
...props,
},
routes: new VueRouter(),
});
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { render, fireEvent, screen } from '@testing-library/vue';
import VueRouter from 'vue-router';
import SelectSourceModal from '../SelectSourceModal.vue';

const renderComponent = props => {
return render(SelectSourceModal, {
props,
routes: new VueRouter(),
});
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import VueRouter from 'vue-router';
import { render, screen } from '@testing-library/vue';
import { FacilityUserGender } from 'kolibri.coreVue.vuex.constants';
import GenderDisplayText from '../GenderDisplayText.vue';
import '@testing-library/jest-dom';

const renderComponent = gender => {
return render(GenderDisplayText, {
routes: new VueRouter(),
props: {
gender,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { render, screen, fireEvent } from '@testing-library/vue';
import VueRouter from 'vue-router';
import GenderSelect from '../GenderSelect.vue';
import '@testing-library/jest-dom';

const renderComponent = () => {
return render(GenderSelect, {
routes: new VueRouter(),
});
return render(GenderSelect);
};

describe('GenderSelect', () => {
Expand Down
9 changes: 9 additions & 0 deletions packages/kolibri-tools/jest.conf/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import logging from 'kolibri.lib.logging';
import { i18nSetup } from 'kolibri.utils.i18n';
import KThemePlugin from 'kolibri-design-system/lib/KThemePlugin';

/* eslint-disable vue/one-component-per-file */

global.beforeEach(() => {
return new Promise(resolve => {
Aphrodite.StyleSheetTestUtils.suppressStyleInjection();
Expand All @@ -35,6 +37,12 @@ logging.setLevel('silent');

// Register Vue plugins and components
Vue.use(Vuex);
Vue.mixin({
beforeCreate: function() {
// This fix some problems between the VueRouter plugin, and Vue-testing-library.
this.$options.router = this.$options.router || undefined;
},
});
Vue.use(VueRouter);
Vue.use(VueMeta);
Vue.use(KThemePlugin);
Expand Down Expand Up @@ -69,3 +77,4 @@ global.flushPromises = function flushPromises() {
scheduler(resolve);
});
};
/* eslint-enable vue/one-component-per-file */

0 comments on commit 0de2806

Please sign in to comment.