2021-11-05 18:12:21 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
2022-02-11 15:14:00 +00:00
|
|
|
import { GlAlert, GlButton, GlEmptyState, GlTable } from '@gitlab/ui';
|
2021-11-25 00:10:49 +00:00
|
|
|
import ServiceAccountsList from '~/google_cloud/components/service_accounts_list.vue';
|
2021-11-05 18:12:21 +00:00
|
|
|
|
|
|
|
describe('ServiceAccounts component', () => {
|
|
|
|
describe('when the project does not have any service accounts', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const findEmptyState = () => wrapper.findComponent(GlEmptyState);
|
|
|
|
const findButtonInEmptyState = () => findEmptyState().findComponent(GlButton);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const propsData = {
|
|
|
|
list: [],
|
|
|
|
createUrl: '#create-url',
|
|
|
|
emptyIllustrationUrl: '#empty-illustration-url',
|
|
|
|
};
|
2021-11-25 00:10:49 +00:00
|
|
|
wrapper = mount(ServiceAccountsList, { propsData });
|
2021-11-05 18:12:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the empty state component', () => {
|
|
|
|
expect(findEmptyState().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
it('shows the link to create new service accounts', () => {
|
|
|
|
const button = findButtonInEmptyState();
|
|
|
|
expect(button.exists()).toBe(true);
|
2022-02-11 15:14:00 +00:00
|
|
|
expect(button.text()).toBe(ServiceAccountsList.i18n.createServiceAccount);
|
2021-11-05 18:12:21 +00:00
|
|
|
expect(button.attributes('href')).toBe('#create-url');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when three service accounts are passed via props', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const findTitle = () => wrapper.find('h2');
|
|
|
|
const findDescription = () => wrapper.find('p');
|
|
|
|
const findTable = () => wrapper.findComponent(GlTable);
|
|
|
|
const findRows = () => findTable().findAll('tr');
|
|
|
|
const findButton = () => wrapper.findComponent(GlButton);
|
2022-02-11 15:14:00 +00:00
|
|
|
const findSecretManagerTip = () => wrapper.findComponent(GlAlert);
|
2021-11-05 18:12:21 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const propsData = {
|
|
|
|
list: [{}, {}, {}],
|
|
|
|
createUrl: '#create-url',
|
|
|
|
emptyIllustrationUrl: '#empty-illustration-url',
|
|
|
|
};
|
2021-11-25 00:10:49 +00:00
|
|
|
wrapper = mount(ServiceAccountsList, { propsData });
|
2021-11-05 18:12:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the title', () => {
|
2022-02-11 15:14:00 +00:00
|
|
|
expect(findTitle().text()).toBe(ServiceAccountsList.i18n.serviceAccountsTitle);
|
2021-11-05 18:12:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the description', () => {
|
2022-02-11 15:14:00 +00:00
|
|
|
expect(findDescription().text()).toBe(ServiceAccountsList.i18n.serviceAccountsDescription);
|
2021-11-05 18:12:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the table', () => {
|
|
|
|
expect(findTable().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('table must have three rows + header row', () => {
|
|
|
|
expect(findRows().length).toBe(4);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the link to create new service accounts', () => {
|
|
|
|
const button = findButton();
|
|
|
|
expect(button.exists()).toBe(true);
|
2022-02-11 15:14:00 +00:00
|
|
|
expect(button.text()).toBe(ServiceAccountsList.i18n.createServiceAccount);
|
2021-11-05 18:12:21 +00:00
|
|
|
expect(button.attributes('href')).toBe('#create-url');
|
|
|
|
});
|
2022-02-11 15:14:00 +00:00
|
|
|
|
|
|
|
it('must contain secret managers tip', () => {
|
|
|
|
const tip = findSecretManagerTip();
|
|
|
|
const expectedText = ServiceAccountsList.i18n.secretManagersDescription.substr(0, 48);
|
|
|
|
expect(tip.text()).toContain(expectedText);
|
|
|
|
});
|
2021-11-05 18:12:21 +00:00
|
|
|
});
|
|
|
|
});
|