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

test(e2e): home shows events #118

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion src/main/frontend/src/components/ResourceListV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ export const ResourceListV2 = ({
return null;
}
return (
<Table title={title} titleVariant={titleVariant} className={className}>
<Table
title={title}
titleVariant={titleVariant}
className={className}
{...properties}
>
<Table.Head columns={headers} />
<Table.Body>
<Content headers={headers} resources={resources} loading={loading}>
Expand Down
6 changes: 4 additions & 2 deletions src/main/frontend/src/components/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ Table.Body = ({children}) => (
);

// For stripes to work need to add 'even' variant to specific property in tailwind.config.js
Table.Row = ({children, className = ''}) => (
<tr className={`even:bg-gray-200/50 ${className}`}>{children}</tr>
Table.Row = ({children, className = '', ...properties}) => (
<tr className={`even:bg-gray-200/50 ${className}`} {...properties}>
{children}
</tr>
);
Table.ResourceRow = ({resource, children, ...properties}) => (
<Table.Row
Expand Down
7 changes: 6 additions & 1 deletion src/main/frontend/src/events/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ const Rows = ({events}) => {
.map(event => {
const lastTimestamp = new Date(timestamp(event));
return (
<Table.ResourceRow key={uid(event)} resource={event}>
<Table.ResourceRow
key={uid(event)}
resource={event}
data-testid='list__events-row'
>
<Table.Cell className='whitespace-nowrap w-3 text-center'>
<Icon
className={
Expand Down Expand Up @@ -156,6 +160,7 @@ export const List = ({...properties}) => {
const resources = Object.values(filterEvents(filteredResources, properties));
return (
<ResourceListV2
data-testid='list__events'
title='Latest Events'
headers={headers}
resources={resources}
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/com/marcnuri/yakd/selenium/HomeIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@
*/
package com.marcnuri.yakd.selenium;

import io.fabric8.kubernetes.api.model.EventBuilder;
import io.fabric8.kubernetes.api.model.MicroTime;
import io.fabric8.kubernetes.api.model.ObjectReferenceBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.NonDeletingOperation;
import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.quarkus.test.kubernetes.client.KubernetesTestServer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
Expand All @@ -29,19 +36,34 @@

import java.net.URL;
import java.time.Duration;
import java.util.regex.Pattern;

import static org.assertj.core.api.Assertions.assertThat;

@QuarkusTest
@TestProfile(IntegrationTestProfile.class)
public class HomeIT {

@KubernetesTestServer
KubernetesServer kubernetes;

@TestHTTPResource
URL url;
WebDriver driver;

@BeforeEach
void loadHomePage() {
// Add a few events to display something in the dashboard
kubernetes.getClient().v1().events().resource(new EventBuilder()
.withNewMetadata().withName("event-1").endMetadata()
.withInvolvedObject(new ObjectReferenceBuilder()
.withKind("Pod")
.withName("a-pod-1")
.build())
.withReason("Started")
.withMessage("Started container")
.withEventTime(new MicroTime("2015-10-21 16:29"))
.build()).createOr(NonDeletingOperation::update);
driver.get(url.toString());
final Wait<WebDriver> wait = new WebDriverWait(driver, Duration.ofSeconds(1));
wait.until(d -> d.findElement(By.cssSelector(".dashboard-page")).isDisplayed());
Expand All @@ -58,4 +80,13 @@ void hasFooter() {
assertThat(driver.findElement(By.cssSelector(".dashboard-page footer")).getText())
.matches("Copyright © \\d{4} - Marc Nuri - Licensed under the Apache License 2.0");
}

@Test
void hasEventList() {
final By selector = By.cssSelector("[data-testid=list__events] [data-testid=list__events-row]");
final Wait<WebDriver> wait = new WebDriverWait(driver, Duration.ofSeconds(5));
wait.until(d -> d.findElement(selector).isDisplayed());
assertThat(driver.findElement(selector).getText())
.matches("^Pod\\na-pod-1\\nStarted Started container\\n.+");
}
}