-
Notifications
You must be signed in to change notification settings - Fork 278
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
cleanup app-link for tests #4526
Conversation
return this.base; | ||
} | ||
|
||
return document.getElementsByTagName('base')[0].getAttribute('href'); |
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.
I don't see any problem with doing this:
const { base } = this;
// Return prop before HTML element to allow tests to mock
return this.base || document.getElementsByTagName('base')[0].getAttribute('href');
It's just a personal preference.
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.
We need to make sure document isn't ever called since it'll throw an error in the tests. I know how bad that sounds but I'll fix it once I move this to a .vue
file.
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.
AFAIK, JavaScript logical statements are evaluated from left to right and not all at once.
Meaning if Boolean(this.base)
is true, it will return that value. As long as you pass the base in the tests, should be good.
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's not that. It's the testing framework seeing it in the AST that's the issue.
computedHref() { | ||
const { indexerId, placeholder } = this; | ||
if (indexerId && placeholder) { | ||
return this.href.replace(placeholder, MEDUSA.config.indexers.indexerIdToName(indexerId)); |
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.
Might as well destructure href
from this
(note the return statement too)
Also to make the switch later easier, I suggest destructuring config
from MEDUSA
(one level would suffice)
const { config } = MEDUSA;
isHashPath() { | ||
return this.computedHref.startsWith('#'); | ||
}, | ||
isAnonymised() { |
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 can already be removed. No references remain (on href
attributes in mako
files).
I'll remove the last one which is the Donations link in another PR (I also changed it on #4519)
It didn't raise an error because it uses this method:
<app-link href="${app.DONATIONS_URL}" rel="noreferrer" onclick="window.open('${app.ANON_REDIRECT}' + this.href); return false;">
// @TODO: Remove this once we move to vue only | ||
if (isAnonymised) { | ||
throw new Error('Still using anon_url in Python!'); | ||
} |
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.
Same, can be removed.
}; | ||
} | ||
}, | ||
template: `#app-link-template` | ||
template: '#app-link-template' |
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.
I think our style is to put the template property right below the component name. Let's do that :)
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.
We need to create a styles guide for things like this on the wiki.
@@ -13,6 +13,7 @@ | |||
<script> | |||
Vue.component('app-link', { | |||
name: 'app-link', |
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.
This line is redundant, please remove it.
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.
This is for future usage.
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.
Okay, then remove the one above it, which overrides the first argument to Vue.component
.
}, | ||
computed: { | ||
config() { | ||
return this.$store.state.config; | ||
}, |
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.
Is that for future usage?
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.
This is for future usage.
This comment has been minimized.
This comment has been minimized.
if (config.indexers[indexer].id === parseInt(indexerId, 10)) { | ||
return config.indexers[indexer].name; | ||
} | ||
})[0]; |
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.
- The keys of
config.indexers
don't contain the indexer names,
it'sconfig.indexers.config.indexers
. see below [1].
It's because of the MEDUSA.config structure. When we stop using it we should be able to fix that... - This can use
find
instead of filter, and be much simpler.
This array iteration is so confusing. We don't return the name, we return the key (which is the identifier).
name=TVDBv2 | identifier=tvdb
const { indexers } = config.indexers.config; // This is weird, I know...
// Returns `undefined` if not found.
return Object.keys(indexers).find(indexer => indexers[indexer].id === parseInt(indexerId, 10));
[1]
{ store.state
"config": {
"indexers": {
"config": {
"indexers": {
"tvdb": {
"xemOrigin": "tvdb",
"apiParams": {
"useZip": true,
"language": "en"
},
"showUrl": "https://www.thetvdb.com/dereferrer/series/",
"id": 1,
"icon": "thetvdb16.png",
"name": "TVDBv2",
"scene_loc": "https://cdn.pymedusa.com/scene_exceptions/scene_exceptions_tvdb.json",
"enabled": true,
"baseUrl": "https://api.thetvdb.com/",
"mappedTo": "tvdb_id",
"identifier": "tvdb"
},
"tmdb": {
"xemOrigin": null,
"apiParams": {
"useZip": true,
"language": "en"
},
"showUrl": "https://www.themoviedb.org/tv/",
"id": 4,
"icon": "tmdb16.png",
"name": "TMDB",
"scene_loc": "https://cdn.pymedusa.com/scene_exceptions/scene_exceptions_tmdb.json",
"enabled": true,
"baseUrl": "https://www.themoviedb.org/",
"mappedTo": "tmdb_id",
"identifier": "tmdb"
},
"tvmaze": {
"xemOrigin": null,
"apiParams": {
"useZip": true,
"language": "en"
},
"showUrl": "http://www.tvmaze.com/shows/",
"id": 3,
"icon": "tvmaze16.png",
"name": "TVmaze",
"scene_loc": "https://cdn.pymedusa.com/scene_exceptions/scene_exceptions_tvmaze.json",
"enabled": true,
"baseUrl": "http://api.tvmaze.com/",
"mappedTo": "tvmaze_id",
"identifier": "tvmaze"
}
},
"main": {
"externalMappings": {<truncated>},
"statusMap": {<truncated>},
"traktIndexers": {<truncated>},
"validLanguages": [<truncated>],
"langabbvToId": {<truncated>}
}
}
}
}
}
if (to) { | ||
return { | ||
is: 'router-link', | ||
to: { name: href } |
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.
Side note...
Have you tried it? This technique doesn't seem to actually work.
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.
How did you test this? The to
needs to be the name of a loaded route.
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.
When on the help and info page:
<app-link to="not-found">Not Found</app-link>
<app-link to="config">Help & Info</app-link>
And the elements I got in the DOM are:
<a class="router-link-exact-active router-link-active">Not Found</a>
<a class="router-link-exact-active router-link-active">Help & Info</a>
It doesn't work even when I put the links inside the routes, like in config.vue
and 404.vue
.
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.
<router-link>
in the same locations, works just fine.
<router-link :to="{ name: 'not-found' }">Not Found</router-link>
<router-link :to="{ name: 'config' }">Help & Info</router-link>
<a href="/not-found" class="">Not Found</a>
<a href="/config" class="router-link-exact-active router-link-active">Help & Info</a>
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.
I think we should replace to: { name: href }
with to
then it'll just pass the whole object through or we could just straight out remove that ability and move those links to router-link
?
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.
I think we should replace
to: { name: href }
withto
then it'll just pass the whole object through
Just tried that, doesn't seem to work still.
or we could just straight out remove that ability and move those links to
router-link
?
If we can't figure it out, then yes...
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.
Did you check what the AppLink's computed props were? This is why we need tests.
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.
Shall we merge and then fix this in the test PR?
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.
Shall we merge and then fix this in the test PR?
No, the app link component is broken on this branch.
Give me a few minutes I'll push a commit to fix everything.
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.
I'll try and fix this another time. Fixed the other errors.
wait, I'm getting console errors on this branch (let me check) |
The first argument for `Vue.component` must be the name. It won't register the component without it.
``` vue.js:597 [Vue warn]: Error in render: "TypeError: Cannot read property 'startsWith' of null" found in ---> <AppLink> <Config> <Root> ```
This will allow us to use Ava tests against this component once #4374 is merged.
Related #4519 see #4526 (comment)