|
| 1 | +/* |
| 2 | + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +import { PLUGIN_NAME } from "../support/constants"; |
| 17 | +import samplePolicy from "../fixtures/sample_policy"; |
| 18 | + |
| 19 | +const POLICY_ID = "test_policy_id"; |
| 20 | +const SAMPLE_INDEX = "sample_index"; |
| 21 | + |
| 22 | +describe("Indices", () => { |
| 23 | + beforeEach(() => { |
| 24 | + // Set welcome screen tracking to false |
| 25 | + localStorage.setItem("home:welcome:show", "false"); |
| 26 | + |
| 27 | + // Visit ISM Kibana |
| 28 | + cy.visit(`${Cypress.env("kibana")}/app/${PLUGIN_NAME}#/indices`); |
| 29 | + |
| 30 | + // Common text to wait for to confirm page loaded, give up to 60 seconds for initial load |
| 31 | + cy.contains("Rows per page", { timeout: 60000 }); |
| 32 | + }); |
| 33 | + |
| 34 | + describe("can be searched", () => { |
| 35 | + before(() => { |
| 36 | + cy.deleteAllIndices(); |
| 37 | + // Create 20+ indices that can be sorted alphabetically by using letters a-z |
| 38 | + for (let i = 97; i < 123; i++) { |
| 39 | + const char = String.fromCharCode(i); |
| 40 | + cy.createIndex(`index_${char}`); |
| 41 | + } |
| 42 | + }); |
| 43 | + |
| 44 | + it("successfully", () => { |
| 45 | + // Get the index table header and click it to sort |
| 46 | + cy.get("thead > tr > th").contains("Index").click({ force: true }); |
| 47 | + |
| 48 | + // Confirm we have index_a in view and not index_z |
| 49 | + cy.contains("index_a"); |
| 50 | + cy.contains("index_z").should("not.exist"); |
| 51 | + |
| 52 | + // Type in index_z in search input |
| 53 | + cy.get(`input[type="search"]`).focus().type("index_z"); |
| 54 | + |
| 55 | + // Confirm we only see index_z in table |
| 56 | + cy.get("tbody > tr").should(($tr) => { |
| 57 | + expect($tr, "1 row").to.have.length(1); |
| 58 | + expect($tr, "item").to.contain("index_z"); |
| 59 | + }); |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + describe("can have policies applied", () => { |
| 64 | + before(() => { |
| 65 | + cy.deleteAllIndices(); |
| 66 | + cy.createPolicy(POLICY_ID, samplePolicy); |
| 67 | + cy.createIndex(SAMPLE_INDEX); |
| 68 | + }); |
| 69 | + |
| 70 | + it("successfully", () => { |
| 71 | + // Confirm we have our initial index |
| 72 | + cy.contains(SAMPLE_INDEX); |
| 73 | + |
| 74 | + // Confirm our initial index is not currently managed |
| 75 | + cy.get(`tbody > tr:contains("${SAMPLE_INDEX}") > td`).filter(`:nth-child(4)`).contains("No"); |
| 76 | + |
| 77 | + // Select checkbox for our index |
| 78 | + cy.get(`[data-test-subj="checkboxSelectRow-${SAMPLE_INDEX}"]`).check({ force: true }); |
| 79 | + |
| 80 | + // Click apply policy button |
| 81 | + cy.get(`[data-test-subj="Apply policyButton"]`).click({ force: true }); |
| 82 | + |
| 83 | + cy.get(`input[data-test-subj="comboBoxSearchInput"]`).focus().type(POLICY_ID, { parseSpecialCharSequences: false, delay: 1 }); |
| 84 | + |
| 85 | + // Click the policy option |
| 86 | + cy.get(`button[role="option"]`).first().click({ force: true }); |
| 87 | + |
| 88 | + cy.contains("A simple description"); |
| 89 | + |
| 90 | + cy.get(`[data-test-subj="applyPolicyModalEditButton"]`).click({ force: true }); |
| 91 | + |
| 92 | + cy.reload(); |
| 93 | + |
| 94 | + cy.contains(SAMPLE_INDEX, { timeout: 20000 }); |
| 95 | + |
| 96 | + // Confirm our index is now being managed |
| 97 | + cy.get(`tbody > tr:contains("${SAMPLE_INDEX}") > td`).filter(`:nth-child(4)`).contains("Yes"); |
| 98 | + }); |
| 99 | + }); |
| 100 | +}); |
0 commit comments