Skip to content

Commit

Permalink
tests: fix project tests by removing unnecessary wait
Browse files Browse the repository at this point in the history
  • Loading branch information
cramakri committed Feb 17, 2022
1 parent 0e75941 commit 3d259d1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 26 deletions.
2 changes: 2 additions & 0 deletions client/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"autosuggest",
"backend",
"bool",
"borderless",
"cancellable",
"cancelled",
"cheatsheet",
Expand Down Expand Up @@ -223,6 +224,7 @@
"noreferrer",
"nowrap",
"nullable",
"objectstores",
"onloadend",
"papermill",
"pathname",
Expand Down
75 changes: 52 additions & 23 deletions client/src/notebooks/ObjectStoresConfig.present.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ function isCloudStorageEndpointValid(cloudStoreConfig) {
return (cloudStoreConfig["endpoint"].length > 0);
}

function EndpointMessage({ validationState }) {
if (!validationState.endpoint) return <FormFeedback>Please enter an endpoint</FormFeedback>;
return (validationState.bucket) ?
<FormText>Data mounted at:</FormText> :
null;
}

function BucketMessage({ credentials, validationState }) {
return (validationState.bucket) ?
<FormText>/cloudstorage/{credentials.bucket}</FormText> :
<FormFeedback>Please enter an bucket</FormFeedback>;
}

/**
* Check if the bucket is valid.
* @param {object} cloudStoreConfig
Expand All @@ -84,18 +97,14 @@ function ObjectStoreRow({ credentials, index, onChangeValue, onDeleteValue }) {
bucket: isCloudStorageBucketValid(credentials),
};

return <tr className="pb-2">
return <tr>
<td>
<FormGroup>
<Input placeholder="endpoint" type="text" autoComplete="text"
id={`s3-endpoint-${index}`} name="endpoint"
bsSize="sm" value={credentials.endpoint}
onChange={changeHandler("endpoint")} invalid={!validationState.endpoint} />
{
(validationState.endpoint) ?
null :
<FormFeedback>Please enter an endpoint</FormFeedback>
}
<EndpointMessage credentials={credentials} validationState={validationState} />
</FormGroup>
</td>
<td>
Expand All @@ -105,11 +114,7 @@ function ObjectStoreRow({ credentials, index, onChangeValue, onDeleteValue }) {
id={`s3-bucket-${index}`} name="bucket"
bsSize="sm" value={credentials.bucket}
onChange={changeHandler("bucket")} invalid={!validationState.bucket} />
{
(validationState.bucket) ?
null :
<FormFeedback>Please enter a bucket</FormFeedback>
}
<BucketMessage credentials={credentials} validationState={validationState} />
</FormGroup>
</td>
<td>
Expand Down Expand Up @@ -139,7 +144,7 @@ function emptyObjectStoreCredentials() {

function ObjectStoresTable({ objectStoresConfiguration, onChangeValue, onDeleteValue }) {

return <Table>
return <Table borderless={true}>
<thead>
<tr>
<th>Endpoint</th>
Expand All @@ -166,11 +171,20 @@ function ObjectStoresTable({ objectStoresConfiguration, onChangeValue, onDeleteV
* @param {array} storesConfig
*/
function validateStoresConfig(storesConfig) {
const invalidConfigs = {};
const bucketNamesMap = {};
for (const cs of storesConfig) {
if (!isCloudStorageEndpointValid(cs)) return false;
if (!isCloudStorageBucketValid(cs)) return false;
if (!isCloudStorageEndpointValid(cs)) invalidConfigs[cs.bucket] = cs;
else if (!isCloudStorageBucketValid(cs)) invalidConfigs[cs.bucket] = cs;
if (bucketNamesMap[cs.bucket]) bucketNamesMap[cs.bucket].push(cs);
else bucketNamesMap[cs.bucket] = [cs];
}
return true;

const conflictingConfigs = {};
Object.keys(bucketNamesMap).forEach((k) => {
if (bucketNamesMap[k].length > 1) conflictingConfigs[k] = bucketNamesMap[k];
});
return { invalidConfigs, conflictingConfigs };
}

