Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
- Refactor tests to make the [using node attributes, using node roles] branch and the various conditions within easier to contrast and compare.
- Add coverage for NoTiersAvailableUsingNodeAttributesNotice scenario.
- Add some helpers for improved maintainability and readability.
  • Loading branch information
cjcenizal committed Apr 30, 2021
1 parent 923a6c2 commit fd44a88
Show file tree
Hide file tree
Showing 4 changed files with 279 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,166 +46,181 @@ describe('<EditPolicy /> node allocation in the cold phase', () => {
component.update();
});

test('shows spinner for node attributes input when loading', async () => {
server.respondImmediately = false;

const { actions, component } = testBed;
await actions.enable(true);

expect(component.find('.euiLoadingSpinner').exists()).toBeTruthy();
expect(actions.hasDataTierAllocationControls()).toBeTruthy();

expect(component.find('.euiCallOut--warning').exists()).toBeFalsy();
expect(actions.hasNodeAttributesSelect()).toBeFalsy();
});

test('offers DATA TIER allocation guidance when no attributes exist and data tiers are available', async () => {
test(`doesn't offer allocation guidance when node with deprecated "data" role exists`, async () => {
httpRequestsMockHelpers.setListNodes({
nodesByAttributes: {},
nodesByRoles: { data: ['node1'] },
nodesByRoles: { data: ['test'] },
isUsingDeprecatedDataRoleConfig: false,
});

await setup();
const { actions, component } = testBed;

component.update();
await actions.enable(true);

expect(component.find('.euiLoadingSpinner').exists()).toBeFalsy();
await actions.setDataAllocation('node_attrs');
expect(actions.hasDefaultToDataTiersNotice()).toBeTruthy();
expect(actions.hasNodeAttributesSelect()).toBeFalsy();
expect(actions.isAllocationLoading()).toBeFalsy();
expect(actions.hasWillUseFallbackTierNotice()).toBeFalsy();
});

test('offers DATA TIER FALLBACK allocation guidance when no attributes exist and data tiers are available, but not for the cold phase', async () => {
httpRequestsMockHelpers.setListNodes({
nodesByAttributes: {},
nodesByRoles: { data_warm: ['node1'] },
isUsingDeprecatedDataRoleConfig: false,
});
describe('when using node attributes', () => {
test('shows spinner for node attributes input when loading', async () => {
server.respondImmediately = false;

await setup();
const { actions, component } = testBed;

component.update();
await actions.enable(true);
const { actions } = testBed;
await actions.enable(true);

expect(component.find('.euiLoadingSpinner').exists()).toBeFalsy();
await actions.setDataAllocation('node_attrs');
expect(actions.hasWillUseFallbackTierNotice()).toBeTruthy();
expect(actions.hasNodeAttributesSelect()).toBeFalsy();
});
expect(actions.isAllocationLoading()).toBeTruthy();
expect(actions.hasDataTierAllocationControls()).toBeTruthy();
expect(actions.hasNodeAttributesSelect()).toBeFalsy();

test('offers DATA NODE allocation guidance when no attributes exist and data nodes are in use', async () => {
httpRequestsMockHelpers.setListNodes({
nodesByAttributes: {},
nodesByRoles: {},
isUsingDeprecatedDataRoleConfig: true,
// No notices will be shown.
expect(actions.hasDefaultToDataTiersNotice()).toBeFalsy();
expect(actions.hasWillUseFallbackTierUsingNodeAttributesNotice()).toBeFalsy();
expect(actions.hasDefaultToDataNodesNotice()).toBeFalsy();
expect(actions.hasNoTiersAvailableUsingNodeAttributesNotice()).toBeFalsy();
});

await setup();
const { actions, component } = testBed;

component.update();
await actions.enable(true);
describe('and some are defined', () => {
test('shows the node attributes input', async () => {
const { actions } = testBed;
await actions.enable(true);

expect(component.find('.euiLoadingSpinner').exists()).toBeFalsy();
await actions.setDataAllocation('node_attrs');
expect(actions.hasDefaultToDataNodesNotice()).toBeTruthy();
expect(actions.hasNodeAttributesSelect()).toBeFalsy();
});
expect(actions.isAllocationLoading()).toBeFalsy();
await actions.setDataAllocation('node_attrs');
expect(actions.hasDefaultAllocationBehaviorNotice()).toBeFalsy();
expect(actions.hasNodeAttributesSelect()).toBeTruthy();
expect(actions.getNodeAttributesSelectOptions().length).toBe(2);
});

test('shows node attributes input when attributes exist', async () => {
const { actions, component } = testBed;
await actions.enable(true);
test('shows view node attributes link when an attribute is selected and shows flyout when clicked', async () => {
const { actions } = testBed;

expect(component.find('.euiLoadingSpinner').exists()).toBeFalsy();
await actions.setDataAllocation('node_attrs');
expect(actions.hasDefaultAllocationBehaviorNotice()).toBeFalsy();
expect(actions.hasNodeAttributesSelect()).toBeTruthy();
expect(actions.getNodeAttributesSelectOptions().length).toBe(2);
});
await actions.enable(true);

test('shows view node attributes link when an attribute is selected and shows flyout when clicked', async () => {
const { actions, component } = testBed;
expect(actions.isAllocationLoading()).toBeFalsy();
await actions.setDataAllocation('node_attrs');
expect(actions.hasDefaultAllocationBehaviorNotice()).toBeFalsy();
expect(actions.hasNodeAttributesSelect()).toBeTruthy();

await actions.enable(true);
expect(actions.hasNodeDetailsFlyout()).toBeFalsy();
expect(actions.getNodeAttributesSelectOptions().length).toBe(2);
await actions.setSelectedNodeAttribute('attribute:true');

expect(component.find('.euiLoadingSpinner').exists()).toBeFalsy();
await actions.setDataAllocation('node_attrs');
expect(actions.hasDefaultAllocationBehaviorNotice()).toBeFalsy();
expect(actions.hasNodeAttributesSelect()).toBeTruthy();
await actions.openNodeDetailsFlyout();
expect(actions.hasNodeDetailsFlyout()).toBeTruthy();
});
});

expect(actions.hasNodeDetailsFlyout()).toBeFalsy();
expect(actions.getNodeAttributesSelectOptions().length).toBe(2);
await actions.setSelectedNodeAttribute('attribute:true');
describe('and none are defined', () => {
const commonSetupAndBaselineAssertions = async () => {
await setup();
const { actions, component } = testBed;
component.update();
await actions.enable(true);

expect(actions.isAllocationLoading()).toBeFalsy();
await actions.setDataAllocation('node_attrs');
expect(actions.hasNodeAttributesSelect()).toBeFalsy();
};

test('and data tiers are available, shows DefaultToDataTiersNotice', async () => {
httpRequestsMockHelpers.setListNodes({
nodesByAttributes: {},
nodesByRoles: { data: ['node1'] },
isUsingDeprecatedDataRoleConfig: false,
});

await commonSetupAndBaselineAssertions();
const { actions } = testBed;
expect(actions.hasDefaultToDataTiersNotice()).toBeTruthy();
});

await actions.openNodeDetailsFlyout();
expect(actions.hasNodeDetailsFlyout()).toBeTruthy();
});
test('and data tiers are available, but not for the cold phase, shows WillUseFallbackTierUsingNodeAttributesNotice', async () => {
httpRequestsMockHelpers.setListNodes({
nodesByAttributes: {},
nodesByRoles: { data_warm: ['node1'] },
isUsingDeprecatedDataRoleConfig: false,
});

test('offers allocation guidance when no node roles are found', async () => {
httpRequestsMockHelpers.setListNodes({
nodesByAttributes: {},
nodesByRoles: {},
isUsingDeprecatedDataRoleConfig: false,
});
await commonSetupAndBaselineAssertions();
const { actions } = testBed;
expect(actions.hasWillUseFallbackTierUsingNodeAttributesNotice()).toBeTruthy();
});

await setup();
const { actions, component } = testBed;
test('when data nodes are in use, shows DefaultToDataNodesNotice', async () => {
httpRequestsMockHelpers.setListNodes({
nodesByAttributes: {},
nodesByRoles: {},
isUsingDeprecatedDataRoleConfig: true,
});

component.update();
await actions.enable(true);
await commonSetupAndBaselineAssertions();
const { actions } = testBed;
expect(actions.hasDefaultToDataNodesNotice()).toBeTruthy();
});

expect(component.find('.euiLoadingSpinner').exists()).toBeFalsy();
expect(actions.hasNoTiersAvailableNotice()).toBeTruthy();
test('when no data tier node roles are defined, shows NoTiersAvailableUsingNodeAttributesNotice', async () => {
httpRequestsMockHelpers.setListNodes({
nodesByAttributes: {},
// data_content is a node role so they're technically in use, but it's not a data tier node role.
nodesByRoles: { data_content: ['node1'] },
isUsingDeprecatedDataRoleConfig: false,
});

await commonSetupAndBaselineAssertions();
const { actions } = testBed;
expect(actions.hasNoTiersAvailableUsingNodeAttributesNotice()).toBeTruthy();
});
});
});

[
{
nodesByRoles: { data_hot: ['test'] },
fallbackTier: 'hot',
},
{
nodesByRoles: { data_hot: ['test'], data_warm: ['test'] },
fallbackTier: 'warm',
},
].forEach(({ nodesByRoles, fallbackTier }) => {
test(`in the cold phase, offers allocation guidance when allocation will fallback to the ${fallbackTier} tier`, async () => {
describe('when using node roles', () => {
test('when no node roles are defined, shows NoTiersAvailableNotice', async () => {
httpRequestsMockHelpers.setListNodes({
nodesByAttributes: {},
nodesByRoles,
nodesByRoles: {},
isUsingDeprecatedDataRoleConfig: false,
});

await setup();
const { actions, component, find } = testBed;
const { actions, component } = testBed;

component.update();
await actions.enable(true);

expect(component.find('.euiLoadingSpinner').exists()).toBeFalsy();
expect(actions.hasWillUseFallbackTierNotice()).toBeTruthy();
expect(find('willUseFallbackTierNotice').text()).toContain(
`No nodes assigned to the cold tierIf no cold nodes are available, data is stored in the ${fallbackTier} tier.`
);
expect(actions.isAllocationLoading()).toBeFalsy();
expect(actions.hasNoTiersAvailableNotice()).toBeTruthy();
});
});

test(`doesn't offer allocation guidance when node with "data" role exists`, async () => {
httpRequestsMockHelpers.setListNodes({
nodesByAttributes: {},
nodesByRoles: { data: ['test'] },
isUsingDeprecatedDataRoleConfig: false,
[
{
nodesByRoles: { data_hot: ['test'] },
fallbackTier: 'hot',
},
{
nodesByRoles: { data_hot: ['test'], data_warm: ['test'] },
fallbackTier: 'warm',
},
].forEach(({ nodesByRoles, fallbackTier }) => {
test(`when allocation will fallback to the ${fallbackTier} tier, shows WillUseFallbackTierNotice and defines the fallback tier`, async () => {
httpRequestsMockHelpers.setListNodes({
nodesByAttributes: {},
nodesByRoles,
isUsingDeprecatedDataRoleConfig: false,
});

await setup();
const { actions, component } = testBed;

component.update();
await actions.enable(true);

expect(actions.isAllocationLoading()).toBeFalsy();
expect(actions.hasWillUseFallbackTierNotice()).toBeTruthy();
expect(actions.getWillUseFallbackTierNoticeText()).toContain(
`No nodes assigned to the cold tierIf no cold nodes are available, data is stored in the ${fallbackTier} tier.`
);
});
});
await setup();
const { actions, component } = testBed;

component.update();
await actions.enable(true);

expect(component.find('.euiLoadingSpinner').exists()).toBeFalsy();
expect(actions.hasWillUseFallbackTierNotice()).toBeFalsy();
});
});
Loading

0 comments on commit fd44a88

Please sign in to comment.