Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Posts table #9

Merged
merged 72 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
444acc7
header task: first commit
bahobab Sep 25, 2020
d7e6cf6
header task: fixed missing default 'javascript'
bahobab Sep 25, 2020
34c1fd3
header task: fixed default link: '/search/javascript'
bahobab Sep 25, 2020
c6faa67
header after first review
bahobab Sep 27, 2020
f46dc2d
header fixing test
bahobab Sep 27, 2020
ae0229e
implemented unit test
bahobab Sep 27, 2020
84feae2
header: before rebase after app-skeleton-review
bahobab Sep 27, 2020
e74b390
resolved conflicts. Fixed unit tests
bahobab Sep 28, 2020
60db4f7
footer: initial commit
bahobab Sep 28, 2020
a462336
implemented Footer.js and Footer.style.js
bahobab Sep 28, 2020
b7c4094
footer: completed unit tests
bahobab Sep 28, 2020
0b12d62
hero-section: initial commit with with fixes from previous PR
bahobab Sep 28, 2020
0817a00
Merge branch 'master' into hero-section
bahobab Sep 28, 2020
e99e5dc
hero-section: completed unit tests
bahobab Sep 29, 2020
2c55849
Merge branch 'hero-section' of https://github.com/ooloo-io/reddit-tim…
bahobab Sep 29, 2020
88238ac
hero-section: fixed linting issues in unit tests
bahobab Sep 29, 2020
0e72262
hero-section: fixed Apps to have all unit tests pass
bahobab Sep 29, 2020
035041f
hero-section: added missing test descriptions in footer.js
bahobab Sep 29, 2020
880d020
hero-section: refactor components and file structure after review
bahobab Sep 29, 2020
2c629e2
info-section: initial commit
bahobab Sep 29, 2020
97ed18d
Merge branch 'master' into info-section
bahobab Sep 30, 2020
3c568ed
info-section: implemented About and How it works sections
bahobab Sep 30, 2020
c4f0d4d
Merge branch 'info-section' of https://github.com/ooloo-io/reddit-tim…
bahobab Sep 30, 2020
bb4486d
info-section: fix link to https://ooloo.io/employers
bahobab Sep 30, 2020
13bdf67
info-section: implemented react-router-hash-link
bahobab Sep 30, 2020
b4a1e4e
info-section: fixed ooloo.io link
bahobab Sep 30, 2020
ee27a75
info-section: implemented unit tests
bahobab Sep 30, 2020
bf59a70
info-section: fixed linting errors
bahobab Sep 30, 2020
d71c19d
info-section: fixed linting errors
bahobab Sep 30, 2020
3ec116c
info-section: fix unit test using this: https://github.com/testing-li…
bahobab Sep 30, 2020
242aefa
info-section: commit after review
bahobab Oct 1, 2020
2780c04
subreddit-form: initial commit. Setup folder structure
bahobab Oct 1, 2020
5b11f42
Merge branch 'master' into subreddit-form
bahobab Oct 1, 2020
f2c2e2d
subreddit-form: implement tests
bahobab Oct 1, 2020
4bb12dc
Merge branch 'subreddit-form' of https://github.com/ooloo-io/reddit-t…
bahobab Oct 1, 2020
c112f47
subreddit-form: fix lint error in Header.js
bahobab Oct 1, 2020
04cf9d2
subreddit-form: completed unit and e2e tests
bahobab Oct 2, 2020
0de4627
subreddit-form: fixes and cleanup after review
bahobab Oct 2, 2020
56554d7
load-the-data: initial commit: added LoadTheData.js
bahobab Oct 2, 2020
56d31c6
load-the-data: fetching data implemented. But unit test and e2e test …
bahobab Oct 3, 2020
7326c4f
Merge branch 'master' into load-the-data
bahobab Oct 3, 2020
1af6086
load-the-data: troubleshooting tests
bahobab Oct 3, 2020
5a60619
Merge branch 'load-the-data' of https://github.com/ooloo-io/reddit-ti…
bahobab Oct 3, 2020
7f50064
load-the-data: continue troubleshooting tests
bahobab Oct 3, 2020
9179df7
load-the-data: fix linting error
bahobab Oct 3, 2020
02223cf
load-the-data: fix the code to fetch top 500 posts
bahobab Oct 3, 2020
1bd7a8e
load-the-data: troubleshooting unit test - 'invalid json response bod…
bahobab Oct 4, 2020
4361e96
load-the-data: integration test passing
bahobab Oct 4, 2020
e061c4a
load-the-data: refactor code after review. still 1 test to fix in Sea…
bahobab Oct 4, 2020
baaccb4
laod-the-data: all tests pass
bahobab Oct 5, 2020
49ccf49
heatmap: first commit: setup heatmap table
bahobab Oct 6, 2020
dd0d221
Merge branch 'master' into heatmap
bahobab Oct 6, 2020
623001e
heatmap: implemented heatmap architecture
bahobab Oct 6, 2020
b552fcb
Merge branch 'heatmap' of https://github.com/ooloo-io/reddit-timer-ba…
bahobab Oct 6, 2020
cf83cc2
heatmap: implemented user timezone
bahobab Oct 6, 2020
2ccfbe7
heatmap: implemented hover, highlit and timezone
bahobab Oct 7, 2020
1b15f5f
heatmap: completed implementation - start testing
bahobab Oct 7, 2020
8040245
heatmap: refactor component structure - set test skeleton
bahobab Oct 7, 2020
6f72e72
heatmap: complete integration tests
bahobab Oct 8, 2020
33c282b
heatmap: complete. fix user timezone in tests
bahobab Oct 8, 2020
62c79e4
heatmap: refactor code after review
bahobab Oct 9, 2020
ae2d7de
heatmap: fix all test errors. ready to merge pr
bahobab Oct 10, 2020
278ff8e
heatmap: fix last test errors. ready to merge pr
bahobab Oct 10, 2020
85c34e4
posts-table: e2e tests passing
bahobab Oct 11, 2020
8f3f626
Merge branch 'master' into posts-table
bahobab Oct 11, 2020
c7c3053
posts-table: 2 integration tests remaining
bahobab Oct 11, 2020
bb7c11f
Merge branch 'posts-table' of https://github.com/ooloo-io/reddit-time…
bahobab Oct 11, 2020
c0cc726
posts-table: resolved conflicts
bahobab Oct 11, 2020
667d0cb
posts-table: fix lint issue
bahobab Oct 11, 2020
e73757c
posts-table: fix lint issue
bahobab Oct 11, 2020
ee0ad49
posts-table: implemented posts sorted by time created
bahobab Oct 12, 2020
7892637
post-table: refactor after review
bahobab Oct 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion src/__tests__/SearchPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const setup = (initialPath = '/') => {
return { ...view, history };
};

