Skip to content

Commit

Permalink
update authmessage test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
nucleogenesis committed Oct 25, 2024
1 parent c8a6c37 commit 63243b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions kolibri/core/assets/src/views/AuthMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
:text="linkText"
:href="signInLink"
appearance="basic-link"
data-test="signinlink"
/>
</p>
<p v-else>
<KExternalLink
:text="$tr('goBackToHomeAction')"
:href="rootUrl"
appearance="basic-link"
data-test="gohomelink"
/>
</p>
</div>
Expand Down
21 changes: 15 additions & 6 deletions kolibri/core/assets/test/views/auth-message.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { shallowMount, createLocalVue } from '@vue/test-utils';
import AuthMessage from '../../src/views/AuthMessage';
import { stubWindowLocation } from 'testUtils'; // eslint-disable-line

jest.mock('urls', () => ({}));
jest.mock('kolibri.urls');

const localVue = createLocalVue();

Expand Down Expand Up @@ -97,7 +97,7 @@ describe('auth message component', () => {

it('shows correct link text if there is a user plugin', () => {
const wrapper = makeWrapper();
const link = wrapper.find('kexternallink-stub');
const link = wrapper.find('[data-test=signinlink]');
expect(link.attributes()).toMatchObject({
href: 'http://localhost:8000/en/auth/#/signin?next=http%3A%2F%2Flocalhost%3A8000%2F%23%2Ftest_url',
text: 'Sign in to Kolibri',
Expand All @@ -107,7 +107,7 @@ describe('auth message component', () => {
it('if the next param is in URL, it is what is used in the sign-in page link', () => {
window.location.href = 'http://localhost:8000/#/some_other_url';
const wrapper = makeWrapper();
const link = wrapper.find('kexternallink-stub');
const link = wrapper.find('[data-test=signinlink]');
expect(link.attributes()).toMatchObject({
href: 'http://localhost:8000/en/auth/#/signin?next=http%3A%2F%2Flocalhost%3A8000%2F%23%2Fsome_other_url',
text: 'Sign in to Kolibri',
Expand All @@ -116,8 +116,17 @@ describe('auth message component', () => {
});

it('shows correct link text if there is not a user plugin', () => {
const wrapper = makeWrapper();
const link = wrapper.find('kexternallink-stub');
// linkText checks to see if `userAuthPluginUrl` is truthy and it's either a
// function or undefined and if there is no user plugin, then it needs to be
// falsy for this test case
const wrapper = makeWrapper({
computed: {
userAuthPluginUrl() {
return false;
},
},
});
const link = wrapper.find('[data-test=signinlink]');
expect(link.attributes()).toMatchObject({
href: '/',
text: 'Go to home page',
Expand All @@ -133,6 +142,6 @@ describe('auth message component', () => {
},
});
const wrapper = makeWrapper({ store });
expect(wrapper.find('kexternallink-stub').exists()).toBe(false);
expect(wrapper.find('[data-test=signinlink]').exists()).toBe(false);
});
});

0 comments on commit 63243b0

Please sign in to comment.