Skip to content

Commit

Permalink
Add tests for template provider and support
Browse files Browse the repository at this point in the history
  • Loading branch information
rawagner committed Jan 28, 2021
1 parent f849211 commit b9ac5b4
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 6 deletions.
@@ -1,4 +1,4 @@
{
"numberChecks": "20",
"numberChecks": "64",
"numberViolations": "0"
}
Expand Up @@ -27,6 +27,16 @@ describe('test vm template source image', () => {
});
});

after(() => {
cy.deleteResource({
kind: 'DataVolume',
metadata: {
name: Cypress.env('TEMPLATE_BASE_IMAGE'),
namespace: Cypress.env('OS_IMAGES_NS'),
},
});
});

it('ID(CNV-5652) add Container image and delete', () => {
virtualization.templates.addSource(TEMPLATE);
addSource.addBootSource(ProvisionSource.REGISTRY);
Expand Down Expand Up @@ -68,3 +78,14 @@ describe('test vm template source image', () => {
virtualization.templates.testSource(TEMPLATE, 'Add source');
});
});

describe('test vm template source image provider', () => {
it('Vm Template list shows source provider', () => {
virtualization.templates.addSource(TEMPLATE);
addSource.addBootSource(ProvisionSource.REGISTRY, undefined, 'fooProvider');
virtualization.templates.testSource(TEMPLATE, 'Importing');
virtualization.templates.testSource(TEMPLATE, 'fooProvider');
virtualization.templates.deleteSource(TEMPLATE);
virtualization.templates.testSource(TEMPLATE, 'Add source');
});
});
@@ -0,0 +1,126 @@
import { virtualization } from '../../view/virtualization';
import { testName } from '../../support';
import { wizard } from '../../view/wizard';

const TEMPLATE_NAME = 'foo';
const TEMPLATE_NO_SUPPORT_NAME = 'foo-no-support';

