Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
#438 Remove ability to sort archived retros by thought count
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomAshes committed May 20, 2022
1 parent 84571b3 commit d8d3c99
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 251 deletions.
4 changes: 0 additions & 4 deletions api/src/main/java/com/ford/labs/retroquest/board/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Formula;

import javax.persistence.*;
import java.time.LocalDate;
Expand All @@ -47,7 +46,4 @@ public class Board {

@OneToMany(fetch = FetchType.EAGER, mappedBy = "boardId", orphanRemoval = true, cascade = CascadeType.ALL)
private List<Thought> thoughts;

@Formula("(select count(*) from thought where thought.board_id=id)")
private int thoughtCount;
}
22 changes: 0 additions & 22 deletions api/src/test/java/com/ford/labs/retroquest/api/BoardApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,6 @@ void getBoards_ShouldGetBoardsSortedByAscendingDate() throws Exception {
.andExpect(jsonPath("$[2].dateCreated", Matchers.is("2018-03-03")));
}

@Test
void getBoards_ShouldGetBoardsSortedByDescendingThoughtCount() throws Exception {
setupBoards();
mockMvc.perform(get("/api/team/" + teamId + "/boards?sortBy=thoughtCount&sortOrder=DESC")
.header("Authorization", getBearerAuthToken()))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].thoughtCount", Matchers.is(3)))
.andExpect(jsonPath("$[1].thoughtCount", Matchers.is(2)))
.andExpect(jsonPath("$[2].thoughtCount", Matchers.is(1)));
}

@Test
void getBoards_ShouldGetBoardsSortedByAscendingThoughtCount() throws Exception {
setupBoards();
mockMvc.perform(get("/api/team/" + teamId + "/boards?sortBy=thoughtCount&sortOrder=ASC")
.header("Authorization", getBearerAuthToken()))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].thoughtCount", Matchers.is(1)))
.andExpect(jsonPath("$[1].thoughtCount", Matchers.is(2)))
.andExpect(jsonPath("$[2].thoughtCount", Matchers.is(3)));
}

@Test
void getBoards_ShouldGetPaginatedBoards() throws Exception {
setupBoards();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
package com.ford.labs.retroquest.board;

import com.ford.labs.retroquest.actionitem.ActionItemService;
import com.ford.labs.retroquest.board.Board;
import com.ford.labs.retroquest.board.BoardRepository;
import com.ford.labs.retroquest.board.BoardService;
import com.ford.labs.retroquest.column.ColumnService;
import com.ford.labs.retroquest.thought.Thought;
import com.ford.labs.retroquest.thought.ThoughtService;
Expand Down Expand Up @@ -135,8 +132,7 @@ public void endRetro_ShouldSaveAllUnboardedThoughtsOnBoard() {
expectedBoardId,
null
)
),
0
)
);

