From e9704ecd6f031282d910f44e3291a9a0bb40efa2 Mon Sep 17 00:00:00 2001 From: p0ps Date: Thu, 3 Sep 2020 20:01:47 +0200 Subject: [PATCH] Fix show-selector.vue using the correct show lists. (#8426) * Fix show-selector.vue using the correct show lists. * Fix sorting in show-selector.vue * Don't display current opened show in show history list. * Fix jest snapshot tests for show-selector.spec.js * Fix jest test for app-header.spec.js * * Fix jest test for app-header.spec.js You want to mock a route? Don't. Just use computed. * Remove useless import --- .../slim/src/components/app-header.vue | 27 +- .../src/components/helpers/show-selector.vue | 79 +-- .../slim/src/components/show-list/index.vue | 3 - .../slim/test/__fixtures__/show-lists.json | 659 ++++++++++++++++++ .../slim/test/__fixtures__/shows.json | 443 +++++++++++- .../__snapshots__/app-header.spec.js.snap | 12 - .../__snapshots__/show-selector.spec.js.snap | 245 +++++-- .../slim/test/specs/app-header.spec.js | 11 +- .../slim/test/specs/show-selector.spec.js | 43 +- themes/dark/assets/js/medusa-runtime.js | 12 +- themes/light/assets/js/medusa-runtime.js | 12 +- 11 files changed, 1382 insertions(+), 164 deletions(-) create mode 100644 themes-default/slim/test/__fixtures__/show-lists.json diff --git a/themes-default/slim/src/components/app-header.vue b/themes-default/slim/src/components/app-header.vue index 5c812cb0c7..3dcee438ed 100644 --- a/themes-default/slim/src/components/app-header.vue +++ b/themes-default/slim/src/components/app-header.vue @@ -123,14 +123,29 @@ export default { username: state => state.auth.user.username, warningLevel: state => state.config.general.logs.loggingLevels.warning }), + /** + * Moved into a computed, so it's easier to mock in Jest. + * @returns {Object} - Route name and query. + */ + currentShowRoute() { + const { $route } = this; + return { + name: $route.name, + query: $route.query + }; + }, recentShows() { - const { config } = this; + const { config, currentShowRoute } = this; const { recentShows } = config; - return recentShows.map(show => { - const { name, indexerName, showId } = show; - const link = `home/displayShow?indexername=${indexerName}&seriesid=${showId}`; - return { name, link }; - }); + + const showAlreadyActive = show => !currentShowRoute.name === 'show' || !(show.indexerName === currentShowRoute.query.indexername && show.showId === Number(currentShowRoute.query.seriesid)); + + return recentShows.filter(showAlreadyActive) + .map(show => { + const { name, indexerName, showId } = show; + const link = `home/displayShow?indexername=${indexerName}&seriesid=${showId}`; + return { name, link }; + }); }, topMenu() { return this.$route.meta.topMenu; diff --git a/themes-default/slim/src/components/helpers/show-selector.vue b/themes-default/slim/src/components/helpers/show-selector.vue index 470a6cb44d..dbe4c51975 100644 --- a/themes-default/slim/src/components/helpers/show-selector.vue +++ b/themes-default/slim/src/components/helpers/show-selector.vue @@ -5,21 +5,24 @@