|
| 1 | +import { regionFactory } from '@linode/utilities'; |
| 2 | +import { authenticate } from 'support/api/authentication'; |
| 3 | +import { mockAppendFeatureFlags } from 'support/intercepts/feature-flags'; |
| 4 | +import { |
| 5 | + mockGetObjectStorageEndpoints, |
| 6 | + mockGetObjectStorageQuotas, |
| 7 | + mockGetObjectStorageQuotaUsages, |
| 8 | +} from 'support/intercepts/object-storage'; |
| 9 | +import { ui } from 'support/ui'; |
| 10 | +import { randomDomainName, randomLabel } from 'support/util/random'; |
| 11 | + |
| 12 | +import { objectStorageEndpointsFactory } from 'src/factories'; |
| 13 | +import { quotaFactory, quotaUsageFactory } from 'src/factories/quotas'; |
| 14 | + |
| 15 | +const mockFeatureFlags = { |
| 16 | + objSummaryPage: true, |
| 17 | +}; |
| 18 | + |
| 19 | +const placeholderText = 'Select an Object Storage S3 endpoint'; |
| 20 | + |
| 21 | +const mockDomain = randomDomainName(); |
| 22 | + |
| 23 | +const mockRegions = regionFactory.buildList(4, { |
| 24 | + capabilities: ['Object Storage'], |
| 25 | +}); |
| 26 | + |
| 27 | +const mockEndpoints = [ |
| 28 | + objectStorageEndpointsFactory.build({ |
| 29 | + endpoint_type: 'E0', |
| 30 | + region: mockRegions[0].id, |
| 31 | + s3_endpoint: `${mockRegions[0].id}-1.${mockDomain}`, |
| 32 | + }), |
| 33 | + objectStorageEndpointsFactory.build({ |
| 34 | + endpoint_type: 'E1', |
| 35 | + region: mockRegions[1].id, |
| 36 | + s3_endpoint: `${mockRegions[1].id}-1.${mockDomain}`, |
| 37 | + }), |
| 38 | + objectStorageEndpointsFactory.build({ |
| 39 | + endpoint_type: 'E1', |
| 40 | + region: mockRegions[2].id, |
| 41 | + s3_endpoint: `${mockRegions[2].id}-1.${mockDomain}`, |
| 42 | + }), |
| 43 | + objectStorageEndpointsFactory.build({ |
| 44 | + endpoint_type: 'E2', |
| 45 | + region: mockRegions[3].id, |
| 46 | + s3_endpoint: `${mockRegions[3].id}-1.${mockDomain}`, |
| 47 | + }), |
| 48 | +]; |
| 49 | + |
| 50 | +const mockSelectedEndpoint = mockEndpoints[1]; |
| 51 | +const selectedDomain = mockSelectedEndpoint.s3_endpoint || ''; |
| 52 | + |
| 53 | +const mockQuotas = [ |
| 54 | + quotaFactory.build({ |
| 55 | + quota_id: `obj-bytes-${selectedDomain}`, |
| 56 | + quota_type: 'obj-bytes', |
| 57 | + description: randomLabel(50), |
| 58 | + endpoint_type: mockSelectedEndpoint.endpoint_type, |
| 59 | + quota_limit: 10, |
| 60 | + quota_name: 'Total Capacity', |
| 61 | + resource_metric: 'byte', |
| 62 | + s3_endpoint: selectedDomain, |
| 63 | + }), |
| 64 | + quotaFactory.build({ |
| 65 | + quota_id: `obj-buckets-${selectedDomain}`, |
| 66 | + quota_type: 'obj-buckets', |
| 67 | + description: randomLabel(50), |
| 68 | + endpoint_type: mockSelectedEndpoint.endpoint_type, |
| 69 | + quota_limit: 78, |
| 70 | + quota_name: 'Number of Objects', |
| 71 | + resource_metric: 'bucket', |
| 72 | + s3_endpoint: selectedDomain, |
| 73 | + }), |
| 74 | + quotaFactory.build({ |
| 75 | + quota_id: `obj-objects-${selectedDomain}`, |
| 76 | + quota_type: 'obj-objects', |
| 77 | + description: randomLabel(50), |
| 78 | + endpoint_type: mockSelectedEndpoint.endpoint_type, |
| 79 | + quota_limit: 400, |
| 80 | + quota_name: 'Number of Buckets', |
| 81 | + resource_metric: 'object', |
| 82 | + s3_endpoint: selectedDomain, |
| 83 | + }), |
| 84 | +]; |
| 85 | + |
| 86 | +const mockQuotaUsages = [ |
| 87 | + quotaUsageFactory.build({ |
| 88 | + quota_limit: mockQuotas[0].quota_limit, |
| 89 | + usage: Math.round(mockQuotas[0].quota_limit * 0.1), |
| 90 | + }), |
| 91 | + quotaUsageFactory.build({ |
| 92 | + quota_limit: mockQuotas[1].quota_limit, |
| 93 | + usage: Math.round(mockQuotas[1].quota_limit * 0.1), |
| 94 | + }), |
| 95 | + quotaUsageFactory.build({ |
| 96 | + quota_limit: mockQuotas[2].quota_limit, |
| 97 | + usage: Math.round(mockQuotas[2].quota_limit * 0.1), |
| 98 | + }), |
| 99 | +]; |
| 100 | + |
| 101 | +authenticate(); |
| 102 | +describe('Object storage summary page test', () => { |
| 103 | + beforeEach(() => { |
| 104 | + mockAppendFeatureFlags(mockFeatureFlags).as('getFeatureFlags'); |
| 105 | + |
| 106 | + mockGetObjectStorageEndpoints(mockEndpoints).as( |
| 107 | + 'getObjectStorageEndpoints' |
| 108 | + ); |
| 109 | + |
| 110 | + cy.wrap(selectedDomain).as('selectedDomain'); |
| 111 | + cy.wrap(mockEndpoints).as('mockEndpoints'); |
| 112 | + cy.wrap(mockQuotas).as('mockQuotas'); |
| 113 | + cy.wrap(mockQuotaUsages).as('mockQuotaUsages'); |
| 114 | + |
| 115 | + mockGetObjectStorageQuotas(selectedDomain, mockQuotas).as('getQuotas'); |
| 116 | + |
| 117 | + mockGetObjectStorageQuotaUsages( |
| 118 | + selectedDomain, |
| 119 | + 'bytes', |
| 120 | + mockQuotaUsages[0] |
| 121 | + ); |
| 122 | + |
| 123 | + mockGetObjectStorageQuotaUsages( |
| 124 | + selectedDomain, |
| 125 | + 'buckets', |
| 126 | + mockQuotaUsages[1] |
| 127 | + ); |
| 128 | + |
| 129 | + mockGetObjectStorageQuotaUsages( |
| 130 | + selectedDomain, |
| 131 | + 'objects', |
| 132 | + mockQuotaUsages[2] |
| 133 | + ).as('getQuotaUsages'); |
| 134 | + }); |
| 135 | + |
| 136 | + it('should display table with user quotas', () => { |
| 137 | + cy.visitWithLogin('/object-storage/summary'); |
| 138 | + |
| 139 | + cy.wait(['@getFeatureFlags', '@getObjectStorageEndpoints']); |
| 140 | + |
| 141 | + // Object Storage Endpoint field is blank |
| 142 | + cy.findByPlaceholderText(placeholderText) |
| 143 | + .should('be.visible') |
| 144 | + .should('be.enabled'); |
| 145 | + |
| 146 | + const endpointSelect = ui.autocomplete.findByLabel(''); |
| 147 | + endpointSelect.should('be.visible').type(selectedDomain); |
| 148 | + ui.autocompletePopper |
| 149 | + .findByTitle(selectedDomain, { exact: false }) |
| 150 | + .should('be.visible') |
| 151 | + .click(); |
| 152 | + endpointSelect.click(); |
| 153 | + |
| 154 | + cy.wait(['@getQuotas', '@getQuotaUsages']); |
| 155 | + |
| 156 | + cy.findByTestId('table-endpoint-summary') |
| 157 | + .find('tbody') |
| 158 | + .within(() => { |
| 159 | + cy.get('[data-testid="table-row-empty"]').should('not.exist'); |
| 160 | + |
| 161 | + cy.get('td') |
| 162 | + .should('have.length', 3) |
| 163 | + .each((_, index) => { |
| 164 | + cy.get('td') |
| 165 | + .eq(index) |
| 166 | + .within(() => { |
| 167 | + const { usage } = mockQuotaUsages[index]; |
| 168 | + const { quota_limit, resource_metric } = mockQuotas[index]; |
| 169 | + |
| 170 | + cy.findByText(selectedDomain, { exact: false }).should( |
| 171 | + 'be.visible' |
| 172 | + ); |
| 173 | + cy.findByText(`${usage} of ${quota_limit}`, { |
| 174 | + exact: false, |
| 175 | + }).should('be.visible'); |
| 176 | + cy.findByText(resource_metric, { |
| 177 | + exact: false, |
| 178 | + }).should('be.visible'); |
| 179 | + }); |
| 180 | + }); |
| 181 | + }); |
| 182 | + }); |
| 183 | +}); |
0 commit comments