when(thoughtService.fetchAllActiveThoughts(eq(expectedTeamId))).thenReturn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class RetroTest {
public void from_returnsAllExpectedBoardFields() {
var column = new Column(3L, "topic", "title", "teamId");
var thought = new Thought(2L, "A message", 0, false, "teamId", 1L, 3L);
var board = new Board(1L, "teamId", LocalDate.now(), List.of(thought), 1);
var board = new Board(1L, "teamId", LocalDate.now(), List.of(thought));
var retro = Retro.from(board, List.of(column));

assertThat(retro.id()).isEqualTo(board.getId());
Expand All @@ -44,7 +44,7 @@ public void from_returnsAllExpectedBoardFields() {
public void from_returnsColumnsInSavedOrder() {
var column1 = new Column(2L, "topic", "title", "teamId");
var column2 = new Column(3L, "topic", "title", "teamId");
var board = new Board(1L, "teamId", LocalDate.now(), List.of(), 0);
var board = new Board(1L, "teamId", LocalDate.now(), List.of());
var retro = Retro.from(board, List.of(column2, column1));

assertThat(retro.columns()).isEqualTo(List.of(column1, column2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface Props {
function ArchivedBoardTile({ board, onTileClicked }: Props): JSX.Element {
return (
<li data-testid="boardArchive" className="archived-board-tile">
<span className="thought-count">{board.thoughtCount}</span>
<span className="thought-count">{board.thoughts.length}</span>
<span className="date">
{moment(board.dateCreated).format('MMMM Do, yyyy')}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

@use './../../../../../Styles/main';
@use 'Styles/main';

.archived-boards-list {
@include main.site-max-width;
Expand All @@ -41,52 +41,6 @@
font-size: 0.8rem;
}

.list-header {
display: flex;
flex-direction: row;
justify-content: space-between;

max-width: 21.875rem;
margin: 0 auto 1rem;
padding: 0.5rem;

background: rgba(main.$asphalt, 0.08);
border-radius: 6px;

.sort-button {
color: rgba(main.$asphalt, 0.4);
font-weight: bold;

&.selected-asc {
color: main.$asphalt;
}

&.selected-asc::after {
display: inline-block;

transform: rotate(180deg) translateX(-3px) translateY(-3px);

content: '';
}

&.selected-desc {
color: main.$asphalt;
}

&.selected-desc::after {
display: inline-block;

transform: translateX(3px);

content: '';
}
}

.spacer {
padding: 0.75rem;
}
}

.list {
max-width: 21.875rem;
margin: 0 auto 1rem;
Expand All @@ -98,22 +52,5 @@
.thoughts-archive-title {
color: main.$gray-1;
}

.list-header {
background: main.$black;

.sort-button {
color: main.$gray-2;
font-weight: bold;

&.selected-asc {
color: main.$gray-1;
}

&.selected-desc {
color: main.$gray-1;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('Archived Boards List', () => {
expect(paginationButton).toHaveClass('active');
});

it('should paginate to second page with default sorting', async () => {
it('should paginate to second page with default sorting of date in descending order', async () => {
await setUpThoughtArchives();
const pagination2Button = screen.getAllByText('2').slice(-1)[0];
expect(pagination2Button).not.toHaveClass('active');
Expand All @@ -92,7 +92,7 @@ describe('Archived Boards List', () => {
expect(screen.getAllByTestId('boardArchive')).toHaveLength(1);
});

it('should paginate to second page with new sorting', async () => {
it('should paginate to second page with sorting of date in ascending order', async () => {
await setUpThoughtArchives();
const pagination2Button = screen.getAllByText('2').slice(-1)[0];
expect(pagination2Button).not.toHaveClass('active');
Expand All @@ -101,10 +101,10 @@ describe('Archived Boards List', () => {
BoardService.getBoards = jest
.fn()
.mockResolvedValue(
getBoardsResponse([mockBoard2], 'thoughtCount', SortOrder.DESC)
getBoardsResponse([mockBoard2], 'dateCreated', SortOrder.DESC)
);

clickThoughtCountSortingButton();
clickDateSortingButton();

await waitFor(() => expect(BoardService.getBoards).toHaveBeenCalled());

Expand All @@ -116,8 +116,8 @@ describe('Archived Boards List', () => {
'teamId',
INITIAL_PAGE_INDEX,
PAGE_SIZE,
'thoughtCount',
'DESC'
'dateCreated',
'ASC'
)
);
expect(screen.getAllByTestId('boardArchive')).toHaveLength(1);
Expand Down Expand Up @@ -192,55 +192,6 @@ describe('Archived Boards List', () => {
expect(within(tiles[0]).getByText('April 22nd, 1998')).toBeDefined();
expect(within(tiles[1]).getByText('October 1st, 1982')).toBeDefined();
});

it('should be sorted by thought count descending when # clicked', async () => {
await setUpThoughtArchives();

BoardService.getBoards = jest
.fn()
.mockResolvedValue(getBoardsResponse([mockBoard1, mockBoard2]));

clickThoughtCountSortingButton();

await waitFor(() =>
expect(BoardService.getBoards).toHaveBeenCalledWith(
'teamId',
INITIAL_PAGE_INDEX,
PAGE_SIZE,
'thoughtCount',
'DESC'
)
);

const tiles = screen.getAllByTestId('boardArchive');
expect(within(tiles[0]).getByText('1')).toBeDefined();
expect(within(tiles[1]).getByText('0')).toBeDefined();
});

it('should be sorted by thought count ascending when # clicked and already sorted by descending', async () => {
await setUpThoughtArchives();
clickThoughtCountSortingButton();

BoardService.getBoards = jest
.fn()
.mockResolvedValue(getBoardsResponse([mockBoard2, mockBoard1]));

clickThoughtCountSortingButton();

await waitFor(() =>
expect(BoardService.getBoards).toHaveBeenCalledWith(
'teamId',
INITIAL_PAGE_INDEX,
PAGE_SIZE,
'thoughtCount',
'ASC'
)
);

const tiles = screen.getAllByTestId('boardArchive');
expect(within(tiles[0]).queryByText('0')).not.toBeNull();
expect(within(tiles[1]).queryByText('1')).not.toBeNull();
});
});

it('should show "No Archives" message when no archived thoughts are present', async () => {
Expand Down Expand Up @@ -290,7 +241,3 @@ function getBoardsResponse(
function clickDateSortingButton() {
userEvent.click(screen.getByText('Date'));
}

function clickThoughtCountSortingButton() {
userEvent.click(screen.getByText('#'));
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ function ArchivedBoardsList({ onBoardSelection }: Props): JSX.Element {
}
}

function handleCountSort(sortOrder: SortOrder): void {
getBoards(paginationData?.pageIndex || 0, 'thoughtCount', sortOrder);
}

function handleDateSort(sortOrder: SortOrder): void {
getBoards(paginationData?.pageIndex || 0, 'dateCreated', sortOrder);
}
Expand All @@ -92,10 +88,7 @@ function ArchivedBoardsList({ onBoardSelection }: Props): JSX.Element {
Thought Archives
<span className="thoughts-archive-metadata">{getPageData()}</span>
</h1>
<ArchivedBoardListHeader
onDateClick={handleDateSort}
onHashClick={handleCountSort}
/>
<ArchivedBoardListHeader onDateClick={handleDateSort} />
<ol className="list">
{boards.map(function (board: Board) {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2022 Ford Motor Company
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@use 'Styles/main';

.list-header {
display: flex;
flex-direction: row;
justify-content: center;

max-width: 21.875rem;
margin: 0 auto 1rem;
padding: 0.5rem;

background: rgba(main.$asphalt, 0.08);
border-radius: 6px;

.sort-button {
padding-right: 0.75rem;

color: rgba(main.$asphalt, 0.4);
font-weight: bold;

&.selected-asc {
color: main.$asphalt;
}

&.selected-asc::after {
display: inline-block;

transform: rotate(180deg) translateX(-3px) translateY(-3px);

content: '';
}

&.selected-desc {
color: main.$asphalt;
}

&.selected-desc::after {
display: inline-block;

transform: translateX(3px);

content: '';
}
}
}

@include main.dark-theme {
.list-header {
background: main.$black;

.sort-button {
color: main.$gray-2;
font-weight: bold;

&.selected-asc {
color: main.$gray-1;
}

&.selected-desc {
color: main.$gray-1;
}
}
}
}
Loading

0 comments on commit d8d3c99

Please sign in to comment.