storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/objects/__tests__/ObjectsHeader.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 { ObjectsHeader } from "../ObjectsHeader"
    20  import { SORT_ORDER_ASC, SORT_ORDER_DESC } from "../../constants"
    21  
    22  describe("ObjectsHeader", () => {
    23    it("should render without crashing", () => {
    24      const sortObjects = jest.fn()
    25      shallow(<ObjectsHeader sortObjects={sortObjects} />)
    26    })
    27  
    28    it("should render the name column with asc class when objects are sorted by name asc", () => {
    29      const sortObjects = jest.fn()
    30      const wrapper = shallow(
    31        <ObjectsHeader
    32          sortObjects={sortObjects}
    33          sortedByName={true}
    34          sortOrder={SORT_ORDER_ASC}
    35        />
    36      )
    37      expect(
    38        wrapper.find("#sort-by-name i").hasClass("fa-sort-alpha-down")
    39      ).toBeTruthy()
    40    })
    41  
    42    it("should render the name column with desc class when objects are sorted by name desc", () => {
    43      const sortObjects = jest.fn()
    44      const wrapper = shallow(
    45        <ObjectsHeader
    46          sortObjects={sortObjects}
    47          sortedByName={true}
    48          sortOrder={SORT_ORDER_DESC}
    49        />
    50      )
    51      expect(
    52        wrapper.find("#sort-by-name i").hasClass("fa-sort-alpha-down-alt")
    53      ).toBeTruthy()
    54    })
    55  
    56    it("should render the size column with asc class when objects are sorted by size asc", () => {
    57      const sortObjects = jest.fn()
    58      const wrapper = shallow(
    59        <ObjectsHeader
    60          sortObjects={sortObjects}
    61          sortedBySize={true}
    62          sortOrder={SORT_ORDER_ASC}
    63        />
    64      )
    65      expect(
    66        wrapper.find("#sort-by-size i").hasClass("fa-sort-amount-down-alt")
    67      ).toBeTruthy()
    68    })
    69  
    70    it("should render the size column with desc class when objects are sorted by size desc", () => {
    71      const sortObjects = jest.fn()
    72      const wrapper = shallow(
    73        <ObjectsHeader
    74          sortObjects={sortObjects}
    75          sortedBySize={true}
    76          sortOrder={SORT_ORDER_DESC}
    77        />
    78      )
    79      expect(
    80        wrapper.find("#sort-by-size i").hasClass("fa-sort-amount-down")
    81      ).toBeTruthy()
    82    })
    83  
    84    it("should render the date column with asc class when objects are sorted by date asc", () => {
    85      const sortObjects = jest.fn()
    86      const wrapper = shallow(
    87        <ObjectsHeader
    88          sortObjects={sortObjects}
    89          sortedByLastModified={true}
    90          sortOrder={SORT_ORDER_ASC}
    91        />
    92      )
    93      expect(
    94        wrapper.find("#sort-by-last-modified i").hasClass("fa-sort-numeric-down")
    95      ).toBeTruthy()
    96    })
    97  
    98    it("should render the date column with desc class when objects are sorted by date desc", () => {
    99      const sortObjects = jest.fn()
   100      const wrapper = shallow(
   101        <ObjectsHeader
   102          sortObjects={sortObjects}
   103          sortedByLastModified={true}
   104          sortOrder={SORT_ORDER_DESC}
   105        />
   106      )
   107      expect(
   108        wrapper.find("#sort-by-last-modified i").hasClass("fa-sort-numeric-down-alt")
   109      ).toBeTruthy()
   110    })
   111  
   112    it("should call sortObjects when a column is clicked", () => {
   113      const sortObjects = jest.fn()
   114      const wrapper = shallow(<ObjectsHeader sortObjects={sortObjects} />)
   115      wrapper.find("#sort-by-name").simulate("click")
   116      expect(sortObjects).toHaveBeenCalledWith("name")
   117      wrapper.find("#sort-by-size").simulate("click")
   118      expect(sortObjects).toHaveBeenCalledWith("size")
   119      wrapper.find("#sort-by-last-modified").simulate("click")
   120      expect(sortObjects).toHaveBeenCalledWith("last-modified")
   121    })
   122  })