describe('test VM template support', () => {
before(() => {
cy.visit('');
cy.createProject(testName);
});

beforeEach(() => {
virtualization.templates.visit();
});

afterEach(() => {
cy.deleteResource({
kind: 'Template',
metadata: {
name: TEMPLATE_NAME,
namespace: testName,
},
});
cy.deleteResource({
kind: 'Template',
metadata: {
name: TEMPLATE_NO_SUPPORT_NAME,
namespace: testName,
},
});
});

it('details show user supported template', () => {
wizard.template.open();
wizard.template.createTemplate(TEMPLATE_NAME, 'bar', true);
virtualization.templates.testProvider(TEMPLATE_NAME, 'bar');
virtualization.templates.testSource(TEMPLATE_NAME, 'bar');
virtualization.templates.testSupport(
TEMPLATE_NAME,
'bar',
Cypress.env('DOWNSTREAM') ? 'Red Hat' : undefined,
);

wizard.template.open();
wizard.template.createTemplate(TEMPLATE_NO_SUPPORT_NAME, 'bar', false);
virtualization.templates.testProvider(TEMPLATE_NO_SUPPORT_NAME, 'bar');
virtualization.templates.testSource(TEMPLATE_NO_SUPPORT_NAME, 'bar');
virtualization.templates.testSupport(
TEMPLATE_NO_SUPPORT_NAME,
undefined,
Cypress.env('DOWNSTREAM') ? 'Red Hat' : undefined,
);
});

if (Cypress.env('DOWNSTREAM')) {
it('shows support modal for community supported template', () => {
virtualization.templates.testSupport('CentOS 7.0+ VM');
virtualization.templates.clickCreate('CentOS 7.0+ VM');
cy.get('.ReactModal__Overlay').within(() => {
cy.get('a').should('have.attr', 'href', 'https://www.centos.org');
cy.byLegacyTestID('modal-cancel-action').click();
});
});

it('shows no support modal for user supported template based on community supported one', () => {
wizard.template.open();
wizard.template.createTemplate(TEMPLATE_NAME, 'bar', true, 'CentOS 7 or higher');
virtualization.templates.testProvider(TEMPLATE_NAME, 'bar');
virtualization.templates.testSource(TEMPLATE_NAME, 'bar');
virtualization.templates.testSupport(TEMPLATE_NAME, 'bar');
virtualization.templates.clickCreate(TEMPLATE_NAME);
cy.get('.ReactModal__Overlay').should('not.exist');
});

it('shows support modal for user template based on community supported one', () => {
wizard.template.open();
wizard.template.createTemplate(TEMPLATE_NAME, 'bar', false, 'CentOS 7 or higher');
virtualization.templates.testProvider(TEMPLATE_NAME, 'bar');
virtualization.templates.testSource(TEMPLATE_NAME, 'bar');
virtualization.templates.testSupport(TEMPLATE_NAME);
virtualization.templates.clickCreate(TEMPLATE_NAME);
cy.get('.ReactModal__Overlay').within(() => {
cy.get('a').should('have.attr', 'href', 'https://www.centos.org');
cy.byLegacyTestID('modal-cancel-action').click();
});
});

it('shows no support modal for supported template', () => {
virtualization.templates.testSupport('Red Hat Enterprise Linux 8.0+ VM', 'Red Hat');
virtualization.templates.clickCreate('Red Hat Enterprise Linux 8.0+ VM');
cy.get('.ReactModal__Overlay').should('not.exist');
});

it('shows no support modal for user supported template', () => {
wizard.template.open();
wizard.template.createTemplate(
TEMPLATE_NAME,
'bar',
true,
'Red Hat Enterprise Linux 8.0 or higher',
);
virtualization.templates.testProvider(TEMPLATE_NAME, 'bar');
virtualization.templates.testSource(TEMPLATE_NAME, 'bar');
virtualization.templates.testSupport(TEMPLATE_NAME, 'bar', 'Red Hat');
virtualization.templates.clickCreate(TEMPLATE_NAME);
cy.get('.ReactModal__Overlay').should('not.exist');
});

it('shows support modal for user template with no support', () => {
wizard.template.open();
wizard.template.createTemplate(TEMPLATE_NAME, 'bar', false, 'CentOS 7 or higher');
virtualization.templates.testProvider(TEMPLATE_NAME, 'bar');
virtualization.templates.testSource(TEMPLATE_NAME, 'bar');
cy.exec(
`kubectl patch template -n ${testName} ${TEMPLATE_NAME} --type=json -p'[{"op": "remove", "path": "/metadata/annotations/template.kubevirt.ui~1parent-support-level"}, {"op": "remove", "path": "/metadata/annotations/template.kubevirt.ui~1parent-provider-url"}]'`,
);
virtualization.templates.testSupport(TEMPLATE_NAME);
virtualization.templates.clickCreate(TEMPLATE_NAME);
cy.get('.ReactModal__Overlay').within(() => {
cy.byTestID('no-support-description').should('exist');
});
});
}
});
Expand Up @@ -11,7 +11,7 @@ type DiskSourceOpts = {
};