function filterConfig(storesConfig) {
Expand All @@ -189,10 +203,12 @@ function filterConfig(storesConfig) {

function saveValidStoresConfig(storesConfig, setObjectStoresConfiguration,
setSaveStatusMessage, toggleShowObjectStoresConfigModal) {
const filteredConfig = filterConfig(storesConfig).filter((cs) => {
// remove invalid rows that contain only empty values
if (!isCloudStorageEndpointValid(cs)) return false;
if (!isCloudStorageBucketValid(cs)) return false;
// remove any rows that contain only empty values
let filteredConfig = filterConfig(storesConfig);
const validatedStores = validateStoresConfig(filteredConfig);
filteredConfig = filteredConfig.filter((cs) => {
if (validatedStores.conflictingConfigs[cs.bucket]) return false;
if (validatedStores.invalidConfigs[cs.bucket]) return false;
return true;
});

Expand All @@ -207,7 +223,16 @@ function saveStoresConfig(storesConfig, setObjectStoresConfiguration,
// const keys = ["bucket", "endpoint", "access_key", "secret_key"];
// remove any rows that contain only empty values
const filteredConfig = filterConfig(storesConfig);
if (!validateStoresConfig(filteredConfig)) {
const validatedStores = validateStoresConfig(filteredConfig);
const conflictingBucketNames = Object.keys(validatedStores.conflictingConfigs);
if (conflictingBucketNames.length > 0) {
const namesStr = conflictingBucketNames.join(", ");
setSaveStatusMessage(<span>Bucket names must be unique; multiple rows share <b>{namesStr}</b>.</span>);
return;
}

const invalidBucketNames = Object.keys(validatedStores.invalidConfigs);
if (invalidBucketNames.length > 0) {
setSaveStatusMessage("Please fix all credentials before saving.");
return;
}
Expand Down Expand Up @@ -238,6 +263,10 @@ function saveStoresConfig(storesConfig, setObjectStoresConfiguration,
function ObjectStoresConfigurationModal({ objectStoresConfiguration, showObjectStoreModal,
toggleShowObjectStoresConfigModal, setObjectStoresConfiguration }) {
const [storesConfig, setStoresConfig] = useState([]);
const setStoresConfigAndClearMessage = (value) => {
setStoresConfig(value);
setSaveStatusMessage("");
};
useEffect(() => {
const initialCredentials = (objectStoresConfiguration.length > 0) ?
List(objectStoresConfiguration) :
Expand All @@ -247,12 +276,12 @@ function ObjectStoresConfigurationModal({ objectStoresConfiguration, showObjectS
const onChangeValue = (index, field, value) => {
const old = Map(storesConfig.get(index));
const newElt = old.set(field, value).toJS();
setStoresConfig(storesConfig.set(index, newElt));
setStoresConfigAndClearMessage(storesConfig.set(index, newElt));
};
const onDeleteValue = (index) => {
let c = storesConfig.remove(index);
if (c.size < 1) c = List([emptyObjectStoreCredentials()]);
setStoresConfig(c);
setStoresConfigAndClearMessage(c);
};
const onAddValue = () => {
setStoresConfig(storesConfig.push(emptyObjectStoreCredentials()));
Expand Down Expand Up @@ -286,7 +315,7 @@ function ObjectStoresConfigurationModal({ objectStoresConfiguration, showObjectS
setCredentials={setStoresConfig} />
</ModalBody>
<ModalFooter>
<FormText>{saveStatusMessage}</FormText>
<FormText color="danger">{saveStatusMessage}</FormText>
<Button color="primary" onClick={onAddValue}>Add Bucket</Button>
<Button color="secondary"
onClick={onSave}>
Expand Down
3 changes: 0 additions & 3 deletions e2e/cypress/integration/local/project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ describe("display migration information", () => {
it("displays recommended migration", () => {
fixtures.projectMigrationRecommended();
cy.visit("/projects/e2e/local-test-project/overview/status");
cy.wait("@getCoreServiceVersion");
// Check that the migration suggestion is shown
cy.contains(
"Updating to the latest version of renku is highly recommended."
Expand Down Expand Up @@ -112,7 +111,6 @@ describe("display migration information for anon user", () => {
it("displays recommended migration", () => {
fixtures.projectMigrationRecommended();
cy.visit("/projects/e2e/local-test-project/overview/status");
cy.wait("@getCoreServiceVersion");
// Check that the migration suggestion is not shown
cy.contains("Project Renku Version");
cy.contains(
Expand Down Expand Up @@ -161,7 +159,6 @@ describe("display migration information for observer user", () => {
it("displays recommended migration", () => {
fixtures.projectMigrationRecommended();
cy.visit("/projects/e2e/local-test-project/overview/status");
cy.wait("@getCoreServiceVersion");
// Check that the migration suggestion is shown
cy.contains(
"Updating to the latest version of renku is highly recommended."
Expand Down

0 comments on commit 3d259d1

Please sign in to comment.