Skip to content

Commit

Permalink
fix(hooks): adapt hooks to use new table component (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 authored Aug 12, 2020
1 parent 53af1b5 commit 2b3b597
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 614 deletions.
95 changes: 28 additions & 67 deletions cypress/integration/hooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ context('Hooks', () => {
});

it('hooks table should show', () => {
cy.get('[data-test=hooks]').should('be.visible');
cy.get('[data-test=hooks-table]').should('be.visible');
});

it('hooks table should show 5 hooks', () => {
cy.get('[data-test=hook]').should('have.length', 5);
cy.get('[data-test=hooks-row]').should('have.length', 5);
});

it('pagination controls should not show', () => {
Expand All @@ -68,65 +68,19 @@ context('Hooks', () => {

context('hook', () => {
beforeEach(() => {
cy.get('[data-test=hook]').first().as('firstHook');
cy.get('[data-test=hook]').last().as('lastHook');
cy.get('[data-test=hooks-row]').first().as('firstHook');
cy.get('[data-test=hooks-row]').last().as('lastHook');
});
it('should show source id', () => {
cy.get('@firstHook').within(() => {
cy.get('.source-id').contains('7bd477e4-4415-11e9-9359-0d41fdf9567e');
});
});
it('should show event', () => {
cy.get('@firstHook').within(() => {
cy.get('.event').contains('push');
});
cy.get('@firstHook').contains('push');
});
it('should show host', () => {
cy.get('@firstHook').within(() => {
cy.get('.host').contains('github.com');
});
});
context('success', () => {
beforeEach(() => {
cy.get('@firstHook').within(() => {
cy.get('.hook-status').as('success');
});
});
it('should have success styles', () => {
cy.get('@success').should('have.class', '-success');
});
context('expanded', () => {
beforeEach(() => {
cy.get('@firstHook').click();
});
context('build', () => {
beforeEach(() => {
cy.get('@firstHook').within(() => {
cy.get('.info').as('build');
});
});
it('should show number', () => {
cy.get('@build').should('be.visible').contains('build:');
cy.get('@build')
.should('be.visible')
.contains('github/octocat/3');
});
it('build number should redirect to build page', () => {
cy.get('@build').within(() => {
cy.get('[data-test=build-link]').click();
cy.location('pathname').should('eq', '/github/octocat/3');
});
});
it('should be running', () => {
cy.get('@build')
.get('.hook-build-status')
.should('have.class', '-running');
});
it('should show duration', () => {
cy.get('@build').contains('duration');
});
});
});
cy.get('@firstHook').contains('github.com');
});
context('failure', () => {
beforeEach(() => {
Expand All @@ -137,21 +91,14 @@ context('Hooks', () => {
it('should have failure styles', () => {
cy.get('@failure').should('have.class', '-failure');
});
context('expanded', () => {
context('error', () => {
beforeEach(() => {
cy.get('@lastHook').click();
cy.get('[data-test=hooks-error]').as('error');
});
context('error', () => {
beforeEach(() => {
cy.get('@lastHook').within(() => {
cy.get('.info').as('error');
});
});
it('should show error', () => {
cy.get('@error').contains(
'github/octocat does not have tag events enabled',
);
});
it('should show error', () => {
cy.get('@error').contains(
'github/octocat does not have tag events enabled',
);
});
});
});
Expand All @@ -167,12 +114,12 @@ context('Hooks', () => {
});

it('hooks table should show 10 hooks', () => {
cy.get('[data-test=hook]').should('have.length', 10);
cy.get('[data-test=hooks-row]').should('have.length', 10);
});

it('shows page 2 of the hooks', () => {
cy.visit('/github/octocat/hooks?page=2');
cy.get('[data-test=hook]').should('have.length', 10);
cy.get('[data-test=hooks-row]').should('have.length', 10);
cy.get('[data-test="crumb-hooks-(page-2)"]')
.should('exist')
.should('contain', 'page 2');
Expand All @@ -188,5 +135,19 @@ context('Hooks', () => {
.click();
cy.location('pathname').should('eq', '/github/octocat/hooks');
});

context('force 550, 750 resolution', () => {
beforeEach(() => {
cy.viewport(550, 750);
});
it('rows have responsive style', () => {
cy.get('[data-test=hooks-row]')
.first()
.should('have.css', 'border-bottom', '2px solid rgb(149, 94, 166)'); // check for lavender border
cy.get('[data-test=hooks-table]')
.first()
.should('have.css', 'border', '0px none rgb(250, 250, 250)'); // no base border
});
});
});
});
101 changes: 2 additions & 99 deletions src/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ import Vela
, Favicon
, Field
, FocusFragment
, HookBuilds
, Hooks
, HooksModel
, Key
Expand Down Expand Up @@ -211,7 +210,6 @@ type alias Model =
, repo : WebData Repository
, inTimeout : Maybe Int
, entryURL : Url
, hookBuilds : HookBuilds
, theme : Theme
, shift : Bool
, visibility : Visibility
Expand Down Expand Up @@ -263,7 +261,6 @@ init flags url navKey =
, repo = RemoteData.succeed defaultRepository
, inTimeout = Nothing
, entryURL = url
, hookBuilds = Dict.empty
, theme = stringToTheme flags.velaTheme
, shift = False
, visibility = Visible
Expand Down Expand Up @@ -309,7 +306,6 @@ type Msg
| RefreshSettings Org Repo
| RefreshHooks Org Repo
| RefreshSecrets Engine Type Org Repo
| ClickHook Org Repo BuildNumber
| SetTheme Theme
| ClickStep Org Repo BuildNumber StepNumber String
| GotoPage Pagination.Page
Expand All @@ -336,7 +332,6 @@ type Msg
| SourceRepositoriesResponse (Result (Http.Detailed.Error String) ( Http.Metadata, SourceRepositories ))
| RepoFavoritedResponse String Bool (Result (Http.Detailed.Error String) ( Http.Metadata, CurrentUser ))
| HooksResponse Org Repo (Result (Http.Detailed.Error String) ( Http.Metadata, Hooks ))
| HookBuildResponse Org Repo BuildNumber (Result (Http.Detailed.Error String) ( Http.Metadata, Build ))
| RepoEnabledResponse Repository (Result (Http.Detailed.Error String) ( Http.Metadata, Repository ))
| RepoUpdatedResponse Field (Result (Http.Detailed.Error String) ( Http.Metadata, Repository ))
| RepoDisabledResponse Repository (Result (Http.Detailed.Error String) ( Http.Metadata, String ))
Expand Down Expand Up @@ -901,15 +896,6 @@ update msg model =
, Cmd.batch <| List.map (Util.dispatch << EnableRepo) repos
)

ClickHook org repo buildNumber ->
let
( hookBuilds, action ) =
clickHook model org repo buildNumber
in
( { model | hookBuilds = hookBuilds }
, action
)

ClickStep org repo buildNumber stepNumber _ ->
let
( steps, fetchStepLogs ) =
Expand Down Expand Up @@ -1023,14 +1009,6 @@ update msg model =
Err error ->
( { model | hooks = { currentHooks | hooks = toFailure error } }, addError error )

HookBuildResponse org repo buildNumber response ->
case response of
Ok ( _, build ) ->
( { model | hookBuilds = Pages.Hooks.receiveHookBuild ( org, repo, buildNumber ) (RemoteData.succeed build) model.hookBuilds }, Cmd.none )

Err error ->
( { model | hookBuilds = Pages.Hooks.receiveHookBuild ( org, repo, buildNumber ) (toFailure error) model.hookBuilds }, Cmd.none )

AlertsUpdate subMsg ->
Alerting.update Alerts.successConfig AlertsUpdate subMsg model

Expand Down Expand Up @@ -1330,7 +1308,6 @@ refreshPage model =
Pages.Hooks org repo maybePage maybePerPage ->
Cmd.batch
[ getHooks model org repo maybePage maybePerPage
, refreshHookBuilds model
]

Pages.OrgSecrets engine org maybePage maybePerPage ->
Expand Down Expand Up @@ -1427,25 +1404,6 @@ refreshBuildSteps model org repo buildNumber =
refresh


{-| refreshHookBuilds : takes model org and repo and refreshes the hook builds being viewed by the user
-}
refreshHookBuilds : Model -> Cmd Msg
refreshHookBuilds model =
let
builds =
Dict.keys model.hookBuilds

buildsToRefresh =
List.filter
(\build -> shouldRefreshHookBuild <| Maybe.withDefault ( NotAsked, False ) <| Dict.get build model.hookBuilds)
builds

refreshCmds =
List.map (\( org, repo, buildNumber ) -> getHookBuild model org repo buildNumber) buildsToRefresh
in
Cmd.batch refreshCmds


{-| shouldRefresh : takes build and returns true if a refresh is required
-}
shouldRefresh : WebData Build -> Bool
Expand All @@ -1465,13 +1423,6 @@ shouldRefresh build =
False


{-| shouldRefreshHookBuild : takes build and viewing state and returns true if a refresh is required
-}
shouldRefreshHookBuild : ( WebData Build, Viewing ) -> Bool
shouldRefreshHookBuild ( build, viewing ) =
viewing && shouldRefresh build


{-| filterCompletedSteps : filters out completed steps based on success and failure
-}
filterCompletedSteps : Steps -> Steps
Expand Down Expand Up @@ -1611,14 +1562,10 @@ viewContent model =
( String.join "/" [ org, repo ] ++ " hooks" ++ page
, div []
[ Pager.view model.hooks.pager Pager.defaultLabels GotoPage
, lazy4 Pages.Hooks.view
, lazy Pages.Hooks.view
{ hooks = model.hooks
, hookBuilds = model.hookBuilds
, time = model.time
}
org
repo
hooksMsgs
, Pager.view model.hooks.pager Pager.defaultLabels GotoPage
]
)
Expand Down Expand Up @@ -2121,7 +2068,7 @@ loadHooksPage model org repo maybePage maybePerPage =
loadingHooks =
{ loadedHooks | hooks = Loading }
in
( { model | page = Pages.Hooks org repo maybePage maybePerPage, hooks = loadingHooks, hookBuilds = Dict.empty }
( { model | page = Pages.Hooks org repo maybePage maybePerPage, hooks = loadingHooks }
, Cmd.batch
[ getHooks model org repo maybePage maybePerPage
, getCurrentUser model
Expand Down Expand Up @@ -2629,38 +2576,6 @@ addLog incomingLog logs =
RemoteData.succeed incomingLog :: logs


{-| clickHook : takes model org repo and build number and fetches build information from the api
-}
clickHook : Model -> Org -> Repo -> BuildNumber -> ( HookBuilds, Cmd Msg )
clickHook model org repo buildNumber =
if buildNumber == "0" then
( model.hookBuilds
, Cmd.none
)

else
let
( buildInfo, action ) =
case Dict.get ( org, repo, buildNumber ) model.hookBuilds of
Just ( webdataBuild, viewing ) ->
case webdataBuild of
Success _ ->
( ( webdataBuild, not viewing ), Cmd.none )

Failure err ->
( ( Failure err, not viewing ), Cmd.none )

_ ->
( ( Loading, not viewing ), Cmd.none )

_ ->
( ( Loading, True ), getHookBuild model org repo buildNumber )
in
( Dict.update ( org, repo, buildNumber ) (\_ -> Just buildInfo) model.hookBuilds
, action
)


{-| homeMsgs : prepares the input record required for the Home page to route Msgs back to Main.elm
-}
homeMsgs : Pages.Home.Msgs Msg
Expand Down Expand Up @@ -2689,13 +2604,6 @@ addReposMsgs =
Pages.AddRepos.Msgs SearchSourceRepos EnableRepo EnableRepos ToggleFavorite


{-| hooksMsgs : prepares the input record required for the Hooks page to route Msgs back to Main.elm
-}
hooksMsgs : Org -> Repo -> BuildNumber -> Msg
hooksMsgs =
ClickHook


{-| repoSettingsMsgs : prepares the input record required for the Settings page to route Msgs back to Main.elm
-}
repoSettingsMsgs : Pages.RepoSettings.Msgs Msg
Expand All @@ -2722,11 +2630,6 @@ getHooks model org repo maybePage maybePerPage =
Api.try (HooksResponse org repo) <| Api.getHooks model maybePage maybePerPage org repo


getHookBuild : Model -> Org -> Repo -> BuildNumber -> Cmd Msg
getHookBuild model org repo buildNumber =
Api.try (HookBuildResponse org repo buildNumber) <| Api.getBuild model org repo buildNumber


getRepo : Model -> Org -> Repo -> Cmd Msg
getRepo model org repo =
Api.try RepoResponse <| Api.getRepo model org repo
Expand Down
Loading

0 comments on commit 2b3b597

Please sign in to comment.