async function clickFirstCellWithValue(cellValue) {
const heatmap = await screen.findByTestId('heatmap');
const cell = within(heatmap).getAllByText(cellValue)[0]; // first cell
userEvent.click(cell);
}

describe('heatmap', () => {
it('loads top post for subreddit in URL', async () => {
setup('/search/reactjs');
Expand Down Expand Up @@ -108,7 +114,67 @@ describe('subreddit form', () => {
it('no accessibility violation', async () => {
const { container } = setup('/search/reactjs');

expect(await screen.findByTestId('heatmap')).toBeInTheDocument();
// expect(await screen.findByTestId('heatmap')).toBeInTheDocument();
await clickFirstCellWithValue('3');

expect(await axe(container)).toHaveNoViolations();
});
});

describe('posts table', () => {
it('not visible when no cell clicked', async () => {
setup('/search/reactjs');
await screen.findByTestId('heatmap');

expect(screen.queryByRole('table')).not.toBeInTheDocument();
});

it('not visible when cell clicked has value 0', async () => {
setup('/search/reactjs');
await clickFirstCellWithValue('0'); // argument is string

expect(screen.queryByRole('table')).not.toBeInTheDocument();
});

it('shows posts ordered by time acording to cell clicked', async () => {
setup('/search/reactjs');
await clickFirstCellWithValue('3'); // argument is string

const table = screen.getByRole('table');
const tableRows = within(table)
.getAllByRole('row')
.slice(1); // return rows in tbody, exclude header row

const tableContents = tableRows.map((row) => {
const cells = within(row).getAllByRole('cell');
const titleLink = within(cells[0]).getByRole('link');
const authorLink = within(cells[4]).getByRole('link');

return {
title: titleLink.innerHTML,
href: titleLink.href,
time: cells[1].innerHTML,
score: cells[2].innerHTML,
numComments: cells[4].innerHTML,
author: authorLink.innerHTML,
authorLink: authorLink.href,
};
});

expect(tableContents).toMatchSnapshot();
});

it('shows no link for deleted author', async () => {
setup('/search/reactjs');
const heatmap = await screen.findByTestId('heatmap');
const hasDeletedAuthor = within(heatmap).getAllByText('3')[4];
userEvent.click(hasDeletedAuthor);

const table = screen.getByRole('table');
const rowWithDeletedUser = within(table).getAllByRole('row')[2];

const authorCell = within(rowWithDeletedUser).getAllByRole('cell')[4];
expect(within(authorCell).queryByRole('link')).not.toBeInTheDocument();
expect(authorCell.innerHTML).toBe('[deleted]');
});
});
98 changes: 98 additions & 0 deletions src/__tests__/_PostsTable.js_
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import React from 'react';
import { MemoryRouter, Route } from 'react-router-dom';
import {
render, screen, within,
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import '@testing-library/jest-dom/extend-expect';

import App from '../app';

const setup = (initialPath = '/') => {
let history;

const view = render(
<MemoryRouter initialEntries={[initialPath]}>
<App />
<Route
path="*"
render={(props) => {
history = props.history;
return null;
}}
/>
</MemoryRouter>,
);
return { ...view, history };
};

describe('post table', () => {
it('shows posts per hour in table', async () => {
setup('/search/reactjs');

let cellToClick;
let numPosts;

screen.getByText('loading-spinner.svg');

const heatmap = await screen.findByTestId('heatmap');

expect(heatmap).toBeInTheDocument();
const cells = await within(heatmap).findAllByRole('button');

// posts table is shown when a box is cliked

// it is not shown when there are no posts for the selected weekday/hour
// eslint-disable-next-line prefer-destructuring
cellToClick = cells[0];
numPosts = Number(cellToClick.innerHTML);

expect(numPosts).toBe(0);
userEvent.click(cellToClick);

// expect(postsTable).not.toBeInTheDocument();
expect(await screen.queryByTestId('postsTable')).toBeNull();

// it is shown when there are posts for the selected weekday/hour
// eslint-disable-next-line prefer-destructuring
cellToClick = cells[28]; // contains a deketed author
numPosts = Number(cellToClick.innerHTML);

expect(numPosts).not.toBe(0);
userEvent.click(cellToClick);

// posts table is shown when a box is cliked
const postsTable = await screen.findByTestId('postsTable');
expect(postsTable).toBeInTheDocument();

const postsRows = await within(postsTable).findAllByTestId('postRow');

expect(postsRows.length).not.toEqual(0);
expect(postsRows.length).toEqual(numPosts);

// links
postsRows.forEach((postRow) => {
// if the author has been deleted it should not be a link
const links = within(postRow).getAllByRole('link');
if (postRow.innerHTML.includes('[deleted]')) {
expect(links.length).toEqual(1);
expect(links[0]).toHaveAttribute('href', expect.not.stringContaining('https://reddit.com/u/'));
} else {
// 'match', /https:\/\/(www.)?reddit.com\/
// r\/javascript\/comments\/er5hqm\/the_new_babel_release_gives_support_for\/?/
// the title links to the post on Reddit
expect(links[0]).toHaveAttribute('href', expect.stringContaining('https://www.reddit.com/r/'));
// the title links opens in a new browser tab
expect(links[0]).toHaveAttribute('target', '_blank');
userEvent.click(links[0]);

// the author links to the author's reddit profile
expect(links[1]).toHaveAttribute('href', expect.stringContaining('https://reddit.com/u/'));
// the author links opens in a new browser tab
expect(links[1]).toHaveAttribute('target', '_blank');
}

// the posts are sorted by the time they have been created
});
});
});
32 changes: 32 additions & 0 deletions src/__tests__/__snapshots__/SearchPage.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,35 @@ Array [
"3",
]
`;

exports[`posts table shows posts ordered by time acording to cell clicked 1`] = `
Array [
Object {
"author": "jherr2016",
"authorLink": "https://reddit.com/u/jherr2016",
"href": "https://reddit.com/r/reactjs/comments/ff55gz/intro_to_federated_modules_in_webpack_5/",
"numComments": "<a href=\\"https://reddit.com/u/jherr2016\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\" class=\\"sc-efHXLn fIzpBR\\">jherr2016</a>",
"score": "127",
"time": "2 am",
"title": "Intro to Federated Modules in Webpack 5",
},
Object {
"author": "albaneso",
"authorLink": "https://reddit.com/u/albaneso",
"href": "https://reddit.com/r/reactjs/comments/du50op/reactinteractivepaycard/",
"numComments": "<a href=\\"https://reddit.com/u/albaneso\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\" class=\\"sc-efHXLn fIzpBR\\">albaneso</a>",
"score": "2070",
"time": "2 am",
"title": "react-interactive-paycard",
},
Object {
"author": "Fizaraz",
"authorLink": "https://reddit.com/u/Fizaraz",
"href": "https://reddit.com/r/reactjs/comments/gpg5xq/i_redesigned_my_personal_website_from_scratch_and/",
"numComments": "<a href=\\"https://reddit.com/u/Fizaraz\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\" class=\\"sc-efHXLn fIzpBR\\">Fizaraz</a>",
"score": "179",
"time": "2 am",
"title": "I redesigned my personal website from scratch, and it is great!",
},
]
`;
Loading