/* eslint-disable vue/require-prop-types */
/* eslint-disable vue/one-component-per-file */
import { createWrapper } from '@vue/test-utils';
import Vue from 'vue';
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
import {
initAccessTokenTableApp,
initExpiresAtField,
initNewAccessTokenApp,
initProjectsField,
initTokensApp,
} from '~/access_tokens';
import * as AccessTokenTableApp from '~/access_tokens/components/access_token_table_app.vue';
import * as ExpiresAtField from '~/access_tokens/components/expires_at_field.vue';
import * as NewAccessTokenApp from '~/access_tokens/components/new_access_token_app.vue';
import * as ProjectsField from '~/access_tokens/components/projects_field.vue';
import * as TokensApp from '~/access_tokens/components/tokens_app.vue';
import { FEED_TOKEN, INCOMING_EMAIL_TOKEN, STATIC_OBJECT_TOKEN } from '~/access_tokens/constants';
import { __, sprintf } from '~/locale';
describe('access tokens', () => {
let wrapper;
afterEach(() => {
wrapper?.destroy();
resetHTMLFixture();
});
describe('initAccessTokenTableApp', () => {
const accessTokenType = 'personal access token';
const accessTokenTypePlural = 'personal access tokens';
const initialActiveAccessTokens = [{ id: '1' }];
const FakeAccessTokenTableApp = Vue.component('FakeComponent', {
inject: [
'accessTokenType',
'accessTokenTypePlural',
'initialActiveAccessTokens',
'noActiveTokensMessage',
'showRole',
],
props: [
'accessTokenType',
'accessTokenTypePlural',
'initialActiveAccessTokens',
'noActiveTokensMessage',
'showRole',
],
render: () => null,
});
AccessTokenTableApp.default = FakeAccessTokenTableApp;
it('mounts the component and provides required values', () => {
setHTMLFixture(
`
`,
);
const vueInstance = initAccessTokenTableApp();
wrapper = createWrapper(vueInstance);
const component = wrapper.findComponent(FakeAccessTokenTableApp);
expect(component.exists()).toBe(true);
expect(component.props()).toMatchObject({
// Required value
accessTokenType,
accessTokenTypePlural,
initialActiveAccessTokens,
// Default values
noActiveTokensMessage: sprintf(__('This user has no active %{accessTokenTypePlural}.'), {
accessTokenTypePlural,
}),
showRole: false,
});
});
it('mounts the component and provides all values', () => {
const noActiveTokensMessage = 'This group has no active access tokens.';
setHTMLFixture(
`