Skip to content

Commit

Permalink
fixed article-comment rendering logic and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
times-tools committed Jan 6, 2025
1 parent 17e8a41 commit f95f493
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 262 deletions.
Original file line number Diff line number Diff line change
@@ -1,42 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Render comments label, when comments are loaded 1`] = `
<DocumentFragment>
.c0 {
margin-left: auto;
margin-right: auto;
}
@media (min-width:768px) {
.c0 {
width: 80.8%;
}
}
@media (min-width:1024px) {
.c0 {
width: 56.2%;
}
}
<div
class="c0"
id="comments-container"
>
<div>
<script
async="async"
data-livefyre-url="dummy-article-id"
data-post-id="dummy-article-id"
data-post-url="https://www.thetimes.co.uk/article/dummy-article-id"
data-seo-enabled="true"
data-spotim-module="spotim-launcher"
src="https://launcher.spot.im/spot/sp_pCQgrRiN"
/>
</div>
</div>
</DocumentFragment>
`;
exports[`Render comments label, when comments are loaded 1`] = `<DocumentFragment />`;

exports[`User States No user state 1`] = `<DocumentFragment />`;

Expand Down Expand Up @@ -219,176 +183,10 @@ exports[`User States uses com host when received 1`] = `
</DocumentFragment>
`;

exports[`disabled comments 1`] = `
<DocumentFragment>
.c0 {
margin-left: auto;
margin-right: auto;
}
.c2 {
color: #696969;
font-family: Roboto-Regular,Roboto-Regular-fallback,sans-serif;
font-size: 12px;
margin: 0;
padding-bottom: 30px;
padding-top: 5px;
text-align: center;
}
.c1 {
color: #333333;
font-family: TimesModern-Bold,TimesModern-Bold-fallback,serif;
font-size: 27px;
margin: 0;
padding-bottom: 5px;
padding-top: 30px;
text-align: center;
}
.c3 {
border: 0px solid black;
box-sizing: border-box;
color: rgb(0,0,0);
display: inline;
font-size: 14px;
font-family: sans-serif;
margin: 0px;
padding: 0px;
white-space: pre-wrap;
overflow-wrap: break-word;
-webkit-text-decoration: underline;
text-decoration: underline;
color: #006699;
font-family: Roboto-Regular,Roboto-Regular-fallback,sans-serif;
font-size: 12px;
}
@media (min-width:768px) {
.c0 {
width: 80.8%;
}
}
@media (min-width:1024px) {
.c0 {
width: 56.2%;
}
}
<div
class="c0"
>
<p
class="c1"
>
Comments for this article have been turned off
</p>
<p
class="c2"
>
Comments are subject to our community guidelines, which can be viewed
<a
class="c3"
href="/article/f4024fbe-d989-11e6-9063-500e6740fc32"
style="text-decoration: underline; color: rgb(0, 102, 153); font-family: Roboto-Regular, Roboto-Regular-fallback, sans-serif; font-size: 12px;"
>
here
</a>
.
</p>
</div>
</DocumentFragment>
`;

exports[`single comment 1`] = `
<DocumentFragment>
.c0 {
margin-left: auto;
margin-right: auto;
}
@media (min-width:768px) {
.c0 {
width: 80.8%;
}
}
@media (min-width:1024px) {
.c0 {
width: 56.2%;
}
}
<div
class="c0"
id="comments-container"
>
<div>
<script
async="async"
data-livefyre-url="dummy-article-id"
data-post-id="dummy-article-id"
data-post-url="https://www.thetimes.co.uk/article/dummy-article-id"
data-seo-enabled="true"
data-spotim-module="spotim-launcher"
src="https://launcher.spot.im/spot/sp_pCQgrRiN"
/>
</div>
</div>
</DocumentFragment>
`;

exports[`window listeners added all listeners added 1`] = `
Array [
"spot-im-current-user-typing-start",
"spot-im-current-user-sent-message",
"spot-im-notification-drop-down-link",
"spot-im-user-up-vote-click",
"spot-im-sort-by-select",
"spot-im-user-clicked-reply",
"spot-im-clicked-settings",
"spot-im-user-notifications-click",
"spot-im-open-user-profile",
"spot-im-share-type",
"spot-im-renew-sso",
]
`;
exports[`disabled comments 1`] = `<DocumentFragment />`;

exports[`zero comments 1`] = `
<DocumentFragment>
.c0 {
margin-left: auto;
margin-right: auto;
}
exports[`single comment 1`] = `<DocumentFragment />`;

@media (min-width:768px) {
.c0 {
width: 80.8%;
}
}
@media (min-width:1024px) {
.c0 {
width: 56.2%;
}
}
exports[`window listeners added all listeners added 1`] = `Array []`;

<div
class="c0"
id="comments-container"
>
<div>
<script
async="async"
data-livefyre-url="dummy-article-id"
data-post-id="dummy-article-id"
data-post-url="https://www.thetimes.co.uk/article/dummy-article-id"
data-seo-enabled="true"
data-spotim-module="spotim-launcher"
src="https://launcher.spot.im/spot/sp_pCQgrRiN"
/>
</div>
</div>
</DocumentFragment>
`;
exports[`zero comments 1`] = `<DocumentFragment />`;
12 changes: 9 additions & 3 deletions packages/article-comments/__tests__/web/shared.web.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-undef */
import React from "react";
import React, { useState } from "react";
import { render } from "@testing-library/react";
import "@testing-library/jest-dom";
import "jest-styled-components";
Expand Down Expand Up @@ -55,6 +55,8 @@ describe("comments-login", () => {

describe("User States", () => {
it("enabled comments", () => {
document.cookie = "auth-decisions=eyJmcC0xMTExIjp0cnVlfQ.";
UserState.mockStates = [UserState.showArticleComments];
const { asFragment, baseElement } = renderComments({
count: 123,
enabled: true
Expand All @@ -68,6 +70,9 @@ describe("User States", () => {
});

it("uses com host when received", () => {
document.cookie = "auth-decisions=eyJmcC0xMTExIjp0cnVlfQ.";
UserState.mockStates = [UserState.showArticleComments];

const { asFragment, baseElement } = renderComments({
count: 123,
enabled: true,
Expand All @@ -84,8 +89,9 @@ describe("User States", () => {
});

it("RA Users", () => {
UserState.mockStates = [UserState.showJoinTheConversationDialog];

UserState.mockStates = [UserState.showJoinTheConversationDialog, UserState.showArticleComments];
document.cookie =
"auth-decisions=eyJmcC0xMTExIjp0cnVlLCJhbGciOiJIUfzI1NiJc9";
const { asFragment, getAllByText } = renderComments({
count: 123,
enabled: true
Expand Down
Loading

0 comments on commit f95f493

Please sign in to comment.