storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/objects/__tests__/PrefixActions.test.js (about)

     1  /*
     2   * MinIO Cloud Storage (C) 2018 MinIO, Inc.
     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   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  import React from "react"
    18  import { shallow } from "enzyme"
    19  import { PrefixActions } from "../PrefixActions"
    20  
    21  describe("PrefixActions", () => {
    22    it("should render without crashing", () => {
    23      shallow(<PrefixActions object={{ name: "abc/" }} currentPrefix={"pre1/"} />)
    24    })
    25  
    26    it("should show DeleteObjectConfirmModal when delete action is clicked", () => {
    27      const wrapper = shallow(
    28        <PrefixActions object={{ name: "abc/" }} currentPrefix={"pre1/"} />
    29      )
    30      wrapper
    31        .find("a")
    32        .last()
    33        .simulate("click", { preventDefault: jest.fn() })
    34      expect(wrapper.state("showDeleteConfirmation")).toBeTruthy()
    35      expect(wrapper.find("DeleteObjectConfirmModal").length).toBe(1)
    36    })
    37  
    38    it("should hide DeleteObjectConfirmModal when Cancel button is clicked", () => {
    39      const wrapper = shallow(
    40        <PrefixActions object={{ name: "abc/" }} currentPrefix={"pre1/"} />
    41      )
    42      wrapper
    43        .find("a")
    44        .last()
    45        .simulate("click", { preventDefault: jest.fn() })
    46      wrapper.find("DeleteObjectConfirmModal").prop("hideDeleteConfirmModal")()
    47      wrapper.update()
    48      expect(wrapper.state("showDeleteConfirmation")).toBeFalsy()
    49      expect(wrapper.find("DeleteObjectConfirmModal").length).toBe(0)
    50    })
    51  
    52    it("should call deleteObject with object name", () => {
    53      const deleteObject = jest.fn()
    54      const wrapper = shallow(
    55        <PrefixActions
    56          object={{ name: "abc/" }}
    57          currentPrefix={"pre1/"}
    58          deleteObject={deleteObject}
    59        />
    60      )
    61      wrapper
    62        .find("a")
    63        .last()
    64        .simulate("click", { preventDefault: jest.fn() })
    65      wrapper.find("DeleteObjectConfirmModal").prop("deleteObject")()
    66      expect(deleteObject).toHaveBeenCalledWith("abc/")
    67    })
    68  
    69  
    70    it("should call downloadPrefix when single object is selected and download button is clicked", () => {
    71      const downloadPrefix = jest.fn()
    72      const wrapper = shallow(
    73        <PrefixActions
    74          object={{ name: "abc/" }}
    75          currentPrefix={"pre1/"}
    76          downloadPrefix={downloadPrefix} />
    77      )
    78      wrapper
    79        .find("a")
    80        .first()
    81        .simulate("click", { preventDefault: jest.fn() })
    82      expect(downloadPrefix).toHaveBeenCalled()
    83    })
    84  })