Skip to content

Commit f721f6a

Browse files
Mario Aguiarravichdev
authored andcommitted
Add snapshot when should not update
1 parent 9c7022b commit f721f6a

File tree

4 files changed

+107
-8
lines changed

4 files changed

+107
-8
lines changed

plugin/assets/src/settings/components/integrations/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ const Integrations = () => {
8181
displayUpdatedOn={ UPDATERS[ key ].displayUpdatedOn }
8282
versionAvailable={ UPDATERS[ key ].versionAvailable }
8383
apiStatus={ state.apiStatus }
84+
updateAvailable={
85+
state.updaters[ UPDATERS[ key ].type ].updateAvailable
86+
}
8487
/>
8588
) ) }
8689
</div>

plugin/assets/src/settings/components/integrations/updater.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ const Updater = ( {
4545
displayUpdatedOn,
4646
versionAvailable,
4747
apiStatus,
48+
updateAvailable,
4849
} ) => {
4950
const [ id ] = useState( _uniqueId( 'updater-' ) );
50-
const { state, dispatch } = useContext( SettingsContext );
51+
const { dispatch } = useContext( SettingsContext );
5152
const isDisabled = needsKey && 'ok' !== apiStatus;
5253
const updatedDate = lastUpdated
5354
? dateI18n( 'M j, Y, h:i A', lastUpdated )
5455
: __( 'never', 'material-design' );
5556
const [ isUpdating, setIsUpdating ] = useState( false );
56-
const shouldUpdate = ! isDisabled && state.updaters[ type ].updateAvailable;
57-
const shouldNotUpdate =
58-
! isDisabled && ! state.updaters[ type ].updateAvailable;
57+
const shouldUpdate = ! isDisabled && updateAvailable;
58+
const shouldNotUpdate = ! isDisabled && ! updateAvailable;
5959

6060
const handleUpdate = response => {
6161
setIsUpdating( true );

plugin/tests/js/settings/components/integrations/__snapshots__/updater.test.js.snap

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ exports[`Settings: Updater matches snapshot 1`] = `
2222
<p
2323
class="mdc-typography--body1"
2424
>
25-
Last update on Apr 6, 2021, 11:23 PM
25+
Last update on Apr 6, 2021, 11:33 PM
2626
</p>
2727
</div>
2828
<div
@@ -66,18 +66,17 @@ exports[`Settings: Updater matches snapshot 1`] = `
6666
>
6767
<button
6868
class="mdc-button mdc-button--raised"
69-
disabled=""
7069
>
7170
<i
7271
aria-hidden="true"
7372
class="material-icons mdc-button__icon leading-icon"
7473
>
75-
done
74+
cached
7675
</i>
7776
<span
7877
class="mdc-button__label"
7978
>
80-
Updated
79+
Update
8180
</span>
8281
</button>
8382
</div>
@@ -209,6 +208,92 @@ exports[`Settings: Updater matches snapshot when never updated 1`] = `
209208
</label>
210209
</div>
211210
</div>
211+
<div
212+
class="mdc-layout-grid__cell mdc-layout-grid__cell--span-2 mdc-layout-grid__cell--align-middle material-settings__cell--justify-end"
213+
>
214+
<button
215+
class="mdc-button mdc-button--raised"
216+
>
217+
<i
218+
aria-hidden="true"
219+
class="material-icons mdc-button__icon leading-icon"
220+
>
221+
cached
222+
</i>
223+
<span
224+
class="mdc-button__label"
225+
>
226+
Update
227+
</span>
228+
</button>
229+
</div>
230+
</div>
231+
</div>
232+
</div>
233+
</div>
234+
`;
235+
236+
exports[`Settings: Updater matches snapshot when should not update 1`] = `
237+
<div>
238+
<div
239+
class="material-settings__updater"
240+
>
241+
<div
242+
class="mdc-layout-grid"
243+
>
244+
<div
245+
class="mdc-layout-grid__inner"
246+
>
247+
<div
248+
class="mdc-layout-grid__cell mdc-layout-grid__cell--span-7 mdc-layout-grid__cell--align-middle"
249+
>
250+
<h3
251+
class="mdc-typography--headline6"
252+
>
253+
Google Fonts
254+
</h3>
255+
<p
256+
class="mdc-typography--body1"
257+
>
258+
Last update on Apr 6, 2021, 11:33 PM
259+
</p>
260+
</div>
261+
<div
262+
class="mdc-layout-grid__cell mdc-layout-grid__cell--span-3 mdc-layout-grid__cell--align-middle material-settings__cell--justify-end"
263+
>
264+
<div
265+
class="material-settings__switch"
266+
>
267+
<div
268+
class="mdc-switch material-wizard-switch mdc-switch--checked"
269+
>
270+
<div
271+
class="mdc-switch__track"
272+
/>
273+
<div
274+
class="mdc-switch__thumb-underlay"
275+
>
276+
<div
277+
class="mdc-switch__thumb"
278+
/>
279+
<input
280+
aria-checked="true"
281+
checked=""
282+
class="mdc-switch__native-control"
283+
id="updater-4"
284+
role="switch"
285+
type="checkbox"
286+
/>
287+
</div>
288+
</div>
289+
<label
290+
for="updater-4"
291+
id="label-updater-4"
292+
>
293+
Auto-updates enabled
294+
</label>
295+
</div>
296+
</div>
212297
<div
213298
class="mdc-layout-grid__cell mdc-layout-grid__cell--span-2 mdc-layout-grid__cell--align-middle material-settings__cell--justify-end"
214299
>

plugin/tests/js/settings/components/integrations/updater.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const baseProps = {
3333
needsKey: true,
3434
checked: true,
3535
apiStatus: 'ok',
36+
updateAvailable: true,
3637
};
3738

3839
const setup = props => {
@@ -68,4 +69,14 @@ describe( 'Settings: Updater', () => {
6869
const { container } = setup( props );
6970
expect( container ).toMatchSnapshot();
7071
} );
72+
73+
it( 'matches snapshot when should not update', () => {
74+
const props = {
75+
...baseProps,
76+
updateAvailable: false,
77+
};
78+
79+
const { container } = setup( props );
80+
expect( container ).toMatchSnapshot();
81+
} );
7182
} );

0 commit comments

Comments
 (0)