Skip to content
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

Change the Anonymous Edit Warning to add TempUser support #598

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h1>New Lexeme</h1>
const config = {
rootSelector: '#app',
isAnonymous: false,
tempUserEnabled: false,
licenseUrl: 'https://creativecommons.org/publicdomain/zero/1.0/',
licenseName: 'Creative Commons CC0',
wikibaseLexemeTermLanguages: new Map([
Expand Down
9 changes: 7 additions & 2 deletions src/components/AnonymousEditWarning.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ import { useConfig } from '@/plugins/ConfigPlugin/Config';
import { useMessages } from '@/plugins/MessagesPlugin/Messages';
import { computed } from 'vue';
import { useAuthenticationLinker } from '@/plugins/AuthenticationLinkerPlugin/AuthenticationLinker';
import MessageKeys from '@/plugins/MessagesPlugin/MessageKeys';

const authenticationLinker = useAuthenticationLinker();
const messages = useMessages();
const config = useConfig();
let messageKey: MessageKeys = 'wikibase-anonymouseditwarning';
if ( config.tempUserEnabled ) {
messageKey = 'wikibase-anonymouseditnotificationtempuser';
}
const warning = computed(
() => messages.get(
'wikibase-anonymouseditwarning',
messageKey,
authenticationLinker.getLoginLink(),
authenticationLinker.getCreateAccountLink(),
) );
const config = useConfig();

</script>

Expand Down
1 change: 1 addition & 0 deletions src/plugins/ConfigPlugin/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface Config {
readonly isAnonymous: boolean;
readonly licenseUrl: string;
readonly licenseName: string;
readonly tempUserEnabled: boolean;
readonly wikibaseLexemeTermLanguages: Map<string, string>;
readonly lexicalCategorySuggestions: SearchedItemOption[];
readonly placeholderExampleData: {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/MessagesPlugin/MessageKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type MessageKeys
| 'wikibaselexeme-newlexeme-lemma-too-long-error'
| 'wikibaselexeme-newlexeme-invalid-language-code-warning'
| 'wikibase-anonymouseditwarning'
| 'wikibase-anonymouseditnotificationtempuser'
| 'wikibase-lexeme-lemma-language-option'
| 'wikibase-entityselector-notfound'
| 'wikibase-shortcopyrightwarning'
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/components/AnonymousEditWarning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,26 @@ describe( 'AnonymousEditWarning', () => {
expect( messages.get ).toHaveBeenCalledWith( 'wikibase-anonymouseditwarning', 'loginLink', 'createAccountLink' );
} );

it( 'uses alternative message if tempuser is enabled', () => {
const messages = { get: jest.fn().mockImplementation( ( ...params ) =>
`(${params.join( ', ' )})`,
) };
const authenticationLinker = {
getLoginLink: jest.fn().mockReturnValue( 'loginLink' ),
getCreateAccountLink: jest.fn().mockReturnValue( 'createAccountLink' ),
};
const warning = mount( AnonymousEditWarning, {
global: {
provide: {
[ ConfigKey as symbol ]: { isAnonymous: true, tempUserEnabled: true },
[ MessagesKey as symbol ]: messages,
[ AuthenticationLinkerKey as symbol ]: authenticationLinker,
},
},
} );

expect( warning.html() ).toMatchSnapshot();
expect( messages.get ).toHaveBeenCalledWith( 'wikibase-anonymouseditnotificationtempuser', 'loginLink', 'createAccountLink' );
} );

} );
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AnonymousEditWarning matches snapshot if anonymous 1`] = `"<div class="wikit wikit-Message wikit-Message--warning wbl-snl-anonymous-edit-warning"><span class="wikit-Message__content"><span class="wikit wikit-Icon wikit-Icon--large wikit-Icon--warning wikit-Message__icon"><svg class="wikit-Icon__svg" xmlns="http://www.w3.org/2000/svg" fill="none" aria-hidden="true" focusable="false" viewBox="0 0 16 16"><path fill="currentColor" d="M9.163 1.68234C9.06078 1.4381 8.89901 1.22746 8.69449 1.07231C8.48997 0.917151 8.25017 0.823144 7.99999 0.800049C7.75116 0.82453 7.51294 0.919178 7.30987 1.07425C7.10679 1.22933 6.94619 1.43922 6.84459 1.68234L0.672272 13.0631C0.0337565 14.2368 0.558251 15.2 1.82768 15.2H14.1723C15.4417 15.2 15.9662 14.2368 15.3277 13.0631L9.163 1.68234ZM8.76013 12.7717H7.23986V11.1528H8.76013V12.7717ZM8.76013 9.53394H7.23986V4.67728H8.76013V9.53394Z"></path></svg></span><span><!-- eslint-disable-next-line vue/no-v-html --><span>(wikibase-anonymouseditwarning, loginLink, createAccountLink)</span></span></span></div>"`;

exports[`AnonymousEditWarning uses alternative message if tempuser is enabled 1`] = `"<div class="wikit wikit-Message wikit-Message--warning wbl-snl-anonymous-edit-warning"><span class="wikit-Message__content"><span class="wikit wikit-Icon wikit-Icon--large wikit-Icon--warning wikit-Message__icon"><svg class="wikit-Icon__svg" xmlns="http://www.w3.org/2000/svg" fill="none" aria-hidden="true" focusable="false" viewBox="0 0 16 16"><path fill="currentColor" d="M9.163 1.68234C9.06078 1.4381 8.89901 1.22746 8.69449 1.07231C8.48997 0.917151 8.25017 0.823144 7.99999 0.800049C7.75116 0.82453 7.51294 0.919178 7.30987 1.07425C7.10679 1.22933 6.94619 1.43922 6.84459 1.68234L0.672272 13.0631C0.0337565 14.2368 0.558251 15.2 1.82768 15.2H14.1723C15.4417 15.2 15.9662 14.2368 15.3277 13.0631L9.163 1.68234ZM8.76013 12.7717H7.23986V11.1528H8.76013V12.7717ZM8.76013 9.53394H7.23986V4.67728H8.76013V9.53394Z"></path></svg></span><span><!-- eslint-disable-next-line vue/no-v-html --><span>(wikibase-anonymouseditnotificationtempuser, loginLink, createAccountLink)</span></span></span></div>"`;
Loading