export const addSource = {
addBootSource: (provisionSource: ProvisionSource, opts?: DiskSourceOpts) => {
addBootSource: (provisionSource: ProvisionSource, opts?: DiskSourceOpts, provider?: string) => {
cy.get('#image-source-type-dropdown').click();
cy.get('.pf-c-select__menu')
.contains(provisionSource.getDescription())
Expand All @@ -35,6 +35,9 @@ export const addSource = {
.clear()
.type('1');
}
if (provider) {
cy.get('#form-ds-provider-input').type(provider);
}
if (Cypress.env('STORAGE_CLASS')) {
cy.byTestID('advanced-section').within(() =>
cy
Expand Down
Expand Up @@ -26,6 +26,23 @@ export const virtualization = {
.should('have.text', 'Add source')
.click(),
),
testProvider: (templateName: string, provider: string) =>
getRow(templateName, () => cy.byTestID('template-provider').should('have.text', provider)),
testSupport: (templateName: string, support?: string, parentSupport?: string) => {
getRow(templateName, () => cy.byTestID('template-details').click());
if (support) {
cy.byTestID('template-support').should('exist');
cy.byTestID('template-support').should('have.text', support);
} else {
cy.byTestID('template-support').should('not.exist');
}
if (parentSupport) {
cy.byTestID('template-support-parent').should('exist');
cy.byTestID('template-support-parent').should('have.text', parentSupport);
} else {
cy.byTestID('template-support-parent').should('not.exist');
}
},
testSource: (templateName: string, sourceStatus: string) =>
getRow(templateName, () =>
cy.byTestID('template-source', { timeout: 600000 }).should('have.text', sourceStatus),
Expand All @@ -37,5 +54,7 @@ export const virtualization = {
cy.byTestID('delete-template-source').click();
cy.byTestID('confirm-action').click();
},
clickCreate: (templateName: string) =>
getRow(templateName, () => cy.byTestID('create-from-template').click()),
},
};
@@ -0,0 +1,37 @@
import { ProvisionSource } from '../enums/provisionSource';

export const wizard = {
template: {
open: () => {
cy.byLegacyTestID('details-actions').click();
cy.byLegacyTestID('template-wizard').click();
},
createTemplate: (
name: string,
provider: string,
supported: boolean,
baseOS = 'Red Hat Enterprise Linux 6.0 or higher',
) => {
cy.get('#vm-name').type(name);
cy.get('#template-provider').type(provider);
if (supported) {
cy.get('#template-supported').click();
cy.get('button')
.contains('Support by template provider')
.click();
}
cy.get('#operating-system-dropdown').click();
cy.get('button')
.contains(baseOS)
.click({ force: true });
cy.get('#image-source-type-dropdown').click();
cy.get('.pf-c-select__menu')
.contains(ProvisionSource.REGISTRY.getDescription())
.click();
cy.get('input[id="provision-source-container"]').type(ProvisionSource.REGISTRY.getSource());
cy.get('#create-vm-wizard-reviewandcreate-btn').click();
cy.get('#create-vm-wizard-submit-btn').click();
cy.byTestID('success-list').click();
},
},
};
Expand Up @@ -58,6 +58,7 @@ export const SuccessResultsComponent: React.FC<SuccessResultsProps> = ({
history.push(modelListPath);
onClick && onClick();
}}
data-test="success-list"
>
{t('kubevirt-plugin~Go to list')}
</Button>
Expand Down
Expand Up @@ -48,7 +48,7 @@ const SupportModal: React.FC<SupportModalProps> = ({ onConfirm, close, community
</>
) : (
<>
<StackItem>
<StackItem data-test="no-support-description">
{t(
'kubevirt-plugin~The support level is not defined in the template yaml. To mark this template as supported, add these two annotations in the template details:',
)}
Expand Down
Expand Up @@ -30,12 +30,15 @@ export const VMTemplateLabel: React.FC<VMTemplateLabelProps> = ({ template, clas
<Tooltip
content={t('kubevirt-plugin~{{provider}} supported', { provider: parentProvider })}
>
<Label color="green">{parentProvider}</Label>
<Label data-test="template-support-parent" color="green">
{parentProvider}
</Label>
</Tooltip>
)}
{templateSupport.provider === 'Full' && provider && (
<Tooltip content={t('kubevirt-plugin~{{provider}} supported', { provider })}>
<Label
data-test="template-support"
color={isCommonTemplate(template) ? 'green' : 'blue'}
className={hasParentProvider ? 'kv-template-support__label' : undefined}
>
Expand Down
Expand Up @@ -206,7 +206,9 @@ const VMTemplateTableRow: RowFunction<TemplateItem, VMTemplateTableRowProps> = (
</Link>
{pinned && <PinnedIcon />}
</TableData>
<TableData className={dimensify()}>{getTemplateProvider(t, template)}</TableData>
<TableData data-test="template-provider" className={dimensify()}>
{getTemplateProvider(t, template)}
</TableData>
<TableData className={dimensify()}>
<ResourceLink
kind={NamespaceModel.kind}
Expand All @@ -229,11 +231,16 @@ const VMTemplateTableRow: RowFunction<TemplateItem, VMTemplateTableRowProps> = (
headerContent={t('kubevirt-plugin~Template details')}
bodyContent={<VMTemplateDetailsBody template={template} sourceStatus={sourceStatus} />}
>
<Button variant="link" className="kubevirt-vm-template-details">
<Button
variant="link"
className="kubevirt-vm-template-details"
data-test="template-details"
>
{t('kubevirt-plugin~Details')}
</Button>
</Popover>
<Button
data-test="create-from-template"
onClick={() => withSupportModal(obj, () => createVMAction(obj, sourceStatus, namespace))}
variant="secondary"
>
Expand Down

0 comments on commit b9ac5b4

Please sign in to comment.